Skip to content

Commit 9397251

Browse files
committed
Flesh out v17 and v18
This patch is massive, I worked on it for many days across multiple weeks. I was lazy and did not pull unrelated fixes out - sorry. Does the following: - Improves stuff in `node` left over from the crate rename from `bitcoind`. - Totally re-writes the `integration_test` crate removing the macros, vastly simplifying it. - Fleshes out v17 adding impls for all blockchain and wallet methods. - Copies the v17 to v18 to prove the process, we have an open problem around docs on the types. Will describe as a github issue. - Various other little things I saw while working on this.
1 parent 6092f89 commit 9397251

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+6726
-3422
lines changed

client/src/client_sync/v17/blockchain.rs

Lines changed: 122 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12+
/// Implements Bitcoin Core JSON-RPC API method `getblockchaininfo`
13+
#[macro_export]
14+
macro_rules! impl_client_v17__getblockchaininfo {
15+
() => {
16+
impl Client {
17+
pub fn get_blockchain_info(&self) -> Result<GetBlockchainInfo> {
18+
self.call("getblockchaininfo", &[])
19+
}
20+
}
21+
};
22+
}
23+
1224
/// Implements Bitcoin Core JSON-RPC API method `getbestblockhash`
1325
#[macro_export]
1426
macro_rules! impl_client_v17__getbestblockhash {
@@ -34,36 +46,23 @@ macro_rules! impl_client_v17__getblock {
3446
impl Client {
3547
/// Gets a block by blockhash.
3648
pub fn get_block(&self, hash: BlockHash) -> Result<Block> {
37-
let json = self.get_block_verbosity_zero(hash)?;
49+
let json = self.get_block_verbose_zero(hash)?;
3850
Ok(json.block()?)
3951
}
4052

41-
pub fn get_block_verbosity_zero(
42-
&self,
43-
hash: BlockHash,
44-
) -> Result<GetBlockVerbosityZero> {
53+
/// Gets a block by blockhash with verbose set to 0.
54+
pub fn get_block_verbose_zero(&self, hash: BlockHash) -> Result<GetBlockVerbosityZero> {
4555
self.call("getblock", &[into_json(hash)?, 0.into()])
4656
}
4757

48-
pub fn get_block_verbosity_one(&self, hash: BlockHash) -> Result<GetBlockVerbosityOne> {
58+
/// Gets a block by blockhash with verbose set to 1.
59+
pub fn get_block_verbose_one(&self, hash: BlockHash) -> Result<GetBlockVerbosityOne> {
4960
self.call("getblock", &[into_json(hash)?, 1.into()])
5061
}
5162
}
5263
};
5364
}
5465

55-
/// Implements Bitcoin Core JSON-RPC API method `getblockchaininfo`
56-
#[macro_export]
57-
macro_rules! impl_client_v17__getblockchaininfo {
58-
() => {
59-
impl Client {
60-
pub fn get_blockchain_info(&self) -> Result<GetBlockchainInfo> {
61-
self.call("getblockchaininfo", &[])
62-
}
63-
}
64-
};
65-
}
66-
6766
/// Implements Bitcoin Core JSON-RPC API method `getblockcount`
6867
#[macro_export]
6968
macro_rules! impl_client_v17__getblockcount {
@@ -164,8 +163,76 @@ macro_rules! impl_client_v17__getmempoolancestors {
164163
() => {
165164
impl Client {
166165
pub fn get_mempool_ancestors(&self, txid: Txid) -> Result<GetMempoolAncestors> {
166+
// Equivalent to self.call("getmempoolancestors", &[into_json(txid)?, into_json(false)?])
167167
self.call("getmempoolancestors", &[into_json(txid)?])
168168
}
169+
170+
pub fn get_mempool_ancestors_verbose(
171+
&self,
172+
txid: Txid,
173+
) -> Result<GetMempoolAncestorsVerbose> {
174+
self.call("getmempoolancestors", &[into_json(txid)?, into_json(true)?])
175+
}
176+
}
177+
};
178+
}
179+
180+
/// Implements Bitcoin Core JSON-RPC API method `getmempooldescendants`
181+
#[macro_export]
182+
macro_rules! impl_client_v17__getmempooldescendants {
183+
() => {
184+
impl Client {
185+
pub fn get_mempool_descendants(&self, txid: Txid) -> Result<GetMempoolDescendants> {
186+
// Equivalent to self.call("getmempooldescendants", &[into_json(txid)?, into_json(false)?])
187+
self.call("getmempooldescendants", &[into_json(txid)?])
188+
}
189+
190+
pub fn get_mempool_descendants_verbose(
191+
&self,
192+
txid: Txid,
193+
) -> Result<GetMempoolDescendantsVerbose> {
194+
self.call("getmempooldescendants", &[into_json(txid)?, into_json(true)?])
195+
}
196+
}
197+
};
198+
}
199+
200+
/// Implements Bitcoin Core JSON-RPC API method `getmempoolentry`
201+
#[macro_export]
202+
macro_rules! impl_client_v17__getmempoolentry {
203+
() => {
204+
impl Client {
205+
pub fn get_mempool_entry(&self, txid: Txid) -> Result<GetMempoolEntry> {
206+
self.call("getmempoolentry", &[into_json(txid)?])
207+
}
208+
}
209+
};
210+
}
211+
212+
/// Implements Bitcoin Core JSON-RPC API method `getmempoolinfo`
213+
#[macro_export]
214+
macro_rules! impl_client_v17__getmempoolinfo {
215+
() => {
216+
impl Client {
217+
pub fn get_mempool_info(&self) -> Result<GetMempoolInfo> {
218+
self.call("getmempoolinfo", &[])
219+
}
220+
}
221+
};
222+
}
223+
224+
/// Implements Bitcoin Core JSON-RPC API method `getrawmempool`
225+
#[macro_export]
226+
macro_rules! impl_client_v17__getrawmempool {
227+
() => {
228+
impl Client {
229+
pub fn get_raw_mempool(&self) -> Result<GetRawMempool> {
230+
// Equivalent to self.call("getrawmempool", &[into_json(false)?])
231+
self.call("getrawmempool", &[])
232+
}
233+
pub fn get_raw_mempool_verbose(&self) -> Result<GetRawMempool> {
234+
self.call("getrawmempool", &[into_json(true)?])
235+
}
169236
}
170237
};
171238
}
@@ -181,3 +248,40 @@ macro_rules! impl_client_v17__gettxout {
181248
}
182249
};
183250
}
251+
252+
/// Implements Bitcoin Core JSON-RPC API method `gettxoutproof`
253+
#[macro_export]
254+
macro_rules! impl_client_v17__gettxoutproof {
255+
() => {
256+
impl Client {
257+
pub fn get_tx_out_proof(&self, txids: Vec<Txid>) -> Result<GetTxOut> {
258+
self.call("gettxoutproof", &[into_json(txids)?])
259+
}
260+
}
261+
};
262+
}
263+
264+
/// Implements Bitcoin Core JSON-RPC API method `gettxoutsetinfo`
265+
#[macro_export]
266+
macro_rules! impl_client_v17__gettxoutsetinfo {
267+
() => {
268+
impl Client {
269+
pub fn get_tx_out_set_info(&self) -> Result<GetTxOut> {
270+
self.call("gettxoutsetinfo", &[])
271+
}
272+
}
273+
};
274+
}
275+
276+
/// Implements Bitcoin Core JSON-RPC API method `verifytxoutproof`
277+
#[macro_export]
278+
macro_rules! impl_client_v17__verifytxoutproof {
279+
() => {
280+
impl Client {
281+
// `proof` is the hex-encoded proof generated by `gettxoutproof`.
282+
pub fn verify_tx_out_proof(&self, proof: &str) -> Result<GetTxOut> {
283+
self.call("verifytxoutproof", &[into_json(proof)?])
284+
}
285+
}
286+
};
287+
}

client/src/client_sync/v17/mod.rs

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,54 @@ pub mod network;
1111
pub mod raw_transactions;
1212
pub mod wallet;
1313

14+
use std::collections::BTreeMap;
15+
use std::path::Path;
16+
1417
use bitcoin::address::{Address, NetworkChecked};
15-
use bitcoin::{Amount, Block, BlockHash, Txid};
18+
use bitcoin::{Amount, Block, BlockHash, PublicKey, Txid};
1619
use serde::{Deserialize, Serialize};
1720

1821
use crate::client_sync::into_json;
1922
use crate::types::v17::*;
2023

24+
/// An element in the `inputs` argument of method `walletcreatefundedpsbt`.
25+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
26+
pub struct WalletCreateFundedPsbtInput {
27+
txid: Txid,
28+
vout: u32,
29+
}
30+
31+
/// Argument to the `Client::get_new_address_with_type` function.
32+
///
33+
/// For Core versions 0.17 through to v22. For Core v23 and onwards use `v23::AddressType`.
34+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
35+
#[serde(rename_all = "kebab-case")]
36+
pub enum AddressType {
37+
Legacy,
38+
P2shSegwit,
39+
Bech32,
40+
}
41+
42+
impl fmt::Display for AddressType {
43+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44+
use AddressType::*;
45+
46+
let s = match *self {
47+
Legacy => "legacy",
48+
P2shSegwit => "p2sh-segwit",
49+
Bech32 => "bech32",
50+
};
51+
fmt::Display::fmt(s, f)
52+
}
53+
}
54+
2155
crate::define_jsonrpc_minreq_client!("v17");
2256
crate::impl_client_check_expected_server_version!({ [170100] });
2357

2458
// == Blockchain ==
25-
crate::impl_client_v17__getblockchaininfo!();
2659
crate::impl_client_v17__getbestblockhash!();
2760
crate::impl_client_v17__getblock!();
28-
crate::impl_client_v17__gettxout!();
61+
crate::impl_client_v17__getblockchaininfo!();
2962
crate::impl_client_v17__getblockcount!();
3063
crate::impl_client_v17__getblockhash!();
3164
crate::impl_client_v17__getblockheader!();
@@ -34,6 +67,14 @@ crate::impl_client_v17__getchaintips!();
3467
crate::impl_client_v17__getchaintxstats!();
3568
crate::impl_client_v17__getdifficulty!();
3669
crate::impl_client_v17__getmempoolancestors!();
70+
crate::impl_client_v17__getmempooldescendants!();
71+
crate::impl_client_v17__getmempoolentry!();
72+
crate::impl_client_v17__getmempoolinfo!();
73+
crate::impl_client_v17__getrawmempool!();
74+
crate::impl_client_v17__gettxout!();
75+
crate::impl_client_v17__gettxoutproof!();
76+
crate::impl_client_v17__gettxoutsetinfo!();
77+
crate::impl_client_v17__verifytxoutproof!();
3778

3879
// == Control ==
3980
crate::impl_client_v17__getmemoryinfo!();
@@ -55,32 +96,33 @@ crate::impl_client_v17__getpeerinfo!();
5596
crate::impl_client_v17__sendrawtransaction!();
5697

5798
// == Wallet ==
99+
crate::impl_client_v17__addmultisigaddress!();
100+
crate::impl_client_v17__bumpfee!();
58101
crate::impl_client_v17__createwallet!();
59-
crate::impl_client_v17__unloadwallet!();
60-
crate::impl_client_v17__loadwallet!();
61-
crate::impl_client_v17__getnewaddress!();
102+
crate::impl_client_v17__dumpprivkey!();
103+
crate::impl_client_v17__dumpwallet!();
104+
crate::impl_client_v17__getaddressesbylabel!();
105+
crate::impl_client_v17__getaddressinfo!();
62106
crate::impl_client_v17__getbalance!();
63-
crate::impl_client_v17__sendtoaddress!();
107+
crate::impl_client_v17__getnewaddress!();
108+
crate::impl_client_v17__getrawchangeaddress!();
109+
crate::impl_client_v17__getreceivedbyaddress!();
64110
crate::impl_client_v17__gettransaction!();
65-
66-
/// Argument to the `Client::get_new_address_with_type` function.
67-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
68-
#[serde(rename_all = "kebab-case")]
69-
pub enum AddressType {
70-
Legacy,
71-
P2shSegwit,
72-
Bech32,
73-
}
74-
75-
impl fmt::Display for AddressType {
76-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
77-
use AddressType::*;
78-
79-
let s = match *self {
80-
Legacy => "legacy",
81-
P2shSegwit => "p2sh-segwit",
82-
Bech32 => "bech32",
83-
};
84-
fmt::Display::fmt(s, f)
85-
}
86-
}
111+
crate::impl_client_v17__getunconfirmedbalance!();
112+
crate::impl_client_v17__getwalletinfo!();
113+
crate::impl_client_v17__listaddressgroupings!();
114+
crate::impl_client_v17__listlabels!();
115+
crate::impl_client_v17__listlockunspent!();
116+
crate::impl_client_v17__listreceivedbyaddress!();
117+
crate::impl_client_v17__listsinceblock!();
118+
crate::impl_client_v17__listtransactions!();
119+
crate::impl_client_v17__listunspent!();
120+
crate::impl_client_v17__listwallets!();
121+
crate::impl_client_v17__loadwallet!();
122+
crate::impl_client_v17__rescanblockchain!();
123+
crate::impl_client_v17__sendmany!();
124+
crate::impl_client_v17__sendtoaddress!();
125+
crate::impl_client_v17__signmessage!();
126+
crate::impl_client_v17__signrawtransactionwithwallet!();
127+
crate::impl_client_v17__walletcreatefundedpsbt!();
128+
crate::impl_client_v17__walletprocesspsbt!();

0 commit comments

Comments
 (0)