Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions cli/v2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use bdk_sp_oracles::{
TrustedPeer, UnboundedReceiver, Warning,
},
filters::kyoto::{FilterEvent, FilterSubscriber},
frigate::{self, FrigateClient},
tweaks::blindbit::{BlindbitSubscriber, TweakEvent},
};
use bdk_sp_wallet::{
Expand Down Expand Up @@ -161,6 +162,24 @@ pub enum Commands {
#[clap(long)]
hash: Option<BlockHash>,
},

ScanFrigrate {
#[clap(flatten)]
rpc_args: RpcArgs,
/// The scan private key for which outputs will be scanned for.
#[clap(long)]
scan_priv_key: String,
/// The spend public key for which outputs will be scanned for.
#[clap(long)]
spend_pub_key: String,
/// An optional start parameter from where the scanning will start. When not specified it starts from Taproot activation height.
#[clap(long)]
start: Option<u64>,
/// Optional list of labels to scan for. It always scan for change index with label 0.
#[clap(long)]
labels: Option<Vec<u32>>,
},

Create {
/// Network
#[clap(long, short, default_value = "signet")]
Expand Down Expand Up @@ -567,6 +586,22 @@ async fn main() -> anyhow::Result<()> {
);
}
}
Commands::ScanFrigrate {
rpc_args,
scan_priv_key,
spend_pub_key,
start,
labels,
} => {
let client = FrigateClient::new(
&rpc_args.url,
rpc_args.rpc_user.as_deref(),
rpc_args.rpc_password.as_deref(),
)?;
let histories: Vec<frigate::History> = Vec::new();

loop {}
}
Commands::Balance => {
fn print_balances<'a>(
title_str: &'a str,
Expand Down
3 changes: 2 additions & 1 deletion oracles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ redb = "2.4.0"
rayon = "1.11.0"
reqwest = { version = "0.12.23", features = ["json", "rustls-tls", "http2", "charset"], default-features = false }
serde = { version = "1.0.219", features = ["serde_derive"] }
serde_json = "1.0.142"
serde_json = { version = "1.0.142", features = ["raw_value"]}
url = "2.5.4"
tracing = "0.1.41"
jsonrpc = "=0.18.0"

[lints]
workspace = true
110 changes: 110 additions & 0 deletions oracles/src/frigate/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use bitcoin::{key::TweakedPublicKey, secp256k1::SecretKey, PublicKey};
use jsonrpc::simple_http::{self, SimpleHttpTransport};
use jsonrpc::Client;
use serde::{Deserialize, Serialize};
use serde_json::value::to_raw_value;

#[derive(Debug)]
pub enum FrigateError {
JsonRpc(jsonrpc::Error),
ParseUrl(url::ParseError),
Serde(serde_json::Error),
}

impl From<serde_json::Error> for FrigateError {
fn from(value: serde_json::Error) -> Self {
FrigateError::Serde(value)
}
}

impl From<url::ParseError> for FrigateError {
fn from(value: url::ParseError) -> Self {
Self::ParseUrl(value)
}
}

impl From<jsonrpc::Error> for FrigateError {
fn from(value: jsonrpc::Error) -> Self {
Self::JsonRpc(value)
}
}

pub struct FrigateClient {
pub host_url: String,
client: Client,
}

#[derive(Serialize, Deserialize)]
pub struct History {
height: u64,
tx_hash: bitcoin::BlockHash,
tweak_key: TweakedPublicKey,
}

#[derive(Serialize, Deserialize)]
pub struct NotifPayload {
scan_private_key: SecretKey,
spend_public_key: PublicKey,
address: String,
labels: Option<Vec<u32>>,
start_height: u64,
progress: f32,
history: Vec<History>,
}

#[derive(Serialize, Deserialize)]
pub struct SubscribeRequest {
scan_privkey: SecretKey,
spend_pubkey: PublicKey,
start_height: u64,
}

#[derive(Serialize, Deserialize)]
pub struct UnsubscribeRequest {
scan_privkey: SecretKey,
spend_pubkey: PublicKey,
}

#[derive(Serialize, Deserialize)]
pub struct GetRequest {
tx_hash: bitcoin::BlockHash,
}

const SUBSCRIBE_RPC_METHOD: &str = "blockchain.silentpayments.subscribe";
const UNSUBSCRIBE_RPC_METHOD: &str = "blockchain.silentpayments.unsubscribe";

impl FrigateClient {
pub fn new(
host_url: &str,
user: Option<&str>,
password: Option<&str>,
) -> Result<Self, simple_http::Error> {
let transport = SimpleHttpTransport::builder()
.url(host_url)?
.auth(user.unwrap_or(""), password)
.build();

Ok(Self {
host_url: host_url.to_string(),
client: Client::with_transport(transport),
})
}

pub fn subscribe(&self, req: &SubscribeRequest) -> Result<String, FrigateError> {
let params = to_raw_value(&serde_json::json!(req))?;
let req = self
.client
.build_request(SUBSCRIBE_RPC_METHOD, Some(&params));
let res = self.client.send_request(req)?;
Ok(res.result()?)
}

pub fn unsubscribe(&self, req: &UnsubscribeRequest) -> Result<String, FrigateError> {
let params = to_raw_value(&serde_json::json!(req))?;
let req = self
.client
.build_request(UNSUBSCRIBE_RPC_METHOD, Some(&params));
let res = self.client.send_request(req)?;
Ok(res.result()?)
}
}
1 change: 1 addition & 0 deletions oracles/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod filters;
pub mod frigate;
pub mod tweaks;
pub use bip157;