Skip to content

Commit f1c40b3

Browse files
committed
Add deprecated warning field for loadwallet/cratewallet` responses
With `v25` the `warning` field was deprecated for `warnings`. While it should only be available when the `-deprecatedrpc=walletwarningfield` is passed, I was hitting parse errors even though I did not find where I passed this argument. Here, we add the `warning` field to the `v25` types (although we ignore it as it's literally duplicative of what's in `warnings` already) to avoid the parse error.
1 parent 79efa7f commit f1c40b3

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

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)