Skip to content

Commit 5db564b

Browse files
authored
Merge pull request #108 from tnull/2025-03-fix-createloadwallet-v25
Fix `{create,load}wallet` on `v25`
2 parents 188d114 + 99a1cda commit 5db564b

File tree

6 files changed

+104
-7
lines changed

6 files changed

+104
-7
lines changed

integration_test/tests/wallet.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
//! Tests for methods found under the `== Wallet ==` section of the API docs.
44
5-
#![cfg(any(feature = "0_17_1", feature = "0_18_1"))]
6-
75
#[cfg(feature = "TODO")]
86
use bitcoin::address::{Address, NetworkChecked};
97
use bitcoin::Amount;
@@ -23,6 +21,7 @@ pub fn add_multisig_address() {
2321
assert!(json.into_model().is_ok());
2422
}
2523

24+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
2625
#[test]
2726
pub fn bump_fee() {
2827
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -49,6 +48,7 @@ pub fn create_wallet() {
4948
// optional `String` to an optional vector of strings in v25. Needs testing.
5049
}
5150

51+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
5252
#[test]
5353
pub fn dump_priv_key() {
5454
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -57,6 +57,7 @@ pub fn dump_priv_key() {
5757
assert!(json.into_model().is_ok());
5858
}
5959

60+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
6061
#[test]
6162
pub fn dump_wallet() {
6263
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -65,6 +66,7 @@ pub fn dump_wallet() {
6566
let _ = json.into_model();
6667
}
6768

69+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
6870
#[test]
6971
pub fn get_addresses_by_label() {
7072
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -76,6 +78,7 @@ pub fn get_addresses_by_label() {
7678
assert!(map.get(&addr).is_some());
7779
}
7880

81+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
7982
#[test]
8083
// TODO: Consider testing a few different address types.
8184
#[cfg(feature = "TODO")]
@@ -86,6 +89,7 @@ pub fn get_address_info() {
8689
assert!(json.into_model().is_ok());
8790
}
8891

92+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
8993
#[test]
9094
fn get_balance() {
9195
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -97,6 +101,7 @@ fn get_balance() {
97101
assert!(json.into_model().is_ok());
98102
}
99103

104+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
100105
#[test]
101106
#[cfg(feature = "v19")]
102107
fn get_balances() {
@@ -108,6 +113,7 @@ fn get_balances() {
108113
assert!(model.mine.trusted > Amount::ZERO);
109114
}
110115

116+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
111117
#[test]
112118
fn get_new_address() {
113119
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -132,13 +138,15 @@ fn get_new_address() {
132138
.unwrap();
133139
}
134140

141+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
135142
#[test]
136143
fn get_raw_change_address() {
137144
let node = Node::with_wallet(Wallet::Default, &[]);
138145
let json = node.client.get_raw_change_address().expect("getrawchangeaddress");
139146
assert!(json.into_model().is_ok());
140147
}
141148

149+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
142150
#[test]
143151
fn get_received_by_address() {
144152
let amount = Amount::from_sat(10_000);
@@ -160,6 +168,7 @@ fn get_received_by_address() {
160168
assert_eq!(model.0, amount);
161169
}
162170

171+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
163172
#[test]
164173
fn get_transaction() {
165174
let node = Node::with_wallet(Wallet::Default, &[]);
@@ -183,6 +192,7 @@ fn load_wallet() {
183192
let _ = Node::with_wallet(Wallet::Default, &[]);
184193
}
185194

195+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
186196
#[test]
187197
#[cfg(not(any(feature = "v17", feature = "v18", feature = "v19", feature = "v20")))]
188198
fn unload_wallet() {
@@ -193,6 +203,7 @@ fn unload_wallet() {
193203
assert!(json.into_model().is_ok())
194204
}
195205

206+
#[cfg(any(feature = "0_17_1", feature = "0_18_1"))]
196207
#[test]
197208
fn send_to_address() {
198209
let node = Node::with_wallet(Wallet::Default, &[]);

types/src/v25/wallet.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ pub struct CreateWallet {
2929
///
3030
/// If the wallet was created using a full path, the wallet_name will be the full path.
3131
pub name: String,
32+
/// Warning messages, if any, related to creating the wallet. Multiple messages will be delimited by newlines.
33+
///
34+
/// DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed. As
35+
/// the content would still be the same as `warnings`, we simply ignore the field.
36+
pub warning: Option<String>,
3237
/// Warning messages, if any, related to creating and loading the wallet.
3338
pub warnings: Option<Vec<String>>,
3439
}
3540

3641
impl CreateWallet {
3742
/// Converts version specific type to a version nonspecific, more strongly typed type.
3843
pub fn into_model(self) -> model::CreateWallet {
44+
// As the content of the deprecated `warning` field would be the same as `warnings`, we
45+
// simply ignore the field, even in case it's set.
3946
model::CreateWallet { name: self.name, warnings: self.warnings.unwrap_or_default() }
4047
}
4148

@@ -58,13 +65,20 @@ impl CreateWallet {
5865
pub struct LoadWallet {
5966
/// The wallet name if loaded successfully.
6067
pub name: String,
68+
/// Warning messages, if any, related to creating the wallet. Multiple messages will be delimited by newlines.
69+
///
70+
/// DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed. As
71+
/// the content would still be the same as `warnings`, we simply ignore the field.
72+
pub warning: Option<String>,
6173
/// Warning messages, if any, related to loading the wallet.
6274
pub warnings: Option<Vec<String>>,
6375
}
6476

6577
impl LoadWallet {
6678
/// Converts version specific type to a version nonspecific, more strongly typed type.
6779
pub fn into_model(self) -> model::LoadWallet {
80+
// As the content of the deprecated `warning` field would be the same as `warnings`, we
81+
// simply ignore the field, even in case it's set.
6882
model::LoadWallet { name: self.name, warnings: self.warnings.unwrap_or_default() }
6983
}
7084

types/src/v26/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@
247247
//! - Method is deprecated.
248248
249249
mod blockchain;
250+
mod wallet;
250251

251252
#[doc(inline)]
252253
pub use self::blockchain::{GetTxOutSetInfo, GetTxOutSetInfoError};
254+
pub use self::wallet::{CreateWallet, LoadWallet};
253255
#[doc(inline)]
254256
pub use crate::{
255257
v17::{
@@ -283,5 +285,4 @@ pub use crate::{
283285
},
284286
v21::UnloadWallet,
285287
v22::{GetTxOut, GetTxOutError, Logging, ScriptPubkey},
286-
v25::{CreateWallet, LoadWallet},
287288
};

types/src/v26/wallet.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v26` - wallet.
4+
//!
5+
//! Types for methods found under the `== Wallet ==` section of the API docs.
6+
7+
use serde::{Deserialize, Serialize};
8+
9+
use crate::model;
10+
11+
/// Result of the JSON-RPC method `createwallet`.
12+
///
13+
/// > createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup external_signer )
14+
///
15+
/// > Creates and loads a new wallet.
16+
///
17+
/// > Arguments:
18+
/// > 1. wallet_name (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.
19+
/// > 2. disable_private_keys (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
20+
/// > 3. blank (boolean, optional, default=false) Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed.
21+
/// > 4. passphrase (string, optional) Encrypt the wallet with this passphrase.
22+
/// > 5. avoid_reuse (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind.
23+
/// > 6. descriptors (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation. Setting to "false" will create a legacy wallet; however, the legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future.
24+
/// > 7. load_on_startup (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged.
25+
/// > 8. external_signer (boolean, optional, default=false) Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true.
26+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
27+
pub struct CreateWallet {
28+
/// The wallet name if created successfully.
29+
///
30+
/// If the wallet was created using a full path, the wallet_name will be the full path.
31+
pub name: String,
32+
/// Warning messages, if any, related to creating and loading the wallet.
33+
pub warnings: Option<Vec<String>>,
34+
}
35+
36+
impl CreateWallet {
37+
/// Converts version specific type to a version nonspecific, more strongly typed type.
38+
pub fn into_model(self) -> model::CreateWallet {
39+
model::CreateWallet { name: self.name, warnings: self.warnings.unwrap_or_default() }
40+
}
41+
42+
/// Returns the created wallet name.
43+
pub fn name(self) -> String { self.into_model().name }
44+
}
45+
46+
/// Result of the JSON-RPC method `loadwallet`.
47+
///
48+
/// > loadwallet "filename" ( load_on_startup )
49+
///
50+
/// > Loads a wallet from a wallet file or directory.
51+
/// > Note that all wallet command-line options used when starting bitcoind will be
52+
/// > applied to the new wallet.
53+
///
54+
/// > Arguments:
55+
/// > 1. filename (string, required) The wallet directory or .dat file.
56+
/// > 2. load_on_startup (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged.
57+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
58+
pub struct LoadWallet {
59+
/// The wallet name if loaded successfully.
60+
pub name: String,
61+
/// Warning messages, if any, related to loading the wallet.
62+
pub warnings: Option<Vec<String>>,
63+
}
64+
65+
impl LoadWallet {
66+
/// Converts version specific type to a version nonspecific, more strongly typed type.
67+
pub fn into_model(self) -> model::LoadWallet {
68+
model::LoadWallet { name: self.name, warnings: self.warnings.unwrap_or_default() }
69+
}
70+
71+
/// Returns the loaded wallet name.
72+
pub fn name(self) -> String { self.into_model().name }
73+
}

types/src/v27/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,5 @@ pub use crate::{
279279
},
280280
v21::UnloadWallet,
281281
v22::{GetTxOut, GetTxOutError, Logging, ScriptPubkey},
282-
v25::{CreateWallet, LoadWallet},
283-
v26::{GetTxOutSetInfo, GetTxOutSetInfoError},
282+
v26::{CreateWallet, GetTxOutSetInfo, GetTxOutSetInfoError, LoadWallet},
284283
};

types/src/v28/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,5 @@ pub use crate::{
292292
},
293293
v21::UnloadWallet,
294294
v22::{GetTxOut, GetTxOutError, Logging, ScriptPubkey},
295-
v25::{CreateWallet, LoadWallet},
296-
v26::{GetTxOutSetInfo, GetTxOutSetInfoError},
295+
v26::{CreateWallet, GetTxOutSetInfo, GetTxOutSetInfoError, LoadWallet},
297296
};

0 commit comments

Comments
 (0)