Skip to content

Commit c72dc84

Browse files
committed
integration of frigate ephemeral scanning
1 parent b9a4fb7 commit c72dc84

5 files changed

Lines changed: 149 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use bdk_sp_oracles::{
3434
TrustedPeer, UnboundedReceiver, Warning,
3535
},
3636
filters::kyoto::{FilterEvent, FilterSubscriber},
37+
frigate::{self, FrigateClient},
3738
tweaks::blindbit::{BlindbitSubscriber, TweakEvent},
3839
};
3940
use bdk_sp_wallet::{
@@ -161,6 +162,24 @@ pub enum Commands {
161162
#[clap(long)]
162163
hash: Option<BlockHash>,
163164
},
165+
166+
ScanFrigrate {
167+
#[clap(flatten)]
168+
rpc_args: RpcArgs,
169+
/// The scan private key for which outputs will be scanned for.
170+
#[clap(long)]
171+
scan_priv_key: String,
172+
/// The spend public key for which outputs will be scanned for.
173+
#[clap(long)]
174+
spend_pub_key: String,
175+
/// An optional start parameter from where the scanning will start. When not specified it starts from Taproot activation height.
176+
#[clap(long)]
177+
start: Option<u64>,
178+
/// Optional list of labels to scan for. It always scan for change index with label 0.
179+
#[clap(long)]
180+
labels: Option<Vec<u32>>,
181+
},
182+
164183
Create {
165184
/// Network
166185
#[clap(long, short, default_value = "signet")]
@@ -567,6 +586,22 @@ async fn main() -> anyhow::Result<()> {
567586
);
568587
}
569588
}
589+
Commands::ScanFrigrate {
590+
rpc_args,
591+
scan_priv_key,
592+
spend_pub_key,
593+
start,
594+
labels,
595+
} => {
596+
let client = FrigateClient::new(
597+
&rpc_args.url,
598+
rpc_args.rpc_user.as_deref(),
599+
rpc_args.rpc_password.as_deref(),
600+
)?;
601+
let histories: Vec<frigate::History> = Vec::new();
602+
603+
loop {}
604+
}
570605
Commands::Balance => {
571606
fn print_balances<'a>(
572607
title_str: &'a str,

oracles/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ redb = "2.4.0"
1313
rayon = "1.11.0"
1414
reqwest = { version = "0.12.23", features = ["json", "rustls-tls", "http2", "charset"], default-features = false }
1515
serde = { version = "1.0.219", features = ["serde_derive"] }
16-
serde_json = "1.0.142"
16+
serde_json = { version = "1.0.142", features = ["raw_value"]}
1717
url = "2.5.4"
1818
tracing = "0.1.41"
19+
jsonrpc = "=0.18.0"
1920

2021
[lints]
2122
workspace = true

oracles/src/frigate/mod.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
use bitcoin::{key::TweakedPublicKey, secp256k1::SecretKey, PublicKey};
2+
use jsonrpc::simple_http::{self, SimpleHttpTransport};
3+
use jsonrpc::Client;
4+
use serde::{Deserialize, Serialize};
5+
use serde_json::value::to_raw_value;
6+
7+
#[derive(Debug)]
8+
pub enum FrigateError {
9+
JsonRpc(jsonrpc::Error),
10+
ParseUrl(url::ParseError),
11+
Serde(serde_json::Error),
12+
}
13+
14+
impl From<serde_json::Error> for FrigateError {
15+
fn from(value: serde_json::Error) -> Self {
16+
FrigateError::Serde(value)
17+
}
18+
}
19+
20+
impl From<url::ParseError> for FrigateError {
21+
fn from(value: url::ParseError) -> Self {
22+
Self::ParseUrl(value)
23+
}
24+
}
25+
26+
impl From<jsonrpc::Error> for FrigateError {
27+
fn from(value: jsonrpc::Error) -> Self {
28+
Self::JsonRpc(value)
29+
}
30+
}
31+
32+
pub struct FrigateClient {
33+
pub host_url: String,
34+
client: Client,
35+
}
36+
37+
#[derive(Serialize, Deserialize)]
38+
pub struct History {
39+
height: u64,
40+
tx_hash: bitcoin::BlockHash,
41+
tweak_key: TweakedPublicKey,
42+
}
43+
44+
#[derive(Serialize, Deserialize)]
45+
pub struct NotifPayload {
46+
scan_private_key: SecretKey,
47+
spend_public_key: PublicKey,
48+
address: String,
49+
labels: Option<Vec<u32>>,
50+
start_height: u64,
51+
progress: f32,
52+
history: Vec<History>,
53+
}
54+
55+
#[derive(Serialize, Deserialize)]
56+
pub struct SubscribeRequest {
57+
scan_privkey: SecretKey,
58+
spend_pubkey: PublicKey,
59+
start_height: u64,
60+
}
61+
62+
#[derive(Serialize, Deserialize)]
63+
pub struct UnsubscribeRequest {
64+
scan_privkey: SecretKey,
65+
spend_pubkey: PublicKey,
66+
}
67+
68+
#[derive(Serialize, Deserialize)]
69+
pub struct GetRequest {
70+
tx_hash: bitcoin::BlockHash,
71+
}
72+
73+
const SUBSCRIBE_RPC_METHOD: &str = "blockchain.silentpayments.subscribe";
74+
const UNSUBSCRIBE_RPC_METHOD: &str = "blockchain.silentpayments.unsubscribe";
75+
76+
impl FrigateClient {
77+
pub fn new(
78+
host_url: &str,
79+
user: Option<&str>,
80+
password: Option<&str>,
81+
) -> Result<Self, simple_http::Error> {
82+
let transport = SimpleHttpTransport::builder()
83+
.url(host_url)?
84+
.auth(user.unwrap_or(""), password)
85+
.build();
86+
87+
Ok(Self {
88+
host_url: host_url.to_string(),
89+
client: Client::with_transport(transport),
90+
})
91+
}
92+
93+
pub fn subscribe(&self, req: &SubscribeRequest) -> Result<String, FrigateError> {
94+
let params = to_raw_value(&serde_json::json!(req))?;
95+
let req = self
96+
.client
97+
.build_request(SUBSCRIBE_RPC_METHOD, Some(&params));
98+
let res = self.client.send_request(req)?;
99+
Ok(res.result()?)
100+
}
101+
102+
pub fn unsubscribe(&self, req: &UnsubscribeRequest) -> Result<String, FrigateError> {
103+
let params = to_raw_value(&serde_json::json!(req))?;
104+
let req = self
105+
.client
106+
.build_request(UNSUBSCRIBE_RPC_METHOD, Some(&params));
107+
let res = self.client.send_request(req)?;
108+
Ok(res.result()?)
109+
}
110+
}

oracles/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod filters;
2+
pub mod frigate;
23
pub mod tweaks;
34
pub use bip157;

0 commit comments

Comments
 (0)