|
18 | 18 |
|
19 | 19 | use bitcoin::{consensus::Encodable, hex::DisplayHex, Script, Txid}; |
20 | 20 |
|
| 21 | +#[cfg(feature = "frigate")] |
| 22 | +use bitcoin::secp256k1::{PublicKey, SecretKey}; |
| 23 | + |
21 | 24 | use crate::{ |
22 | 25 | response, CowStr, ElectrumScriptHash, ElectrumScriptStatus, MethodAndParams, RawRequest, |
23 | 26 | ResponseError, |
@@ -656,3 +659,93 @@ impl Request for Ping { |
656 | 659 | ("server.ping".into(), vec![]) |
657 | 660 | } |
658 | 661 | } |
| 662 | + |
| 663 | +/// A request to establish connection with Frigate Electrum client |
| 664 | +/// |
| 665 | +/// This corresponds to the `"server.version"` Frigate Electrum RPC method |
| 666 | +/// |
| 667 | +/// See: https://github.com/sparrowwallet/frigate |
| 668 | +#[cfg(feature = "frigate")] |
| 669 | +#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
| 670 | +pub struct Version { |
| 671 | + pub client_name: CowStr, |
| 672 | + pub version: CowStr, |
| 673 | +} |
| 674 | + |
| 675 | +#[cfg(feature = "frigate")] |
| 676 | +impl Request for Version { |
| 677 | + type Response = Vec<String>; |
| 678 | + |
| 679 | + fn to_method_and_params(&self) -> MethodAndParams { |
| 680 | + ( |
| 681 | + "server.version".into(), |
| 682 | + vec![self.client_name.clone().into(), self.version.clone().into()], |
| 683 | + ) |
| 684 | + } |
| 685 | +} |
| 686 | + |
| 687 | +/// A request to subscribe to payment outputs belonging to the provided keys |
| 688 | +/// |
| 689 | +/// This corresponds to the `"blockchain.silentpayments.subscribe"` Frigate Electrum RPC method. |
| 690 | +/// It returns The silent payment address that has been subscribed. |
| 691 | +/// |
| 692 | +/// See: https://github.com/sparrowwallet/frigate#blockchainsilentpaymentssubscribe |
| 693 | +#[cfg(feature = "frigate")] |
| 694 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 695 | +pub struct Subscribe { |
| 696 | + pub scan_priv_key: SecretKey, |
| 697 | + pub scan_pub_key: PublicKey, |
| 698 | + pub start_height: Option<u32>, |
| 699 | + pub labels: Option<Vec<u32>>, |
| 700 | +} |
| 701 | + |
| 702 | +#[cfg(feature = "frigate")] |
| 703 | +impl Request for Subscribe { |
| 704 | + type Response = String; |
| 705 | + |
| 706 | + fn to_method_and_params(&self) -> MethodAndParams { |
| 707 | + let mut params = vec![ |
| 708 | + serde_json::json!(self.scan_priv_key), |
| 709 | + serde_json::json!(self.scan_pub_key), |
| 710 | + ]; |
| 711 | + |
| 712 | + if let Some(start_height) = self.start_height { |
| 713 | + params.push(start_height.into()); |
| 714 | + } |
| 715 | + |
| 716 | + if let Some(labels) = &self.labels { |
| 717 | + params.push(labels.clone().into()); |
| 718 | + } |
| 719 | + |
| 720 | + ("blockchain.silentpayments.subscribe".into(), params) |
| 721 | + } |
| 722 | +} |
| 723 | + |
| 724 | +/// A request to unsubscribe to payment outputs belonging to the provided keys |
| 725 | +/// |
| 726 | +/// This corresponds to the `"blockchain.silentpayments.unsubscribe"` Frigate Electrum RPC method. |
| 727 | +/// It returns The silent payment address that has been subscribed.This should cancel any scans that |
| 728 | +/// may be currently running for this address. |
| 729 | +/// |
| 730 | +/// See: https://github.com/sparrowwallet/frigate#blockchainsilentpaymentsunsubscribe |
| 731 | +#[cfg(feature = "frigate")] |
| 732 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 733 | +pub struct UnSubscribe { |
| 734 | + pub scan_priv_key: SecretKey, |
| 735 | + pub scan_pub_key: PublicKey, |
| 736 | +} |
| 737 | + |
| 738 | +#[cfg(feature = "frigate")] |
| 739 | +impl Request for UnSubscribe { |
| 740 | + type Response = String; |
| 741 | + |
| 742 | + fn to_method_and_params(&self) -> MethodAndParams { |
| 743 | + ( |
| 744 | + "blockchain.silentpayments.unsubscribe".into(), |
| 745 | + vec![ |
| 746 | + serde_json::json!(self.scan_priv_key), |
| 747 | + serde_json::json!(self.scan_pub_key), |
| 748 | + ], |
| 749 | + ) |
| 750 | + } |
| 751 | +} |
0 commit comments