Skip to content

Commit 79e814b

Browse files
committed
Fix up unloadwallet
Starting at Core version 21 the `unloadwallet` method starts returning a json object (with warnings in it). Prior to v21 it returned null. There is a mistake in the client currently, the `unloadwallet` method is changed in v22 but should have been in v21. Fix up the types, the client implementation, and the integration tests to fully test unload. Add an integration test function that creates, loads, unloads a random wallet. As a side note, keep the test names `load_wallet`, `unload_wallet` and call the other function - this is done so that the tests can be verified with the `verify` tool.
1 parent 5db564b commit 79e814b

File tree

29 files changed

+141
-47
lines changed

29 files changed

+141
-47
lines changed

client/src/client_sync/v17/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ crate::impl_client_v17__sendmany!();
101101
crate::impl_client_v17__sendtoaddress!();
102102
crate::impl_client_v17__signmessage!();
103103
crate::impl_client_v17__signrawtransactionwithwallet!();
104+
crate::impl_client_v17__unloadwallet!();
104105
crate::impl_client_v17__walletcreatefundedpsbt!();
105106
crate::impl_client_v17__walletprocesspsbt!();
106107

client/src/client_sync/v17/wallet.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,22 @@ macro_rules! impl_client_v17__signrawtransactionwithwallet {
432432
};
433433
}
434434

435+
/// Implements Bitcoin Core JSON-RPC API method `unloadwallet`.
436+
#[macro_export]
437+
macro_rules! impl_client_v17__unloadwallet {
438+
() => {
439+
impl Client {
440+
pub fn unload_wallet(&self, wallet_name: &str) -> Result<()> {
441+
match self.call("unloadwallet", &[into_json(wallet_name)?]) {
442+
Ok(serde_json::Value::Null) => Ok(()),
443+
Ok(res) => Err(Error::Returned(res.to_string())),
444+
Err(err) => Err(err.into()),
445+
}
446+
}
447+
}
448+
};
449+
}
450+
435451
/// Implements Bitcoin Core JSON-RPC API method `walletcreatefundedpsbt`.
436452
#[macro_export]
437453
macro_rules! impl_client_v17__walletcreatefundedpsbt {

client/src/client_sync/v18/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ crate::impl_client_v17__sendmany!();
9696
crate::impl_client_v17__sendtoaddress!();
9797
crate::impl_client_v17__signmessage!();
9898
crate::impl_client_v17__signrawtransactionwithwallet!();
99+
crate::impl_client_v17__unloadwallet!();
99100
crate::impl_client_v17__walletcreatefundedpsbt!();
100101
crate::impl_client_v17__walletprocesspsbt!();

client/src/client_sync/v19/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ crate::impl_client_v17__sendmany!();
9494
crate::impl_client_v17__sendtoaddress!();
9595
crate::impl_client_v17__signmessage!();
9696
crate::impl_client_v17__signrawtransactionwithwallet!();
97+
crate::impl_client_v17__unloadwallet!();
9798
crate::impl_client_v17__walletcreatefundedpsbt!();
9899
crate::impl_client_v17__walletprocesspsbt!();

client/src/client_sync/v20.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@ crate::impl_client_v17__sendmany!();
9292
crate::impl_client_v17__sendtoaddress!();
9393
crate::impl_client_v17__signmessage!();
9494
crate::impl_client_v17__signrawtransactionwithwallet!();
95+
crate::impl_client_v17__unloadwallet!();
9596
crate::impl_client_v17__walletcreatefundedpsbt!();
9697
crate::impl_client_v17__walletprocesspsbt!();

client/src/client_sync/v21.rs renamed to client/src/client_sync/v21/mod.rs

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

@@ -92,5 +94,6 @@ crate::impl_client_v17__sendmany!();
9294
crate::impl_client_v17__sendtoaddress!();
9395
crate::impl_client_v17__signmessage!();
9496
crate::impl_client_v17__signrawtransactionwithwallet!();
97+
crate::impl_client_v21__unloadwallet!();
9598
crate::impl_client_v17__walletcreatefundedpsbt!();
9699
crate::impl_client_v17__walletprocesspsbt!();

client/src/client_sync/v21/wallet.rs

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 `v21`.
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 `unloadwallet`
13+
#[macro_export]
14+
macro_rules! impl_client_v21__unloadwallet {
15+
() => {
16+
impl Client {
17+
pub fn unload_wallet(&self, wallet: &str) -> Result<UnloadWallet> {
18+
self.call("unloadwallet", &[wallet.into()])
19+
}
20+
}
21+
};
22+
}

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,6 @@ crate::impl_client_v17__sendmany!();
9595
crate::impl_client_v17__sendtoaddress!();
9696
crate::impl_client_v17__signmessage!();
9797
crate::impl_client_v17__signrawtransactionwithwallet!();
98+
crate::impl_client_v21__unloadwallet!();
9899
crate::impl_client_v17__walletcreatefundedpsbt!();
99100
crate::impl_client_v17__walletprocesspsbt!();

client/src/client_sync/v22/wallet.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12-
/// Implements Bitcoin Core JSON-RPC API method `unloadwallet`
13-
#[macro_export]
14-
macro_rules! impl_client_v22__unloadwallet {
15-
() => {
16-
impl Client {
17-
pub fn unload_wallet(&self, wallet: &str) -> Result<UnloadWallet> {
18-
self.call("unloadwallet", &[wallet.into()])
19-
}
20-
}
21-
};
22-
}
23-
2412
/// Implements Bitcoin Core JSON-RPC API method `loadwallet`
2513
#[macro_export]
2614
macro_rules! impl_client_v22__loadwallet {

client/src/client_sync/v23.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ crate::impl_client_v17__sendmany!();
9393
crate::impl_client_v17__sendtoaddress!();
9494
crate::impl_client_v17__signmessage!();
9595
crate::impl_client_v17__signrawtransactionwithwallet!();
96-
crate::impl_client_v22__unloadwallet!();
96+
crate::impl_client_v21__unloadwallet!();
9797
crate::impl_client_v17__walletcreatefundedpsbt!();
9898
crate::impl_client_v17__walletprocesspsbt!();
9999

0 commit comments

Comments
 (0)