-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add frigate electrum based RPC methods #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4c80f38
3a63c94
99312db
df15c6b
120356e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| //! | ||
| //! - [`Notification::Header`] for `"blockchain.headers.subscribe"` | ||
| //! - [`Notification::ScriptHash`] for `"blockchain.scripthash.subscribe"` | ||
| //! - [`Notification::SpSubscribe`] for `"blockchain.silentpayments.subscribe"` (requires the `frigate` feature) | ||
| //! - [`Notification::Unknown`] for unrecognized or unsupported methods | ||
| //! | ||
| //! Each variant wraps a struct that contains the deserialized payload for that notification type. | ||
|
|
@@ -32,6 +33,11 @@ pub enum Notification { | |
| /// status. | ||
| ScriptHash(ScriptHashNotification), | ||
|
|
||
| /// A notification from `"blockchain.silentpayments.subscribe"` indicating a new history | ||
| /// of transactions | ||
| #[cfg(feature = "frigate")] | ||
| SpSubscribe(SpNotification), | ||
|
|
||
| /// A catch-all for notifications with unrecognized methods. | ||
| /// | ||
| /// The original [`RawNotification`] is preserved for downstream inspection. | ||
|
|
@@ -52,6 +58,10 @@ impl Notification { | |
| "blockchain.scripthash.subscribe" => { | ||
| ScriptHashNotification::deserialize(params).map(Notification::ScriptHash) | ||
| } | ||
| #[cfg(feature = "frigate")] | ||
| "blockchain.silentpayments.subscribe" => { | ||
| SpNotification::deserialize(params).map(Notification::SpSubscribe) | ||
| } | ||
| _ => Ok(Notification::Unknown(raw.clone())), | ||
| } | ||
| } | ||
|
|
@@ -102,3 +112,14 @@ impl ScriptHashNotification { | |
| self.param_1 | ||
| } | ||
| } | ||
|
|
||
| /// A notification indicating new transactions. | ||
| /// | ||
| /// Corresponds to `"blockchain.silentpayments.subscribe"` Frigate Electrum notification method. | ||
| #[cfg(feature = "frigate")] | ||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct SpNotification { | ||
| pub subscription: response::SpSubscribeResp, | ||
| pub progress: f32, | ||
| pub history: Vec<response::TxTweak>, | ||
|
Comment on lines
+121
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs missing |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -656,3 +656,87 @@ impl Request for Ping { | |
| ("server.ping".into(), vec![]) | ||
| } | ||
| } | ||
|
|
||
| /// A request to subscribe to payment outputs belonging to the provided keys | ||
| /// | ||
| /// This corresponds to the `"blockchain.silentpayments.subscribe"` Frigate Electrum RPC method. | ||
| /// It returns the silent payment address that has been subscribed. | ||
| /// | ||
| /// Supported Frigate version: <= 1.4.1 | ||
| /// | ||
| /// See: <https://github.com/sparrowwallet/frigate/tree/1.4.1#blockchainsilentpaymentssubscribe> | ||
| #[cfg(feature = "frigate")] | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct SpSubscribe { | ||
| // A 64 character string containing the hex of the scan private key. | ||
| pub scan_priv_key: bitcoin::secp256k1::SecretKey, | ||
|
|
||
| // A 66 character string containing the hex of the spend public key. | ||
| pub spend_pub_key: bitcoin::secp256k1::PublicKey, | ||
|
|
||
| // Block height or timestamp to start scanning from. Values above 500,000,000 are treated as seconds from the start of the epoch. | ||
|
Comment on lines
+671
to
+677
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs need |
||
| pub start_height: Option<u32>, | ||
|
sdmg15 marked this conversation as resolved.
|
||
|
|
||
| // An array of positive integers specifying additional silent payment labels to scan for. | ||
| pub labels: Option<Vec<u32>>, | ||
| } | ||
|
|
||
| #[cfg(feature = "frigate")] | ||
| impl Request for SpSubscribe { | ||
| type Response = String; | ||
|
sdmg15 marked this conversation as resolved.
|
||
|
|
||
| fn to_method_and_params(&self) -> MethodAndParams { | ||
| let mut params = vec![ | ||
| serde_json::json!(self.scan_priv_key), | ||
| serde_json::json!(self.spend_pub_key), | ||
| ]; | ||
|
|
||
| match (self.start_height, &self.labels) { | ||
| (Some(start_height), Some(labels)) => { | ||
| params.extend([start_height.into(), labels.clone().into()]); | ||
| } | ||
|
|
||
| (Some(start_height), None) => params.push(start_height.into()), | ||
| (None, Some(labels)) => { | ||
| params.extend([serde_json::Value::Null, labels.clone().into()]); | ||
| } | ||
| (None, None) => {} | ||
| } | ||
|
|
||
| ("blockchain.silentpayments.subscribe".into(), params) | ||
| } | ||
| } | ||
|
|
||
| /// A request to unsubscribe from payment outputs belonging to the provided keys | ||
| /// | ||
| /// This corresponds to the `"blockchain.silentpayments.unsubscribe"` Frigate Electrum RPC method. | ||
| /// It returns the silent payment address that has been unsubscribed. This should cancel any scans | ||
| /// that may be currently running for this address. | ||
| /// | ||
| /// Supported Frigate version <= 1.4.1 | ||
| /// | ||
| /// See: <https://github.com/sparrowwallet/frigate/tree/1.4.1#blockchainsilentpaymentsunsubscribe> | ||
| #[cfg(feature = "frigate")] | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct SpUnsubscribe { | ||
| // A 64 character string containing the hex of the scan private key. | ||
| pub scan_priv_key: bitcoin::secp256k1::SecretKey, | ||
|
|
||
| // A 66 character string containing the hex of the spend public key. | ||
|
Comment on lines
+722
to
+725
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs need |
||
| pub spend_pub_key: bitcoin::secp256k1::PublicKey, | ||
| } | ||
|
|
||
| #[cfg(feature = "frigate")] | ||
| impl Request for SpUnsubscribe { | ||
| type Response = String; | ||
|
|
||
| fn to_method_and_params(&self) -> MethodAndParams { | ||
| ( | ||
| "blockchain.silentpayments.unsubscribe".into(), | ||
| vec![ | ||
| serde_json::json!(self.scan_priv_key), | ||
| serde_json::json!(self.spend_pub_key), | ||
| ], | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,3 +318,19 @@ pub struct ServerHostValues { | |
| /// TCP Port. | ||
| pub tcp_port: Option<u16>, | ||
| } | ||
|
|
||
| #[cfg(feature = "frigate")] | ||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct SpSubscribeResp { | ||
| pub address: String, | ||
| pub labels: Vec<u32>, | ||
| pub start_height: u32, | ||
|
Comment on lines
+324
to
+327
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs missing |
||
| } | ||
|
|
||
| #[cfg(feature = "frigate")] | ||
| #[derive(Debug, Clone, serde::Deserialize)] | ||
| pub struct TxTweak { | ||
| pub height: u32, | ||
| pub tx_hash: bitcoin::Txid, | ||
| pub tweak_key: bitcoin::secp256k1::PublicKey, | ||
| } | ||
|
Comment on lines
+332
to
+336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docs missing |
||
Uh oh!
There was an error while loading. Please reload this page.