Skip to content

Address all TODO in v24 #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/client_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ macro_rules! define_jsonrpc_minreq_client {
let transport = jsonrpc::http::minreq_http::Builder::new()
.url(url)
.expect("jsonrpc v0.18, this function does not error")
.timeout(std::time::Duration::from_secs(60))
.build();
let inner = jsonrpc::client::Client::with_transport(transport);

Expand All @@ -99,6 +100,7 @@ macro_rules! define_jsonrpc_minreq_client {
let transport = jsonrpc::http::minreq_http::Builder::new()
.url(url)
.expect("jsonrpc v0.18, this function does not error")
.timeout(std::time::Duration::from_secs(60))
.basic_auth(user.unwrap(), pass)
.build();
let inner = jsonrpc::client::Client::with_transport(transport);
Expand Down
31 changes: 31 additions & 0 deletions client/src/client_sync/v24/blockchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is methods found under the `== Blockchain ==` section of the
//! API docs of Bitcoin Core `v24`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.

/// Implements Bitcoin Core JSON-RPC API method `gettxspendingprevout`
#[macro_export]
macro_rules! impl_client_v24__get_tx_spending_prevout {
() => {
impl Client {
pub fn get_tx_spending_prevout(
&self,
outputs: &[bitcoin::OutPoint],
) -> Result<GetTxSpendingPrevout> {
let json_outputs: Vec<_> = outputs.iter().map(|out| {
serde_json::json!({
"txid": out.txid.to_string(),
"vout": out.vout,
})
Comment on lines +22 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is odd here, we should be able to use into_json(out).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I tried first but got the error "JSON value of type string is not of expected type object".

into_json(outputs) gives:

Array [String("943682170364f0a4ea99f3364b4f2aa682343baae4c8b1eea15de788cb073bc8:0"), String("5069674b175134818f301fd51d41f55230c6ab592170f3d79e67b51610b328a7:0")]

json_outputs that works as an argument for the RPC is:

Array [Object {"txid": String("56b067fed4743116139e3c9a2e2cf2b6bf5c864a59fcfce4c8e92e896c1b2947"), "vout": Number(0)}, Object {"txid": String("3fcd727c4efbc0808597722bff13aed989eb8af2e1808ba62d09e05aa3581b9a"), "vout": Number(0)}]

Using into_json on the OutPoint directly make a single field txid:vout not separate like json_outputs above.

}).collect();
self.call("gettxspendingprevout", &[json_outputs.into()])
}
}
};
}
7 changes: 7 additions & 0 deletions client/src/client_sync/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//!
//! We ignore option arguments unless they effect the shape of the returned JSON data.

pub mod blockchain;
pub mod wallet;

use std::collections::BTreeMap;
use std::path::Path;

Expand Down Expand Up @@ -48,6 +51,7 @@ crate::impl_client_v17__get_raw_mempool!();
crate::impl_client_v17__get_tx_out!();
crate::impl_client_v17__get_tx_out_proof!();
crate::impl_client_v17__get_tx_out_set_info!();
crate::impl_client_v24__get_tx_spending_prevout!();
crate::impl_client_v17__precious_block!();
crate::impl_client_v17__prune_blockchain!();
crate::impl_client_v23__save_mempool!();
Expand Down Expand Up @@ -167,19 +171,22 @@ crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v24__migrate_wallet!();
crate::impl_client_v23__new_keypool!();
crate::impl_client_v21__psbt_bump_fee!();
crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v23__restore_wallet!();
crate::impl_client_v21__send!();
crate::impl_client_v24__send_all!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v24__simulate_raw_transaction!();
crate::impl_client_v21__unload_wallet!();
crate::impl_client_v21__upgrade_wallet!();
crate::impl_client_v17__wallet_create_funded_psbt!();
Expand Down
49 changes: 49 additions & 0 deletions client/src/client_sync/v24/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is methods found under the `== Wallet ==` section of the
//! API docs of Bitcoin Core `v24`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.

/// Implements Bitcoin Core JSON-RPC API method `migratewallet`.
#[macro_export]
macro_rules! impl_client_v24__migrate_wallet {
() => {
impl Client {
pub fn migrate_wallet(&self, wallet_name: &str) -> Result<MigrateWallet> {
self.call("migratewallet", &[wallet_name.into()])
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `sendall`.
#[macro_export]
macro_rules! impl_client_v24__send_all {
() => {
impl Client {
pub fn send_all(&self, recipients: &[Address]) -> Result<SendAll> {
self.call("sendall", &[into_json(recipients)?])
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `simulaterawtransaction`.
#[macro_export]
macro_rules! impl_client_v24__simulate_raw_transaction {
() => {
impl Client {
pub fn simulate_raw_transaction(
&self,
rawtxs: &[String],
) -> Result<SimulateRawTransaction> {
self.call("simulaterawtransaction", &[into_json(rawtxs)?])
}
}
};
}
4 changes: 4 additions & 0 deletions client/src/client_sync/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ crate::impl_client_v17__get_raw_mempool!();
crate::impl_client_v17__get_tx_out!();
crate::impl_client_v17__get_tx_out_proof!();
crate::impl_client_v17__get_tx_out_set_info!();
crate::impl_client_v24__get_tx_spending_prevout!();
crate::impl_client_v17__precious_block!();
crate::impl_client_v17__prune_blockchain!();
crate::impl_client_v23__save_mempool!();
Expand Down Expand Up @@ -169,19 +170,22 @@ crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v24__migrate_wallet!();
crate::impl_client_v23__new_keypool!();
crate::impl_client_v21__psbt_bump_fee!();
crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v23__restore_wallet!();
crate::impl_client_v21__send!();
crate::impl_client_v24__send_all!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v24__simulate_raw_transaction!();
crate::impl_client_v21__unload_wallet!();
crate::impl_client_v21__upgrade_wallet!();
crate::impl_client_v17__wallet_create_funded_psbt!();
Expand Down
4 changes: 4 additions & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ crate::impl_client_v17__get_raw_mempool!();
crate::impl_client_v17__get_tx_out!();
crate::impl_client_v17__get_tx_out_proof!();
crate::impl_client_v26__get_tx_out_set_info!();
crate::impl_client_v24__get_tx_spending_prevout!();
crate::impl_client_v17__precious_block!();
crate::impl_client_v17__prune_blockchain!();
crate::impl_client_v23__save_mempool!();
Expand Down Expand Up @@ -173,19 +174,22 @@ crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v24__migrate_wallet!();
crate::impl_client_v23__new_keypool!();
crate::impl_client_v21__psbt_bump_fee!();
crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v23__restore_wallet!();
crate::impl_client_v21__send!();
crate::impl_client_v24__send_all!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v24__simulate_raw_transaction!();
crate::impl_client_v21__unload_wallet!();
crate::impl_client_v21__upgrade_wallet!();
crate::impl_client_v17__wallet_create_funded_psbt!();
Expand Down
4 changes: 4 additions & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ crate::impl_client_v17__get_raw_mempool!();
crate::impl_client_v17__get_tx_out!();
crate::impl_client_v17__get_tx_out_proof!();
crate::impl_client_v26__get_tx_out_set_info!();
crate::impl_client_v24__get_tx_spending_prevout!();
crate::impl_client_v17__precious_block!();
crate::impl_client_v17__prune_blockchain!();
crate::impl_client_v23__save_mempool!();
Expand Down Expand Up @@ -169,19 +170,22 @@ crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v24__migrate_wallet!();
crate::impl_client_v23__new_keypool!();
crate::impl_client_v21__psbt_bump_fee!();
crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v23__restore_wallet!();
crate::impl_client_v21__send!();
crate::impl_client_v24__send_all!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v24__simulate_raw_transaction!();
crate::impl_client_v21__unload_wallet!();
crate::impl_client_v21__upgrade_wallet!();
crate::impl_client_v17__wallet_create_funded_psbt!();
Expand Down
4 changes: 4 additions & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ crate::impl_client_v17__get_raw_mempool!();
crate::impl_client_v17__get_tx_out!();
crate::impl_client_v17__get_tx_out_proof!();
crate::impl_client_v26__get_tx_out_set_info!();
crate::impl_client_v24__get_tx_spending_prevout!();
crate::impl_client_v17__precious_block!();
crate::impl_client_v17__prune_blockchain!();
crate::impl_client_v23__save_mempool!();
Expand Down Expand Up @@ -171,19 +172,22 @@ crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v24__migrate_wallet!();
crate::impl_client_v23__new_keypool!();
crate::impl_client_v21__psbt_bump_fee!();
crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v23__restore_wallet!();
crate::impl_client_v21__send!();
crate::impl_client_v24__send_all!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v24__simulate_raw_transaction!();
crate::impl_client_v21__unload_wallet!();
crate::impl_client_v21__upgrade_wallet!();
crate::impl_client_v17__wallet_create_funded_psbt!();
Expand Down
4 changes: 4 additions & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ crate::impl_client_v17__get_raw_mempool!();
crate::impl_client_v17__get_tx_out!();
crate::impl_client_v17__get_tx_out_proof!();
crate::impl_client_v26__get_tx_out_set_info!();
crate::impl_client_v24__get_tx_spending_prevout!();
crate::impl_client_v17__precious_block!();
crate::impl_client_v17__prune_blockchain!();
crate::impl_client_v23__save_mempool!();
Expand Down Expand Up @@ -171,19 +172,22 @@ crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v24__migrate_wallet!();
crate::impl_client_v23__new_keypool!();
crate::impl_client_v21__psbt_bump_fee!();
crate::impl_client_v17__remove_pruned_funds!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v23__restore_wallet!();
crate::impl_client_v21__send!();
crate::impl_client_v24__send_all!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
crate::impl_client_v17__set_hd_seed!();
crate::impl_client_v17__set_tx_fee!();
crate::impl_client_v19__set_wallet_flag!();
crate::impl_client_v17__sign_message!();
crate::impl_client_v17__sign_raw_transaction_with_wallet!();
crate::impl_client_v24__simulate_raw_transaction!();
crate::impl_client_v21__unload_wallet!();
crate::impl_client_v21__upgrade_wallet!();
crate::impl_client_v17__wallet_create_funded_psbt!();
Expand Down
29 changes: 29 additions & 0 deletions integration_test/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,35 @@ fn blockchain__get_tx_out_set_info__modelled() {
model.unwrap();
}

#[test]
#[cfg(not(feature = "v23_and_below"))]
fn blockchain__get_tx_spending_prevout__modelled() {
let node = Node::with_wallet(Wallet::Default, &[]);
node.fund_wallet();

let (_address1, txid_1) = node.create_mempool_transaction();
let (_address2, txid_2) = node.create_mempool_transaction();

let inputs = vec![
bitcoin::OutPoint {
txid: txid_1,
vout: 0,
},
bitcoin::OutPoint {
txid: txid_2,
vout: 0,
},
];

let json: GetTxSpendingPrevout = node.client.get_tx_spending_prevout(&inputs).expect("gettxspendingprevout");
let model: Result<mtype::GetTxSpendingPrevout, GetTxSpendingPrevoutError> = json.into_model();
let spending_prevout = model.unwrap();

assert_eq!(spending_prevout.0.len(), 2);
assert_eq!(spending_prevout.0[0].outpoint.txid, txid_1);
assert_eq!(spending_prevout.0[0].outpoint.vout, 0);
}

#[test]
fn blockchain__precious_block() {
let node = Node::with_wallet(Wallet::Default, &[]);
Expand Down
Loading