Skip to content

Commit 4238b85

Browse files
committed
add frigate non nix playbook
1 parent d28dd52 commit 4238b85

5 files changed

Lines changed: 87 additions & 26 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/v2/src/main.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ use bdk_sp::{
2929
};
3030
use bdk_sp_oracles::{
3131
bip157::{
32-
self,
33-
tokio::{self, select},
34-
AddrV2, Builder, Client as KyotoClient, HeaderCheckpoint, IndexedBlock, Info, ServiceFlags,
35-
TrustedPeer, UnboundedReceiver, Warning,
32+
self, AddrV2, Builder, Client as KyotoClient, HeaderCheckpoint, IndexedBlock, Info, ServiceFlags, TrustedPeer, UnboundedReceiver, Warning, tokio::{self, select}
3633
},
3734
filters::kyoto::{FilterEvent, FilterSubscriber},
38-
frigate::{FrigateClient, History, SubscribeRequest, UnsubscribeRequest},
35+
frigate::{DUMMY_COINBASE, FrigateClient, History, SubscribeRequest, UnsubscribeRequest},
3936
tweaks::blindbit::{BlindbitSubscriber, TweakEvent},
4037
};
4138
use bdk_sp_wallet::{
@@ -167,9 +164,10 @@ pub enum Commands {
167164
ScanFrigate {
168165
#[clap(flatten)]
169166
rpc_args: RpcArgs,
170-
/// The scan private key for which outputs will be scanned for.
171167
#[clap(long)]
172-
start: Option<u32>,
168+
height: Option<u32>,
169+
#[clap(long)]
170+
hash: Option<BlockHash>,
173171
},
174172

175173
Create {
@@ -578,15 +576,33 @@ async fn main() -> anyhow::Result<()> {
578576
);
579577
}
580578
}
581-
Commands::ScanFrigate { rpc_args, start } => {
582-
// The implementation done here differ from what mentionned in the section https://github.com/sparrowwallet/frigate/tree/master?tab=readme-ov-file#blockchainsilentpaymentssubscribe
583-
// We are doing a one time scanning only. So instead of calling `blockchain.scripthash.subscribe` on each script from the wallet,
584-
// we just subscribe and read the scanning result from the stream. On each result received we update the wallet state and once scanning progress reaches 1.0 (100%) we stop.
579+
Commands::ScanFrigate { rpc_args, height, hash } => {
580+
// The implementation done here differs from what is mentioned in the section
581+
// https://github.com/sparrowwallet/frigate/tree/master?tab=readme-ov-file#blockchainsilentpaymentssubscribe
582+
// This implementation is doing a one time scanning only. So instead of calling
583+
// `blockchain.scripthash.subscribe` on each script from the wallet, we just subscribe
584+
// and read the scanning result from the stream. On each result received we update the
585+
// wallet state and once scanning progress reaches 1.0 (100%) we stop.
586+
let sync_point = if let (Some(height), Some(hash)) = (height, hash) {
587+
HeaderCheckpoint::new(height, hash)
588+
} else if wallet.birthday.height <= wallet.chain().tip().height() {
589+
let height = wallet.chain().tip().height();
590+
let hash = wallet.chain().tip().hash();
591+
HeaderCheckpoint::new(height, hash)
592+
} else {
593+
let checkpoint = wallet
594+
.chain()
595+
.get(wallet.birthday.height)
596+
.expect("should be something");
597+
let height = checkpoint.height();
598+
let hash = checkpoint.hash();
599+
HeaderCheckpoint::new(height, hash)
600+
};
585601

586602
let mut client = FrigateClient::connect(&rpc_args.url)
587603
.await
588604
.unwrap()
589-
.with_timeout(tokio::time::Duration::from_secs(600));
605+
.with_timeout(tokio::time::Duration::from_secs(60));
590606

591607
let labels = wallet
592608
.indexer()
@@ -604,7 +620,7 @@ async fn main() -> anyhow::Result<()> {
604620
let subscribe_params = SubscribeRequest {
605621
scan_priv_key: *wallet.indexer().scan_sk(),
606622
spend_pub_key: *wallet.indexer().spend_pk(),
607-
start_height: start,
623+
start_height: Some(sync_point.height),
608624
labels,
609625
};
610626

@@ -661,9 +677,8 @@ async fn main() -> anyhow::Result<()> {
661677
raw_blk.push_str("00");
662678

663679
// Push dummy coinbase
664-
let dummy_coinbase = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1b03951a0604f15ccf5609013803062b9b5a0100072f425443432f20000000000000000000";
665680
let coinbase: Transaction =
666-
deserialize(&Vec::<u8>::from_hex(dummy_coinbase).unwrap())
681+
deserialize(&Vec::<u8>::from_hex(DUMMY_COINBASE).unwrap())
667682
.unwrap();
668683
let mut block: Block =
669684
deserialize(&Vec::<u8>::from_hex(&raw_blk).unwrap()).unwrap();

doc/tabconf7/frigate_playbook.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
########################### STAGE 1: setup ####################################
4+
5+
# 1. Install dependencies locally and setup regtest environment
6+
just non_nix_init
7+
# 2. Check bitcoind is running on regtest
8+
just cli getblockchaininfo
9+
# 3. Check bdk-cli wallet was created correctly
10+
just regtest-bdk balance
11+
# 4. Check sp-cli wallet was created correctly
12+
just regtest-sp balance
13+
# 5. Synchronize bdk-cli wallet
14+
just regtest-bdk sync
15+
16+
###################### STAGE 2: fund bdk-cli wallet ###########################
17+
18+
# 6. Get a new address from bdk-cli wallet
19+
REGTEST_ADDRESS=$(just regtest-bdk unused_address | jq -r '.address' | tr -d '\n')
20+
# 7. Mine a few more blocks to fund the wallet
21+
just mine 1 $REGTEST_ADDRESS
22+
# 8. Mine some of them to the internal wallet to confirm the bdk-cli balance
23+
just mine 101
24+
# 9. Synchronize bdk-cli wallet
25+
just regtest-bdk sync
26+
# 10. Check balance
27+
just regtest-bdk balance
28+
29+
################ STAGE 3: create a silent payment output ######################
30+
31+
# 11. Get a silent payment code from sp-cli2 wallet
32+
SP_CODE=$(just regtest-sp code | jq -r '.silent_payment_code' | tr -d '\n')
33+
# 12. Create a transaction spending bdk-cli wallet UTXOs to a the previous silent payment code
34+
RAW_TX=$(just regtest-bdk create_sp_tx --to-sp $SP_CODE:10000 --fee_rate 5 | jq -r '.raw_tx' | tr -d '\n')
35+
TXID=$(just regtest-bdk broadcast --tx $RAW_TX | jq -r '.txid' | tr -d '\n')
36+
# 14. Mine a new block
37+
just mine 1
38+
# 15. Once the new transaction has been mined, synchronize bdk-cli wallet again
39+
just regtest-bdk sync
40+
41+
# ################## STAGE 4: find a silent payment output ######################
42+
43+
# 16. Now synchronize sp-cli2 wallet using frigate ephemeral scanning
44+
FRIGATE_HOST="127.0.0.1:57001"
45+
START_HEIGHT=1
46+
just regtest-sp scan-frigate --url $FRIGATE_HOST --start $START_HEIGHT
47+
# 17. Check balance on sp-cli2 wallet
48+
just regtest-sp balance
49+
# 18. Check balance on bdk-cli wallet
50+
just regtest-bdk balance
51+
52+
# At this point we will able to see SP outputs paid to out wallet!

doc/tabconf7/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ build TAG="1.0.0" VERSION="29.0" RELEASE="29.0": machine
123123
RUN mkdir -p /build/frigate
124124
RUN mkdir -p /frigate
125125
WORKDIR /frigate
126-
RUN git clone --recursive --branch 1.1.0 --depth 1 https://github.com/sparrowwallet/frigate.git .
126+
RUN git clone --recursive --branch 1.3.2 --depth 1 https://github.com/sparrowwallet/frigate.git .
127127
RUN ./gradlew jpackage
128128
RUN cp -r ./build/jpackage/frigate /build/frigate
129129
RUN rm -rf /frigate

oracles/src/frigate/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ pub struct GetRequest {
9595
pub struct RequestPayload {
9696
pub method: String,
9797
pub params: Value,
98-
pub id: serde_json::Value,
9998
pub jsonrpc: String,
10099
}
101100

102101
const SUBSCRIBE_RPC_METHOD: &str = "blockchain.silentpayments.subscribe";
103102
const UNSUBSCRIBE_RPC_METHOD: &str = "blockchain.silentpayments.unsubscribe";
104103
const GET_RPC_METHOD: &str = "blockchain.transaction.get";
105104
const VERSION_RPC_METHOD: &str = "server.version";
106-
const _SUBSCRIBE_OWNED_OUTPUTS: &str = "blockchain.scripthash.subscribe";
105+
const BLOCK_HEADER_RPC_METHOD: &str = "blockchain.block.header";
106+
pub const DUMMY_COINBASE: &str = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1b03951a0604f15ccf5609013803062b9b5a0100072f425443432f20000000000000000000";
107107

108108
impl FrigateClient {
109109
pub async fn connect(host_url: &str) -> Result<Self, FrigateError> {
@@ -161,9 +161,8 @@ impl FrigateClient {
161161
pub async fn get_block_header(&mut self, height: u32) -> Result<String, FrigateError> {
162162
let params = vec![height];
163163
let req = RequestPayload {
164-
method: "blockchain.block.header".to_string(),
164+
method: BLOCK_HEADER_RPC_METHOD.to_string(),
165165
params: serde_json::json!(params),
166-
id: serde_json::Value::from(1000),
167166
jsonrpc: "2.0".to_string(),
168167
};
169168
let req_bytes = serde_json::to_vec(&req)?;
@@ -181,7 +180,6 @@ impl FrigateClient {
181180
let req = RequestPayload {
182181
method: GET_RPC_METHOD.to_string(),
183182
params: serde_json::json!(params),
184-
id: serde_json::Value::from(51),
185183
jsonrpc: "2.0".to_string(),
186184
};
187185
let req_bytes = serde_json::to_vec(&req)?;
@@ -199,7 +197,6 @@ impl FrigateClient {
199197
let req = RequestPayload {
200198
method: VERSION_RPC_METHOD.to_string(),
201199
params: serde_json::json!(params),
202-
id: serde_json::Value::from(71),
203200
jsonrpc: "2.0".to_string(),
204201
};
205202

@@ -230,7 +227,7 @@ impl FrigateClient {
230227
let req = RequestPayload {
231228
method: SUBSCRIBE_RPC_METHOD.to_string(),
232229
params: serde_json::json!(params),
233-
id: serde_json::Value::from(91),
230+
//:Value::from(91),
234231
jsonrpc: "2.0".to_string(),
235232
};
236233

@@ -264,7 +261,6 @@ impl FrigateClient {
264261
let req = RequestPayload {
265262
method: UNSUBSCRIBE_RPC_METHOD.to_string(),
266263
params: serde_json::json!(params),
267-
id: serde_json::Value::from(189),
268264
jsonrpc: "2.0".to_string(),
269265
};
270266

0 commit comments

Comments
 (0)