Skip to content

Commit 88c69b3

Browse files
committed
Merge #289: Address all TODO in v21
a150076 Add upgradewallet method and test (Jamil Lambert, PhD) f855ead Add psbtbumpfee method, model and test (Jamil Lambert, PhD) 2eecd0f Add send method, model and test (Jamil Lambert, PhD) 0ed10d4 Add importdescriptors method, and test (Jamil Lambert, PhD) 5ee20ed Add create descriptor wallet fn to client (Jamil Lambert, PhD) 8e80267 Move v21 wallet module into subdirectory (Jamil Lambert, PhD) ec52fad Add getindexinfo method, and test (Jamil Lambert, PhD) 73368d4 Add generateblock method, model and test (Jamil Lambert, PhD) Pull request description: Go through all the `TODO` in the v21 types table. Add all the missing RPCs including models when required and tests. Add a new macro `create_wallet_with_descriptors` that creates a descriptor wallet for use with v21 and v22 where the default is a legacy wallet. This is required for the `importdescriptors` test. Move the `wallet` module to a subdirectory since there are multiple new RPCs in v21. ACKs for top commit: tcharding: ACK a150076 Tree-SHA512: 945bde0bf1d0be6b867baa12a79d6f8b823a5e38f6930325d7b3794eb25f7a2f324ac725b99ff24a428dc36aa12f013b74ecd30bd66c1cf3d1b04be4d42388b0
2 parents 6875709 + a150076 commit 88c69b3

File tree

39 files changed

+966
-92
lines changed

39 files changed

+966
-92
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Specifically this is methods found under the `== Generating ==` section of the
6+
//! API docs of Bitcoin Core `v0.21`.
7+
//!
8+
//! All macros require `Client` to be in scope.
9+
//!
10+
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `generateblock`
13+
#[macro_export]
14+
macro_rules! impl_client_v21__generate_block {
15+
() => {
16+
impl Client {
17+
pub fn generate_block(
18+
&self,
19+
output: &str,
20+
transactions: &[String],
21+
) -> Result<GenerateBlock> {
22+
self.call("generateblock", &[into_json(output)?, into_json(transactions)?])
23+
}
24+
}
25+
};
26+
}

client/src/client_sync/v21/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
//!
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
7+
mod generating;
8+
mod util;
79
mod wallet;
810

911
use std::collections::BTreeMap;
1012
use std::path::Path;
1113

1214
use bitcoin::address::{Address, NetworkChecked};
1315
use bitcoin::{sign_message, Amount, Block, BlockHash, PublicKey, Txid};
16+
use serde::{Deserialize, Serialize};
1417

1518
use crate::client_sync::into_json;
1619
use crate::types::v21::*;
@@ -61,6 +64,7 @@ crate::impl_client_v17__stop!();
6164
crate::impl_client_v17__uptime!();
6265

6366
// == Generating ==
67+
crate::impl_client_v21__generate_block!();
6468
crate::impl_client_v17__generate_to_address!();
6569
crate::impl_client_v20__generate_to_descriptor!();
6670
crate::impl_client_v17__invalidate_block!();
@@ -113,6 +117,7 @@ crate::impl_client_v17__create_multisig!();
113117
crate::impl_client_v18__derive_addresses!();
114118
crate::impl_client_v17__estimate_smart_fee!();
115119
crate::impl_client_v18__get_descriptor_info!();
120+
crate::impl_client_v21__get_index_info!();
116121
crate::impl_client_v17__sign_message_with_priv_key!();
117122
crate::impl_client_v17__validate_address!();
118123
crate::impl_client_v17__verify_message!();
@@ -124,6 +129,7 @@ crate::impl_client_v17__add_multisig_address!();
124129
crate::impl_client_v17__backup_wallet!();
125130
crate::impl_client_v17__bump_fee!();
126131
crate::impl_client_v17__create_wallet!();
132+
crate::impl_client_v21__create_wallet_with_descriptors!();
127133
crate::impl_client_v17__dump_priv_key!();
128134
crate::impl_client_v17__dump_wallet!();
129135
crate::impl_client_v17__encrypt_wallet!();
@@ -139,6 +145,7 @@ crate::impl_client_v17__get_transaction!();
139145
crate::impl_client_v17__get_unconfirmed_balance!();
140146
crate::impl_client_v17__get_wallet_info!();
141147
crate::impl_client_v17__import_address!();
148+
crate::impl_client_v21__import_descriptors!();
142149
crate::impl_client_v17__import_multi!();
143150
crate::impl_client_v17__import_privkey!();
144151
crate::impl_client_v17__import_pruned_funds!();
@@ -157,8 +164,10 @@ crate::impl_client_v18__list_wallet_dir!();
157164
crate::impl_client_v17__list_wallets!();
158165
crate::impl_client_v17__load_wallet!();
159166
crate::impl_client_v17__lock_unspent!();
167+
crate::impl_client_v21__psbt_bump_fee!();
160168
crate::impl_client_v17__remove_pruned_funds!();
161169
crate::impl_client_v17__rescan_blockchain!();
170+
crate::impl_client_v21__send!();
162171
crate::impl_client_v17__send_many!();
163172
crate::impl_client_v17__send_to_address!();
164173
crate::impl_client_v17__set_hd_seed!();
@@ -167,6 +176,17 @@ crate::impl_client_v19__set_wallet_flag!();
167176
crate::impl_client_v17__sign_message!();
168177
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
169178
crate::impl_client_v21__unload_wallet!();
179+
crate::impl_client_v21__upgrade_wallet!();
170180
crate::impl_client_v17__wallet_create_funded_psbt!();
171181
crate::impl_client_v17__wallet_lock!();
172182
crate::impl_client_v17__wallet_process_psbt!();
183+
184+
/// Request object for the `importdescriptors` method.
185+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
186+
#[serde(deny_unknown_fields)]
187+
pub struct ImportDescriptorsRequest {
188+
/// Descriptor to import.
189+
pub desc: String,
190+
/// Time from which to start rescanning the blockchain for this descriptor, in UNIX epoch time or "now".
191+
pub timestamp: serde_json::Value,
192+
}

client/src/client_sync/v21/util.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Specifically this is methods found under the `== Util ==` section of the
6+
//! API docs of Bitcoin Core `v0.21`.
7+
//!
8+
//! All macros require `Client` to be in scope.
9+
//!
10+
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `getindexinfo`.
13+
#[macro_export]
14+
macro_rules! impl_client_v21__get_index_info {
15+
() => {
16+
impl Client {
17+
pub fn get_index_info(&self) -> Result<GetIndexInfo> { self.call("getindexinfo", &[]) }
18+
}
19+
};
20+
}

client/src/client_sync/v21/wallet.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,66 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12+
/// Implements Bitcoin Core JSON-RPC API method `createwallet` with descriptors=true (descriptor wallet)
13+
#[macro_export]
14+
macro_rules! impl_client_v21__create_wallet_with_descriptors {
15+
() => {
16+
impl Client {
17+
pub fn create_wallet_with_descriptors(&self, wallet: &str) -> Result<CreateWallet> {
18+
let args = [
19+
wallet.into(),
20+
false.into(), // disable_private_keys
21+
false.into(), // blank
22+
serde_json::Value::Null, // passphrase
23+
false.into(), // avoid_reuse
24+
true.into(), // descriptors=true
25+
serde_json::Value::Null, // load_on_startup
26+
];
27+
self.call("createwallet", &args)
28+
}
29+
}
30+
};
31+
}
32+
33+
/// Implements Bitcoin Core JSON-RPC API method `importdescriptors`
34+
#[macro_export]
35+
macro_rules! impl_client_v21__import_descriptors {
36+
() => {
37+
impl Client {
38+
pub fn import_descriptors(
39+
&self,
40+
requests: &[ImportDescriptorsRequest],
41+
) -> Result<ImportDescriptors> {
42+
self.call("importdescriptors", &[into_json(requests)?])
43+
}
44+
}
45+
};
46+
}
47+
48+
/// Implements Bitcoin Core JSON-RPC API method `psbtbumpfee`.
49+
#[macro_export]
50+
macro_rules! impl_client_v21__psbt_bump_fee {
51+
() => {
52+
impl Client {
53+
pub fn psbt_bump_fee(&self, txid: &bitcoin::Txid) -> Result<PsbtBumpFee> {
54+
self.call("psbtbumpfee", &[into_json(txid)?])
55+
}
56+
}
57+
};
58+
}
59+
60+
/// Implements Bitcoin Core JSON-RPC API method `send`.
61+
#[macro_export]
62+
macro_rules! impl_client_v21__send {
63+
() => {
64+
impl Client {
65+
pub fn send(&self, outputs: &BTreeMap<String, f64>) -> Result<Send> {
66+
self.call("send", &[into_json(outputs)?])
67+
}
68+
}
69+
};
70+
}
71+
1272
/// Implements Bitcoin Core JSON-RPC API method `unloadwallet`
1373
#[macro_export]
1474
macro_rules! impl_client_v21__unload_wallet {
@@ -20,3 +80,15 @@ macro_rules! impl_client_v21__unload_wallet {
2080
}
2181
};
2282
}
83+
84+
/// Implements Bitcoin Core JSON-RPC API method `upgradewallet`.
85+
#[macro_export]
86+
macro_rules! impl_client_v21__upgrade_wallet {
87+
() => {
88+
impl Client {
89+
pub fn upgrade_wallet(&self) -> Result<UpgradeWallet> {
90+
self.call("upgradewallet", &[])
91+
}
92+
}
93+
};
94+
}

client/src/client_sync/v22/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use crate::client_sync::{
2121
AddNodeCommand, AddressType, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp, Input, Output, SetBanCommand, TemplateRequest,
2222
TemplateRules, WalletCreateFundedPsbtInput,
2323
},
24+
v21::ImportDescriptorsRequest,
2425
};
2526

2627
crate::define_jsonrpc_minreq_client!("v22");
@@ -61,6 +62,7 @@ crate::impl_client_v17__stop!();
6162
crate::impl_client_v17__uptime!();
6263

6364
// == Generating ==
65+
crate::impl_client_v21__generate_block!();
6466
crate::impl_client_v17__generate_to_address!();
6567
crate::impl_client_v20__generate_to_descriptor!();
6668
crate::impl_client_v17__invalidate_block!();
@@ -113,6 +115,7 @@ crate::impl_client_v17__create_multisig!();
113115
crate::impl_client_v18__derive_addresses!();
114116
crate::impl_client_v17__estimate_smart_fee!();
115117
crate::impl_client_v18__get_descriptor_info!();
118+
crate::impl_client_v21__get_index_info!();
116119
crate::impl_client_v17__sign_message_with_priv_key!();
117120
crate::impl_client_v17__validate_address!();
118121
crate::impl_client_v17__verify_message!();
@@ -124,6 +127,7 @@ crate::impl_client_v17__add_multisig_address!();
124127
crate::impl_client_v17__backup_wallet!();
125128
crate::impl_client_v17__bump_fee!();
126129
crate::impl_client_v17__create_wallet!();
130+
crate::impl_client_v21__create_wallet_with_descriptors!();
127131
crate::impl_client_v17__dump_priv_key!();
128132
crate::impl_client_v17__dump_wallet!();
129133
crate::impl_client_v17__encrypt_wallet!();
@@ -139,6 +143,7 @@ crate::impl_client_v17__get_transaction!();
139143
crate::impl_client_v17__get_unconfirmed_balance!();
140144
crate::impl_client_v17__get_wallet_info!();
141145
crate::impl_client_v17__import_address!();
146+
crate::impl_client_v21__import_descriptors!();
142147
crate::impl_client_v17__import_multi!();
143148
crate::impl_client_v17__import_privkey!();
144149
crate::impl_client_v17__import_pruned_funds!();
@@ -157,8 +162,10 @@ crate::impl_client_v18__list_wallet_dir!();
157162
crate::impl_client_v17__list_wallets!();
158163
crate::impl_client_v17__load_wallet!();
159164
crate::impl_client_v17__lock_unspent!();
165+
crate::impl_client_v21__psbt_bump_fee!();
160166
crate::impl_client_v17__remove_pruned_funds!();
161167
crate::impl_client_v17__rescan_blockchain!();
168+
crate::impl_client_v21__send!();
162169
crate::impl_client_v17__send_many!();
163170
crate::impl_client_v17__send_to_address!();
164171
crate::impl_client_v17__set_hd_seed!();
@@ -167,6 +174,7 @@ crate::impl_client_v19__set_wallet_flag!();
167174
crate::impl_client_v17__sign_message!();
168175
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
169176
crate::impl_client_v21__unload_wallet!();
177+
crate::impl_client_v21__upgrade_wallet!();
170178
crate::impl_client_v17__wallet_create_funded_psbt!();
171179
crate::impl_client_v17__wallet_lock!();
172180
crate::impl_client_v17__wallet_process_psbt!();

client/src/client_sync/v23/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub use crate::client_sync::{
2323
AddNodeCommand, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp, Input, Output, SetBanCommand, TemplateRequest, TemplateRules,
2424
WalletCreateFundedPsbtInput,
2525
},
26+
v21::ImportDescriptorsRequest,
2627
};
2728

2829
crate::define_jsonrpc_minreq_client!("v23");
@@ -63,6 +64,7 @@ crate::impl_client_v17__stop!();
6364
crate::impl_client_v17__uptime!();
6465

6566
// == Generating ==
67+
crate::impl_client_v21__generate_block!();
6668
crate::impl_client_v17__generate_to_address!();
6769
crate::impl_client_v20__generate_to_descriptor!();
6870
crate::impl_client_v17__invalidate_block!();
@@ -115,6 +117,7 @@ crate::impl_client_v17__create_multisig!();
115117
crate::impl_client_v18__derive_addresses!();
116118
crate::impl_client_v17__estimate_smart_fee!();
117119
crate::impl_client_v18__get_descriptor_info!();
120+
crate::impl_client_v21__get_index_info!();
118121
crate::impl_client_v17__sign_message_with_priv_key!();
119122
crate::impl_client_v17__validate_address!();
120123
crate::impl_client_v17__verify_message!();
@@ -126,6 +129,7 @@ crate::impl_client_v17__add_multisig_address!();
126129
crate::impl_client_v17__backup_wallet!();
127130
crate::impl_client_v17__bump_fee!();
128131
crate::impl_client_v23__create_wallet!();
132+
crate::impl_client_v21__create_wallet_with_descriptors!();
129133
crate::impl_client_v17__dump_priv_key!();
130134
crate::impl_client_v17__dump_wallet!();
131135
crate::impl_client_v17__encrypt_wallet!();
@@ -141,6 +145,7 @@ crate::impl_client_v17__get_transaction!();
141145
crate::impl_client_v17__get_unconfirmed_balance!();
142146
crate::impl_client_v17__get_wallet_info!();
143147
crate::impl_client_v17__import_address!();
148+
crate::impl_client_v21__import_descriptors!();
144149
crate::impl_client_v17__import_multi!();
145150
crate::impl_client_v17__import_privkey!();
146151
crate::impl_client_v17__import_pruned_funds!();
@@ -159,8 +164,10 @@ crate::impl_client_v18__list_wallet_dir!();
159164
crate::impl_client_v17__list_wallets!();
160165
crate::impl_client_v22__load_wallet!();
161166
crate::impl_client_v17__lock_unspent!();
167+
crate::impl_client_v21__psbt_bump_fee!();
162168
crate::impl_client_v17__remove_pruned_funds!();
163169
crate::impl_client_v17__rescan_blockchain!();
170+
crate::impl_client_v21__send!();
164171
crate::impl_client_v17__send_many!();
165172
crate::impl_client_v17__send_to_address!();
166173
crate::impl_client_v17__set_hd_seed!();
@@ -169,6 +176,7 @@ crate::impl_client_v19__set_wallet_flag!();
169176
crate::impl_client_v17__sign_message!();
170177
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
171178
crate::impl_client_v21__unload_wallet!();
179+
crate::impl_client_v21__upgrade_wallet!();
172180
crate::impl_client_v17__wallet_create_funded_psbt!();
173181
crate::impl_client_v17__wallet_lock!();
174182
crate::impl_client_v17__wallet_process_psbt!();

client/src/client_sync/v24/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub use crate::client_sync::{
1919
AddNodeCommand, ImportMultiRequest, ImportMultiScriptPubKey, ImportMultiTimestamp, Input, Output, SetBanCommand, TemplateRequest, TemplateRules,
2020
WalletCreateFundedPsbtInput,
2121
},
22+
v21::ImportDescriptorsRequest,
2223
v23::AddressType,
2324
};
2425

@@ -60,6 +61,7 @@ crate::impl_client_v17__stop!();
6061
crate::impl_client_v17__uptime!();
6162

6263
// == Generating ==
64+
crate::impl_client_v21__generate_block!();
6365
crate::impl_client_v17__generate_to_address!();
6466
crate::impl_client_v20__generate_to_descriptor!();
6567
crate::impl_client_v17__invalidate_block!();
@@ -112,6 +114,7 @@ crate::impl_client_v17__create_multisig!();
112114
crate::impl_client_v18__derive_addresses!();
113115
crate::impl_client_v17__estimate_smart_fee!();
114116
crate::impl_client_v18__get_descriptor_info!();
117+
crate::impl_client_v21__get_index_info!();
115118
crate::impl_client_v17__sign_message_with_priv_key!();
116119
crate::impl_client_v17__validate_address!();
117120
crate::impl_client_v17__verify_message!();
@@ -123,6 +126,7 @@ crate::impl_client_v17__add_multisig_address!();
123126
crate::impl_client_v17__backup_wallet!();
124127
crate::impl_client_v17__bump_fee!();
125128
crate::impl_client_v23__create_wallet!();
129+
crate::impl_client_v21__create_wallet_with_descriptors!();
126130
crate::impl_client_v17__dump_priv_key!();
127131
crate::impl_client_v17__dump_wallet!();
128132
crate::impl_client_v17__encrypt_wallet!();
@@ -138,6 +142,7 @@ crate::impl_client_v17__get_transaction!();
138142
crate::impl_client_v17__get_unconfirmed_balance!();
139143
crate::impl_client_v17__get_wallet_info!();
140144
crate::impl_client_v17__import_address!();
145+
crate::impl_client_v21__import_descriptors!();
141146
crate::impl_client_v17__import_multi!();
142147
crate::impl_client_v17__import_privkey!();
143148
crate::impl_client_v17__import_pruned_funds!();
@@ -156,8 +161,10 @@ crate::impl_client_v18__list_wallet_dir!();
156161
crate::impl_client_v17__list_wallets!();
157162
crate::impl_client_v22__load_wallet!();
158163
crate::impl_client_v17__lock_unspent!();
164+
crate::impl_client_v21__psbt_bump_fee!();
159165
crate::impl_client_v17__remove_pruned_funds!();
160166
crate::impl_client_v17__rescan_blockchain!();
167+
crate::impl_client_v21__send!();
161168
crate::impl_client_v17__send_many!();
162169
crate::impl_client_v17__send_to_address!();
163170
crate::impl_client_v17__set_hd_seed!();
@@ -166,6 +173,7 @@ crate::impl_client_v19__set_wallet_flag!();
166173
crate::impl_client_v17__sign_message!();
167174
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
168175
crate::impl_client_v21__unload_wallet!();
176+
crate::impl_client_v21__upgrade_wallet!();
169177
crate::impl_client_v17__wallet_create_funded_psbt!();
170178
crate::impl_client_v17__wallet_lock!();
171179
crate::impl_client_v17__wallet_process_psbt!();

0 commit comments

Comments
 (0)