Skip to main content

corepc_client/client_sync/v17/
mod.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! A JSON-RPC client for testing against Bitcoin Core `v0.17`.
4//!
5//! We ignore option arguments unless they effect the shape of the returned JSON data.
6
7pub mod blockchain;
8pub mod control;
9pub mod generating;
10pub mod hidden;
11pub mod mining;
12pub mod network;
13pub mod raw_transactions;
14pub mod util;
15pub mod wallet;
16pub mod zmq;
17
18use std::collections::{BTreeMap, HashMap};
19use std::path::Path;
20
21use bitcoin::address::{Address, NetworkChecked};
22use bitcoin::{sign_message, Amount, Block, BlockHash, PublicKey, Txid};
23use serde::{Deserialize, Serialize, Serializer};
24
25use crate::client_sync::into_json;
26use crate::types::v17::*;
27
28crate::define_jsonrpc_bitreq_client!("v17");
29crate::impl_client_check_expected_server_version!({ [170200] });
30
31// == Blockchain ==
32crate::impl_client_v17__get_best_block_hash!();
33crate::impl_client_v17__get_block!();
34crate::impl_client_v17__get_blockchain_info!();
35crate::impl_client_v17__get_block_count!();
36crate::impl_client_v17__get_block_hash!();
37crate::impl_client_v17__get_block_header!();
38crate::impl_client_v17__get_block_stats!();
39crate::impl_client_v17__get_chain_tips!();
40crate::impl_client_v17__get_chain_tx_stats!();
41crate::impl_client_v17__get_difficulty!();
42crate::impl_client_v17__get_mempool_ancestors!();
43crate::impl_client_v17__get_mempool_descendants!();
44crate::impl_client_v17__get_mempool_entry!();
45crate::impl_client_v17__get_mempool_info!();
46crate::impl_client_v17__get_raw_mempool!();
47crate::impl_client_v17__get_tx_out!();
48crate::impl_client_v17__get_tx_out_proof!();
49crate::impl_client_v17__get_tx_out_set_info!();
50crate::impl_client_v17__precious_block!();
51crate::impl_client_v17__prune_blockchain!();
52crate::impl_client_v17__save_mempool!();
53crate::impl_client_v17__scan_tx_out_set!();
54crate::impl_client_v17__verify_chain!();
55crate::impl_client_v17__verify_tx_out_proof!();
56
57// == Control ==
58crate::impl_client_v17__get_memory_info!();
59crate::impl_client_v17__help!();
60crate::impl_client_v17__logging!();
61crate::impl_client_v17__stop!();
62crate::impl_client_v17__uptime!();
63
64// == Generating ==
65crate::impl_client_v17__generate_to_address!();
66crate::impl_client_v17__generate!();
67crate::impl_client_v17__invalidate_block!();
68
69// == Hidden ==
70crate::impl_client_v17__estimate_raw_fee!();
71crate::impl_client_v17__wait_for_block!();
72crate::impl_client_v17__wait_for_block_height!();
73crate::impl_client_v17__wait_for_new_block!();
74crate::impl_client_v17__sync_with_validation_interface_queue!();
75crate::impl_client_v17__reconsider_block!();
76
77// == Mining ==
78crate::impl_client_v17__get_block_template!();
79crate::impl_client_v17__get_mining_info!();
80crate::impl_client_v17__get_network_hashes_per_second!();
81crate::impl_client_v17__prioritise_transaction!();
82crate::impl_client_v17__submit_block!();
83
84// == Network ==
85crate::impl_client_v17__add_node!();
86crate::impl_client_v17__clear_banned!();
87crate::impl_client_v17__disconnect_node!();
88crate::impl_client_v17__get_added_node_info!();
89crate::impl_client_v17__get_connection_count!();
90crate::impl_client_v17__get_net_totals!();
91crate::impl_client_v17__get_network_info!();
92crate::impl_client_v17__get_peer_info!();
93crate::impl_client_v17__list_banned!();
94crate::impl_client_v17__ping!();
95crate::impl_client_v17__set_ban!();
96crate::impl_client_v17__set_network_active!();
97
98// == Rawtransactions ==
99crate::impl_client_v17__combine_psbt!();
100crate::impl_client_v17__combine_raw_transaction!();
101crate::impl_client_v17__convert_to_psbt!();
102crate::impl_client_v17__create_psbt!();
103crate::impl_client_v17__create_raw_transaction!();
104crate::impl_client_v17__decode_psbt!();
105crate::impl_client_v17__decode_raw_transaction!();
106crate::impl_client_v17__decode_script!();
107crate::impl_client_v17__finalize_psbt!();
108crate::impl_client_v17__fund_raw_transaction!();
109crate::impl_client_v17__get_raw_transaction!();
110crate::impl_client_v17__send_raw_transaction!();
111crate::impl_client_v17__sign_raw_transaction!();
112crate::impl_client_v17__sign_raw_transaction_with_key!();
113crate::impl_client_v17__test_mempool_accept!();
114
115// == Util ==
116crate::impl_client_v17__create_multisig!();
117crate::impl_client_v17__estimate_smart_fee!();
118crate::impl_client_v17__sign_message_with_priv_key!();
119crate::impl_client_v17__validate_address!();
120crate::impl_client_v17__verify_message!();
121
122// == Wallet ==
123crate::impl_client_v17__abandon_transaction!();
124crate::impl_client_v17__abort_rescan!();
125crate::impl_client_v17__add_multisig_address!();
126crate::impl_client_v17__backup_wallet!();
127crate::impl_client_v17__bump_fee!();
128crate::impl_client_v17__create_wallet!();
129crate::impl_client_v17__dump_priv_key!();
130crate::impl_client_v17__dump_wallet!();
131crate::impl_client_v17__encrypt_wallet!();
132crate::impl_client_v17__get_addresses_by_label!();
133crate::impl_client_v17__get_address_info!();
134crate::impl_client_v17__get_balance!();
135crate::impl_client_v17__get_new_address!();
136crate::impl_client_v17__get_raw_change_address!();
137crate::impl_client_v17__get_received_by_address!();
138crate::impl_client_v17__get_transaction!();
139crate::impl_client_v17__get_unconfirmed_balance!();
140crate::impl_client_v17__get_wallet_info!();
141crate::impl_client_v17__import_address!();
142crate::impl_client_v17__import_multi!();
143crate::impl_client_v17__import_privkey!();
144crate::impl_client_v17__import_pruned_funds!();
145crate::impl_client_v17__import_pubkey!();
146crate::impl_client_v17__import_wallet!();
147crate::impl_client_v17__key_pool_refill!();
148crate::impl_client_v17__list_address_groupings!();
149crate::impl_client_v17__list_labels!();
150crate::impl_client_v17__list_lock_unspent!();
151crate::impl_client_v17__list_received_by_address!();
152crate::impl_client_v17__list_since_block!();
153crate::impl_client_v17__list_transactions!();
154crate::impl_client_v17__list_unspent!();
155crate::impl_client_v17__list_wallets!();
156crate::impl_client_v17__load_wallet!();
157crate::impl_client_v17__lock_unspent!();
158crate::impl_client_v17__remove_pruned_funds!();
159crate::impl_client_v17__rescan_blockchain!();
160crate::impl_client_v17__send_many!();
161crate::impl_client_v17__send_to_address!();
162crate::impl_client_v17__set_hd_seed!();
163crate::impl_client_v17__set_tx_fee!();
164crate::impl_client_v17__sign_message!();
165crate::impl_client_v17__sign_raw_transaction_with_wallet!();
166crate::impl_client_v17__unload_wallet!();
167crate::impl_client_v17__wallet_create_funded_psbt!();
168crate::impl_client_v17__wallet_lock!();
169crate::impl_client_v17__wallet_passphrase!();
170crate::impl_client_v17__wallet_passphrase_change!();
171crate::impl_client_v17__wallet_process_psbt!();
172
173// == Zmq ==
174crate::impl_client_v17__get_zmq_notifications!();
175
176/// Argument to the `Client::get_new_address_with_type` function.
177///
178/// For Core versions 0.17 through to v22. For Core v23 and onwards use `v23::AddressType`.
179#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
180#[serde(rename_all = "kebab-case")]
181pub enum AddressType {
182    Legacy,
183    P2shSegwit,
184    Bech32,
185}
186
187impl fmt::Display for AddressType {
188    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
189        use AddressType::*;
190
191        let s = match *self {
192            Legacy => "legacy",
193            P2shSegwit => "p2sh-segwit",
194            Bech32 => "bech32",
195        };
196        fmt::Display::fmt(s, f)
197    }
198}
199
200/// Arg for the `getblocktemplate` method.
201///
202/// For Core versions 0.17 through to v28. For Core v29 and onwards use `v29::TemplateRequest`.
203#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
204pub struct TemplateRequest {
205    /// A list of strings.
206    pub rules: Vec<TemplateRules>,
207}
208
209/// Client side supported softfork deployment.
210#[derive(Copy, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
211#[serde(rename_all = "lowercase")]
212pub enum TemplateRules {
213    /// SegWit v0 supported.
214    Segwit,
215    /// Signet supported.
216    Signet,
217    /// CSV supported.
218    Csv,
219    /// Taproot supported.
220    Taproot,
221}
222
223/// Input used as parameter to `create_raw_transaction`.
224#[derive(Debug, Serialize)]
225pub struct Input {
226    /// The txid of the transaction that contains the UTXO.
227    pub txid: bitcoin::Txid,
228    /// The vout for the UTXO.
229    pub vout: u64,
230    /// Sequence number if needed.
231    pub sequence: Option<bitcoin::Sequence>,
232}
233
234/// Output used as parameter to `create_raw_transaction`.
235// Abuse `HashMap` so we can derive serialize to get the correct JSON object.
236#[derive(Debug, Serialize)]
237pub struct Output(
238    /// Map of address to value. Always only has a single item in it.
239    HashMap<String, f64>,
240);
241
242impl Output {
243    /// Creates a single output that serializes as Core expects.
244    pub fn new(addr: Address, value: Amount) -> Self {
245        let mut map = HashMap::new();
246        map.insert(addr.to_string(), value.to_btc());
247        Output(map)
248    }
249}
250
251/// An element in the `inputs` argument of method `walletcreatefundedpsbt`.
252#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
253pub struct WalletCreateFundedPsbtInput {
254    txid: Txid,
255    vout: u32,
256}
257
258impl WalletCreateFundedPsbtInput {
259    /// Create a new walletcreatefundedpsbt input entry.
260    pub fn new(txid: Txid, vout: u32) -> Self { Self { txid, vout } }
261}
262
263/// Args for the `addnode` method.
264#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
265#[serde(rename_all = "lowercase")]
266pub enum AddNodeCommand {
267    Add,
268    Remove,
269    OneTry,
270}
271
272/// Args for the `setban` method.
273#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
274#[serde(rename_all = "lowercase")]
275pub enum SetBanCommand {
276    Add,
277    Remove,
278}
279
280/// Args for the `importmulti` method.
281#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
282pub struct ImportMultiRequest {
283    /// Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts, or pubkeys.
284    #[serde(rename = "desc", skip_serializing_if = "Option::is_none")]
285    pub descriptor: Option<String>, // from core v18 onwards.
286    /// Type of scriptPubKey (string for script, json for address). Should not be provided if using descriptor.
287    #[serde(rename = "scriptPubKey", skip_serializing_if = "Option::is_none")]
288    pub script_pubkey: Option<ImportMultiScriptPubKey>,
289    /// Creation time of the key expressed in UNIX epoch time, or the string "now" to substitute the current synced blockchain time.
290    pub timestamp: ImportMultiTimestamp,
291}
292
293/// `scriptPubKey` can be a string for script or json for address.
294#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
295#[serde(untagged)]
296pub enum ImportMultiScriptPubKey {
297    /// The script.
298    Script(String),
299    /// The address.
300    Address { address: String },
301}
302
303/// `timestamp` can be a number (UNIX epoch time) or the string `"now"`.
304#[derive(Clone, Debug, Deserialize, PartialEq)]
305#[serde(untagged)]
306pub enum ImportMultiTimestamp {
307    /// The string "now".
308    Now,
309    /// The UNIX timestamp.
310    Time(u64),
311}
312
313impl Serialize for ImportMultiTimestamp {
314    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
315    where
316        S: Serializer,
317    {
318        match self {
319            ImportMultiTimestamp::Now => serializer.serialize_str("now"),
320            ImportMultiTimestamp::Time(t) => serializer.serialize_u64(*t),
321        }
322    }
323}
324
325/// Arg for the `estimatesmartfee` method.
326#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
327#[serde(rename_all = "UPPERCASE")]
328pub enum FeeEstimateMode {
329    /// Use default settings based on other criteria
330    Unset,
331    /// Force estimatesmartfee to use non-conservative estimates
332    Economical,
333    /// Force estimatesmartfee to use conservative estimates
334    Conservative,
335}