Skip to content

Commit b6d31ec

Browse files
committed
Merge #308: Address all TODO in v24
78cbbdc Run the formatter (Jamil Lambert, PhD) 2125b02 Add simulaterawtransaction method, model and test (Jamil Lambert, PhD) 3a9e9be Add migratewallet method and test (Jamil Lambert, PhD) 976bb9e Increase client timeout (Jamil Lambert, PhD) 5adeeae Add sendall method, model and test (Jamil Lambert, PhD) 8610326 Add gettxspendingprevout method, model and test (Jamil Lambert, PhD) Pull request description: Go through all the TODO in the v24 types table. Add all the missing RPCs. - Add `gettxspendingprevout` method, model and test - Add `sendall` method, model and test - Increase `client` timeout - The `migratewallet` RPC call takes about 30sec on v24, it's a lot faster on v29. The default timeout was 15sec, increase it to 60 to prevent the timeout during testing. To quote Core "This RPC may take a long time to complete. Increasing the RPC client timeout is recommended." - Add `migratewallet` method, and test - The help says that `passphrase` is required in v24, but it isn't. The optional argument `wallet_name` was required for testing. There is nothing to model so the types table was updated accordingly. - Add `simulaterawtransaction` method, model and test - The help says that the `rawtxs` are optional, but they are required for testing or nothing is simulated. - Run the formatter ACKs for top commit: tcharding: ACK 78cbbdc Tree-SHA512: 5ceaa4056111d355e87336109f0872f23618dd8bc21be54a66350d26bf1b223041dd2becce99198981cf3fe3e585f88a3615e607f8f53644ede86fc85535e8f2
2 parents f00ea0f + 78cbbdc commit b6d31ec

File tree

32 files changed

+529
-53
lines changed

32 files changed

+529
-53
lines changed

client/src/client_sync/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ macro_rules! define_jsonrpc_minreq_client {
8383
let transport = jsonrpc::http::minreq_http::Builder::new()
8484
.url(url)
8585
.expect("jsonrpc v0.18, this function does not error")
86+
.timeout(std::time::Duration::from_secs(60))
8687
.build();
8788
let inner = jsonrpc::client::Client::with_transport(transport);
8889

@@ -99,6 +100,7 @@ macro_rules! define_jsonrpc_minreq_client {
99100
let transport = jsonrpc::http::minreq_http::Builder::new()
100101
.url(url)
101102
.expect("jsonrpc v0.18, this function does not error")
103+
.timeout(std::time::Duration::from_secs(60))
102104
.basic_auth(user.unwrap(), pass)
103105
.build();
104106
let inner = jsonrpc::client::Client::with_transport(transport);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 `== Blockchain ==` section of the
6+
//! API docs of Bitcoin Core `v24`.
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 `gettxspendingprevout`
13+
#[macro_export]
14+
macro_rules! impl_client_v24__get_tx_spending_prevout {
15+
() => {
16+
impl Client {
17+
pub fn get_tx_spending_prevout(
18+
&self,
19+
outputs: &[bitcoin::OutPoint],
20+
) -> Result<GetTxSpendingPrevout> {
21+
let json_outputs: Vec<_> = outputs.iter().map(|out| {
22+
serde_json::json!({
23+
"txid": out.txid.to_string(),
24+
"vout": out.vout,
25+
})
26+
}).collect();
27+
self.call("gettxspendingprevout", &[json_outputs.into()])
28+
}
29+
}
30+
};
31+
}

client/src/client_sync/v24/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//!
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
7+
pub mod blockchain;
8+
pub mod wallet;
9+
710
use std::collections::BTreeMap;
811
use std::path::Path;
912

@@ -48,6 +51,7 @@ crate::impl_client_v17__get_raw_mempool!();
4851
crate::impl_client_v17__get_tx_out!();
4952
crate::impl_client_v17__get_tx_out_proof!();
5053
crate::impl_client_v17__get_tx_out_set_info!();
54+
crate::impl_client_v24__get_tx_spending_prevout!();
5155
crate::impl_client_v17__precious_block!();
5256
crate::impl_client_v17__prune_blockchain!();
5357
crate::impl_client_v23__save_mempool!();
@@ -166,19 +170,22 @@ crate::impl_client_v18__list_wallet_dir!();
166170
crate::impl_client_v17__list_wallets!();
167171
crate::impl_client_v22__load_wallet!();
168172
crate::impl_client_v17__lock_unspent!();
173+
crate::impl_client_v24__migrate_wallet!();
169174
crate::impl_client_v23__new_keypool!();
170175
crate::impl_client_v21__psbt_bump_fee!();
171176
crate::impl_client_v17__remove_pruned_funds!();
172177
crate::impl_client_v17__rescan_blockchain!();
173178
crate::impl_client_v23__restore_wallet!();
174179
crate::impl_client_v21__send!();
180+
crate::impl_client_v24__send_all!();
175181
crate::impl_client_v17__send_many!();
176182
crate::impl_client_v17__send_to_address!();
177183
crate::impl_client_v17__set_hd_seed!();
178184
crate::impl_client_v17__set_tx_fee!();
179185
crate::impl_client_v19__set_wallet_flag!();
180186
crate::impl_client_v17__sign_message!();
181187
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
188+
crate::impl_client_v24__simulate_raw_transaction!();
182189
crate::impl_client_v21__unload_wallet!();
183190
crate::impl_client_v21__upgrade_wallet!();
184191
crate::impl_client_v17__wallet_create_funded_psbt!();

client/src/client_sync/v24/wallet.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 `== Wallet ==` section of the
6+
//! API docs of Bitcoin Core `v24`.
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 `migratewallet`.
13+
#[macro_export]
14+
macro_rules! impl_client_v24__migrate_wallet {
15+
() => {
16+
impl Client {
17+
pub fn migrate_wallet(&self, wallet_name: &str) -> Result<MigrateWallet> {
18+
self.call("migratewallet", &[wallet_name.into()])
19+
}
20+
}
21+
};
22+
}
23+
24+
/// Implements Bitcoin Core JSON-RPC API method `sendall`.
25+
#[macro_export]
26+
macro_rules! impl_client_v24__send_all {
27+
() => {
28+
impl Client {
29+
pub fn send_all(&self, recipients: &[Address]) -> Result<SendAll> {
30+
self.call("sendall", &[into_json(recipients)?])
31+
}
32+
}
33+
};
34+
}
35+
36+
/// Implements Bitcoin Core JSON-RPC API method `simulaterawtransaction`.
37+
#[macro_export]
38+
macro_rules! impl_client_v24__simulate_raw_transaction {
39+
() => {
40+
impl Client {
41+
pub fn simulate_raw_transaction(
42+
&self,
43+
rawtxs: &[String],
44+
) -> Result<SimulateRawTransaction> {
45+
self.call("simulaterawtransaction", &[into_json(rawtxs)?])
46+
}
47+
}
48+
};
49+
}

client/src/client_sync/v25/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ crate::impl_client_v17__get_raw_mempool!();
5050
crate::impl_client_v17__get_tx_out!();
5151
crate::impl_client_v17__get_tx_out_proof!();
5252
crate::impl_client_v17__get_tx_out_set_info!();
53+
crate::impl_client_v24__get_tx_spending_prevout!();
5354
crate::impl_client_v17__precious_block!();
5455
crate::impl_client_v17__prune_blockchain!();
5556
crate::impl_client_v23__save_mempool!();
@@ -168,19 +169,22 @@ crate::impl_client_v18__list_wallet_dir!();
168169
crate::impl_client_v17__list_wallets!();
169170
crate::impl_client_v22__load_wallet!();
170171
crate::impl_client_v17__lock_unspent!();
172+
crate::impl_client_v24__migrate_wallet!();
171173
crate::impl_client_v23__new_keypool!();
172174
crate::impl_client_v21__psbt_bump_fee!();
173175
crate::impl_client_v17__remove_pruned_funds!();
174176
crate::impl_client_v17__rescan_blockchain!();
175177
crate::impl_client_v23__restore_wallet!();
176178
crate::impl_client_v21__send!();
179+
crate::impl_client_v24__send_all!();
177180
crate::impl_client_v17__send_many!();
178181
crate::impl_client_v17__send_to_address!();
179182
crate::impl_client_v17__set_hd_seed!();
180183
crate::impl_client_v17__set_tx_fee!();
181184
crate::impl_client_v19__set_wallet_flag!();
182185
crate::impl_client_v17__sign_message!();
183186
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
187+
crate::impl_client_v24__simulate_raw_transaction!();
184188
crate::impl_client_v21__unload_wallet!();
185189
crate::impl_client_v21__upgrade_wallet!();
186190
crate::impl_client_v17__wallet_create_funded_psbt!();

client/src/client_sync/v26/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ crate::impl_client_v17__get_raw_mempool!();
5252
crate::impl_client_v17__get_tx_out!();
5353
crate::impl_client_v17__get_tx_out_proof!();
5454
crate::impl_client_v26__get_tx_out_set_info!();
55+
crate::impl_client_v24__get_tx_spending_prevout!();
5556
crate::impl_client_v17__precious_block!();
5657
crate::impl_client_v17__prune_blockchain!();
5758
crate::impl_client_v23__save_mempool!();
@@ -172,19 +173,22 @@ crate::impl_client_v18__list_wallet_dir!();
172173
crate::impl_client_v17__list_wallets!();
173174
crate::impl_client_v22__load_wallet!();
174175
crate::impl_client_v17__lock_unspent!();
176+
crate::impl_client_v24__migrate_wallet!();
175177
crate::impl_client_v23__new_keypool!();
176178
crate::impl_client_v21__psbt_bump_fee!();
177179
crate::impl_client_v17__remove_pruned_funds!();
178180
crate::impl_client_v17__rescan_blockchain!();
179181
crate::impl_client_v23__restore_wallet!();
180182
crate::impl_client_v21__send!();
183+
crate::impl_client_v24__send_all!();
181184
crate::impl_client_v17__send_many!();
182185
crate::impl_client_v17__send_to_address!();
183186
crate::impl_client_v17__set_hd_seed!();
184187
crate::impl_client_v17__set_tx_fee!();
185188
crate::impl_client_v19__set_wallet_flag!();
186189
crate::impl_client_v17__sign_message!();
187190
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
191+
crate::impl_client_v24__simulate_raw_transaction!();
188192
crate::impl_client_v21__unload_wallet!();
189193
crate::impl_client_v21__upgrade_wallet!();
190194
crate::impl_client_v17__wallet_create_funded_psbt!();

client/src/client_sync/v27/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ crate::impl_client_v17__get_raw_mempool!();
4848
crate::impl_client_v17__get_tx_out!();
4949
crate::impl_client_v17__get_tx_out_proof!();
5050
crate::impl_client_v26__get_tx_out_set_info!();
51+
crate::impl_client_v24__get_tx_spending_prevout!();
5152
crate::impl_client_v17__precious_block!();
5253
crate::impl_client_v17__prune_blockchain!();
5354
crate::impl_client_v23__save_mempool!();
@@ -168,19 +169,22 @@ crate::impl_client_v18__list_wallet_dir!();
168169
crate::impl_client_v17__list_wallets!();
169170
crate::impl_client_v22__load_wallet!();
170171
crate::impl_client_v17__lock_unspent!();
172+
crate::impl_client_v24__migrate_wallet!();
171173
crate::impl_client_v23__new_keypool!();
172174
crate::impl_client_v21__psbt_bump_fee!();
173175
crate::impl_client_v17__remove_pruned_funds!();
174176
crate::impl_client_v17__rescan_blockchain!();
175177
crate::impl_client_v23__restore_wallet!();
176178
crate::impl_client_v21__send!();
179+
crate::impl_client_v24__send_all!();
177180
crate::impl_client_v17__send_many!();
178181
crate::impl_client_v17__send_to_address!();
179182
crate::impl_client_v17__set_hd_seed!();
180183
crate::impl_client_v17__set_tx_fee!();
181184
crate::impl_client_v19__set_wallet_flag!();
182185
crate::impl_client_v17__sign_message!();
183186
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
187+
crate::impl_client_v24__simulate_raw_transaction!();
184188
crate::impl_client_v21__unload_wallet!();
185189
crate::impl_client_v21__upgrade_wallet!();
186190
crate::impl_client_v17__wallet_create_funded_psbt!();

client/src/client_sync/v28/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ crate::impl_client_v17__get_raw_mempool!();
5050
crate::impl_client_v17__get_tx_out!();
5151
crate::impl_client_v17__get_tx_out_proof!();
5252
crate::impl_client_v26__get_tx_out_set_info!();
53+
crate::impl_client_v24__get_tx_spending_prevout!();
5354
crate::impl_client_v17__precious_block!();
5455
crate::impl_client_v17__prune_blockchain!();
5556
crate::impl_client_v23__save_mempool!();
@@ -170,19 +171,22 @@ crate::impl_client_v18__list_wallet_dir!();
170171
crate::impl_client_v17__list_wallets!();
171172
crate::impl_client_v22__load_wallet!();
172173
crate::impl_client_v17__lock_unspent!();
174+
crate::impl_client_v24__migrate_wallet!();
173175
crate::impl_client_v23__new_keypool!();
174176
crate::impl_client_v21__psbt_bump_fee!();
175177
crate::impl_client_v17__remove_pruned_funds!();
176178
crate::impl_client_v17__rescan_blockchain!();
177179
crate::impl_client_v23__restore_wallet!();
178180
crate::impl_client_v21__send!();
181+
crate::impl_client_v24__send_all!();
179182
crate::impl_client_v17__send_many!();
180183
crate::impl_client_v17__send_to_address!();
181184
crate::impl_client_v17__set_hd_seed!();
182185
crate::impl_client_v17__set_tx_fee!();
183186
crate::impl_client_v19__set_wallet_flag!();
184187
crate::impl_client_v17__sign_message!();
185188
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
189+
crate::impl_client_v24__simulate_raw_transaction!();
186190
crate::impl_client_v21__unload_wallet!();
187191
crate::impl_client_v21__upgrade_wallet!();
188192
crate::impl_client_v17__wallet_create_funded_psbt!();

client/src/client_sync/v29/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ crate::impl_client_v17__get_raw_mempool!();
5050
crate::impl_client_v17__get_tx_out!();
5151
crate::impl_client_v17__get_tx_out_proof!();
5252
crate::impl_client_v26__get_tx_out_set_info!();
53+
crate::impl_client_v24__get_tx_spending_prevout!();
5354
crate::impl_client_v17__precious_block!();
5455
crate::impl_client_v17__prune_blockchain!();
5556
crate::impl_client_v23__save_mempool!();
@@ -170,19 +171,22 @@ crate::impl_client_v18__list_wallet_dir!();
170171
crate::impl_client_v17__list_wallets!();
171172
crate::impl_client_v22__load_wallet!();
172173
crate::impl_client_v17__lock_unspent!();
174+
crate::impl_client_v24__migrate_wallet!();
173175
crate::impl_client_v23__new_keypool!();
174176
crate::impl_client_v21__psbt_bump_fee!();
175177
crate::impl_client_v17__remove_pruned_funds!();
176178
crate::impl_client_v17__rescan_blockchain!();
177179
crate::impl_client_v23__restore_wallet!();
178180
crate::impl_client_v21__send!();
181+
crate::impl_client_v24__send_all!();
179182
crate::impl_client_v17__send_many!();
180183
crate::impl_client_v17__send_to_address!();
181184
crate::impl_client_v17__set_hd_seed!();
182185
crate::impl_client_v17__set_tx_fee!();
183186
crate::impl_client_v19__set_wallet_flag!();
184187
crate::impl_client_v17__sign_message!();
185188
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
189+
crate::impl_client_v24__simulate_raw_transaction!();
186190
crate::impl_client_v21__unload_wallet!();
187191
crate::impl_client_v21__upgrade_wallet!();
188192
crate::impl_client_v17__wallet_create_funded_psbt!();

integration_test/tests/blockchain.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,35 @@ fn blockchain__get_tx_out_set_info__modelled() {
302302
model.unwrap();
303303
}
304304

305+
#[test]
306+
#[cfg(not(feature = "v23_and_below"))]
307+
fn blockchain__get_tx_spending_prevout__modelled() {
308+
let node = Node::with_wallet(Wallet::Default, &[]);
309+
node.fund_wallet();
310+
311+
let (_address1, txid_1) = node.create_mempool_transaction();
312+
let (_address2, txid_2) = node.create_mempool_transaction();
313+
314+
let inputs = vec![
315+
bitcoin::OutPoint {
316+
txid: txid_1,
317+
vout: 0,
318+
},
319+
bitcoin::OutPoint {
320+
txid: txid_2,
321+
vout: 0,
322+
},
323+
];
324+
325+
let json: GetTxSpendingPrevout = node.client.get_tx_spending_prevout(&inputs).expect("gettxspendingprevout");
326+
let model: Result<mtype::GetTxSpendingPrevout, GetTxSpendingPrevoutError> = json.into_model();
327+
let spending_prevout = model.unwrap();
328+
329+
assert_eq!(spending_prevout.0.len(), 2);
330+
assert_eq!(spending_prevout.0[0].outpoint.txid, txid_1);
331+
assert_eq!(spending_prevout.0[0].outpoint.vout, 0);
332+
}
333+
305334
#[test]
306335
fn blockchain__precious_block() {
307336
let node = Node::with_wallet(Wallet::Default, &[]);

0 commit comments

Comments
 (0)