|
| 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 | +} |
0 commit comments