Skip to content

Commit 5adeeae

Browse files
committed
Add sendall method, model and test
Add the struct, model, client macro, reexports and test.
1 parent 8610326 commit 5adeeae

File tree

19 files changed

+150
-14
lines changed

19 files changed

+150
-14
lines changed

client/src/client_sync/v24/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
77
pub mod blockchain;
8+
pub mod wallet;
89

910
use std::collections::BTreeMap;
1011
use std::path::Path;
@@ -176,6 +177,7 @@ crate::impl_client_v17__remove_pruned_funds!();
176177
crate::impl_client_v17__rescan_blockchain!();
177178
crate::impl_client_v23__restore_wallet!();
178179
crate::impl_client_v21__send!();
180+
crate::impl_client_v24__send_all!();
179181
crate::impl_client_v17__send_many!();
180182
crate::impl_client_v17__send_to_address!();
181183
crate::impl_client_v17__set_hd_seed!();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 `sendall`.
13+
#[macro_export]
14+
macro_rules! impl_client_v24__send_all {
15+
() => {
16+
impl Client {
17+
pub fn send_all(&self, recipients: &[Address]) -> Result<SendAll> {
18+
self.call("sendall", &[into_json(recipients)?])
19+
}
20+
}
21+
};
22+
}

client/src/client_sync/v25/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ crate::impl_client_v17__remove_pruned_funds!();
176176
crate::impl_client_v17__rescan_blockchain!();
177177
crate::impl_client_v23__restore_wallet!();
178178
crate::impl_client_v21__send!();
179+
crate::impl_client_v24__send_all!();
179180
crate::impl_client_v17__send_many!();
180181
crate::impl_client_v17__send_to_address!();
181182
crate::impl_client_v17__set_hd_seed!();

client/src/client_sync/v26/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ crate::impl_client_v17__remove_pruned_funds!();
180180
crate::impl_client_v17__rescan_blockchain!();
181181
crate::impl_client_v23__restore_wallet!();
182182
crate::impl_client_v21__send!();
183+
crate::impl_client_v24__send_all!();
183184
crate::impl_client_v17__send_many!();
184185
crate::impl_client_v17__send_to_address!();
185186
crate::impl_client_v17__set_hd_seed!();

client/src/client_sync/v27/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ crate::impl_client_v17__remove_pruned_funds!();
176176
crate::impl_client_v17__rescan_blockchain!();
177177
crate::impl_client_v23__restore_wallet!();
178178
crate::impl_client_v21__send!();
179+
crate::impl_client_v24__send_all!();
179180
crate::impl_client_v17__send_many!();
180181
crate::impl_client_v17__send_to_address!();
181182
crate::impl_client_v17__set_hd_seed!();

client/src/client_sync/v28/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ crate::impl_client_v17__remove_pruned_funds!();
178178
crate::impl_client_v17__rescan_blockchain!();
179179
crate::impl_client_v23__restore_wallet!();
180180
crate::impl_client_v21__send!();
181+
crate::impl_client_v24__send_all!();
181182
crate::impl_client_v17__send_many!();
182183
crate::impl_client_v17__send_to_address!();
183184
crate::impl_client_v17__set_hd_seed!();

client/src/client_sync/v29/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ crate::impl_client_v17__remove_pruned_funds!();
178178
crate::impl_client_v17__rescan_blockchain!();
179179
crate::impl_client_v23__restore_wallet!();
180180
crate::impl_client_v21__send!();
181+
crate::impl_client_v24__send_all!();
181182
crate::impl_client_v17__send_many!();
182183
crate::impl_client_v17__send_to_address!();
183184
crate::impl_client_v17__set_hd_seed!();

integration_test/tests/wallet.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,18 @@ fn wallet__send__modelled() {
647647
model.unwrap();
648648
}
649649

650+
#[cfg(not(feature = "v23_and_below"))]
651+
#[test]
652+
fn wallet__send_all__modelled() {
653+
let node = Node::with_wallet(Wallet::Default, &[]);
654+
node.fund_wallet();
655+
let address = node.client.new_address().expect("failed to create new address");
656+
657+
let json: SendAll = node.client.send_all(&[address]).expect("sendall");
658+
let model: Result<mtype::SendAll, SendAllError> = json.into_model();
659+
model.unwrap();
660+
}
661+
650662
#[test]
651663
fn wallet__send_to_address__modelled() {
652664
let node = Node::with_wallet(Wallet::Default, &[]);

types/src/model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub use self::{
6161
ListLockUnspent, ListLockUnspentItem, ListReceivedByAddress, ListReceivedByAddressItem,
6262
ListReceivedByLabel, ListReceivedByLabelItem, ListSinceBlock, ListSinceBlockTransaction,
6363
ListTransactions, ListTransactionsItem, ListUnspent, ListUnspentItem, ListWallets,
64-
LoadWallet, PsbtBumpFee, RescanBlockchain, ScriptType, Send, SendMany, SendToAddress,
64+
LoadWallet, PsbtBumpFee, RescanBlockchain, ScriptType, Send, SendAll, SendMany, SendToAddress,
6565
SignMessage, TransactionCategory, UnloadWallet, WalletCreateFundedPsbt,
6666
WalletDisplayAddress, WalletProcessPsbt,
6767
},

types/src/model/wallet.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,21 @@ pub struct Send {
751751
pub psbt: Option<Psbt>,
752752
}
753753

754+
/// Models the result of JSON-RPC method `sendall`.
755+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
756+
#[serde(deny_unknown_fields)]
757+
pub struct SendAll {
758+
/// If the transaction has a complete set of signatures.
759+
pub complete: bool,
760+
/// The transaction id for the send. Only 1 transaction is created regardless of the number of addresses.
761+
pub txid: Option<Txid>,
762+
/// If add_to_wallet is false, the hex-encoded raw transaction with signature(s).
763+
pub hex: Option<Transaction>,
764+
/// If more signatures are needed, or if add_to_wallet is false, the base64-encoded (partially)
765+
/// signed transaction.
766+
pub psbt: Option<Psbt>,
767+
}
768+
754769
/// Models the result of JSON-RPC method `sendmany`.
755770
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
756771
#[serde(deny_unknown_fields)]

0 commit comments

Comments
 (0)