bwk_electrum/electrum/
method.rs1use miniscript::serde::{Deserialize, Serialize};
2use std::fmt::Debug;
3
4#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
5pub enum Method {
6 #[serde(rename = "server.banner")]
7 Banner,
8 #[serde(rename = "blockchain.block.header")]
9 BlockHeader,
10 #[serde(rename = "blockchain.block.headers")]
11 BlockHeaders,
12 #[serde(rename = "blockchain.transaction.broadcast")]
13 TransactionBroadcast,
14 #[serde(rename = "server.donation_address")]
15 Donation,
16 #[serde(rename = "blockchain.estimatefee")]
17 EstimateFee,
18 #[serde(rename = "server.features")]
19 Features,
20 #[serde(rename = "blockchain.headers.subscribe")]
21 HeadersSubscribe,
22 #[serde(rename = "mempool.get_fee_histogram")]
23 FeeHistogram,
24 #[serde(rename = "server.peers.subscribe")]
25 ListPeers,
26 #[serde(rename = "server.ping")]
27 Ping,
28 #[serde(rename = "blockchain.relayfee")]
29 RelayFee,
30 #[serde(rename = "blockchain.scripthash.get_balance")]
31 ScriptHashGetBalance,
32 #[serde(rename = "blockchain.scripthash.get_history")]
33 ScriptHashGetHistory,
34 #[serde(rename = "blockchain.scripthash.listunspent")]
38 ScriptHashListUnspent,
39 #[serde(rename = "blockchain.scripthash.subscribe")]
40 ScriptHashSubscribe,
41 #[serde(rename = "blockchain.scripthash.unsubscribe")]
42 ScriptHashUnsubscribe,
43 #[serde(rename = "blockchain.transaction.get")]
44 TransactionGet,
45 #[serde(rename = "blockchain.transaction.get_merkle")]
46 TransactionGetMerkle,
47 #[serde(rename = "blockchain.transaction.id_from_pos")]
48 TransactionFromPosition,
49 #[serde(rename = "server.version")]
50 Version,
51}
52
53impl Debug for Method {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 match self {
56 Self::Banner => write!(f, "server.banner"),
57 Self::BlockHeader => write!(f, "blockchain.block.header"),
58 Self::BlockHeaders => write!(f, "blockchain.block.headers"),
59 Self::TransactionBroadcast => write!(f, "blockchain.transaction.broadcast"),
60 Self::Donation => write!(f, "server.donation_address"),
61 Self::EstimateFee => write!(f, "blockchain.estimatefee"),
62 Self::Features => write!(f, "server.features"),
63 Self::HeadersSubscribe => write!(f, "blockchain.headers.subscribe"),
64 Self::FeeHistogram => write!(f, "mempool.get_fee_histogram"),
65 Self::ListPeers => write!(f, "server.peers.subscribe"),
66 Self::Ping => write!(f, "server.ping"),
67 Self::RelayFee => write!(f, "blockchain.relayfee"),
68 Self::ScriptHashGetBalance => write!(f, "blockchain.scripthash.get_balance"),
69 Self::ScriptHashGetHistory => write!(f, "blockchain.scripthash.get_history"),
70 Self::ScriptHashListUnspent => write!(f, "blockchain.scripthash.listunspent"),
71 Self::ScriptHashSubscribe => write!(f, "blockchain.scripthash.subscribe"),
72 Self::ScriptHashUnsubscribe => write!(f, "blockchain.scripthash.unsubscribe"),
73 Self::TransactionGet => write!(f, "blockchain.transaction.get"),
74 Self::TransactionGetMerkle => write!(f, "blockchain.transaction.get_merkle"),
75 Self::TransactionFromPosition => write!(f, "blockchain.transaction.id_from_pos"),
76 Self::Version => write!(f, "server.version"),
77 }
80 }
81}
82
83#[cfg(test)]
84mod tests {
85 use super::Method::*;
86
87 macro_rules! debug_json {
88 ($value:expr) => {{
89 use serde_json::to_string;
90
91 let json_str = to_string(&$value).unwrap();
92 let json_str = json_str.trim_matches('"');
93
94 let debug_str = format!("{:?}", $value);
95
96 assert_eq!(
97 json_str, debug_str,
98 "Debug and JSON representations do not match"
99 );
100 }};
101 }
102
103 #[test]
104 fn debug() {
105 debug_json!(Version);
106 debug_json!(TransactionFromPosition);
107 debug_json!(TransactionGetMerkle);
108 debug_json!(TransactionGet);
109 debug_json!(ScriptHashUnsubscribe);
110 debug_json!(ScriptHashSubscribe);
111 debug_json!(ScriptHashListUnspent);
112 debug_json!(ScriptHashGetHistory);
113 debug_json!(ScriptHashGetBalance);
114 debug_json!(RelayFee);
115 debug_json!(Ping);
116 debug_json!(ListPeers);
117 debug_json!(FeeHistogram);
118 debug_json!(HeadersSubscribe);
119 debug_json!(Features);
120 debug_json!(EstimateFee);
121 debug_json!(Donation);
122 debug_json!(TransactionBroadcast);
123 debug_json!(BlockHeaders);
124 debug_json!(BlockHeader);
125 debug_json!(Banner);
126 }
127}