Skip to content

Implement encryptwallet method and test #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v17__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
13 changes: 13 additions & 0 deletions client/src/client_sync/v17/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ macro_rules! impl_client_v17__dump_wallet {
};
}

/// Implements Bitcoin Core JSON-RPC API method `encryptwallet`.
#[macro_export]
macro_rules! impl_client_v17__encrypt_wallet {
() => {
impl Client {
// filename is either absolute or relative to bitcoind.
pub fn encrypt_wallet(&self, passphrase: &str) -> Result<EncryptWallet> {
self.call("encryptwallet", &[into_json(passphrase)?])
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `getaddressesbylabel`.
#[macro_export]
macro_rules! impl_client_v17__get_addresses_by_label {
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v17__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v17__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v17__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v17__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v18__get_received_by_label!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v17__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v18__get_received_by_label!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ crate::impl_client_v17__bump_fee!();
crate::impl_client_v23__create_wallet!();
crate::impl_client_v17__dump_priv_key!();
crate::impl_client_v17__dump_wallet!();
crate::impl_client_v17__encrypt_wallet!();
crate::impl_client_v17__get_addresses_by_label!();
crate::impl_client_v17__get_address_info!();
crate::impl_client_v17__get_balance!();
Expand Down
12 changes: 12 additions & 0 deletions integration_test/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ fn wallet__dump_wallet() {
}
}

#[test]
fn wallet__encrypt_wallet() {
let node = Node::with_wallet(Wallet::None, &[]);

// NOTE: Create a new wallet and returns a dedicated client instance for it.
// This client will send RPCs to the `/wallet/test-wallet` endpoint.
let wallet_client = node.create_wallet("test-wallet").expect("createwallet");

// Use the dedicated client to encrypt the new wallet
let _: EncryptWallet = wallet_client.encrypt_wallet("test-passphrase").expect("encryptwallet");
}

#[test]
fn wallet__get_addresses_by_label__modelled() {
let node = Node::with_wallet(Wallet::Default, &[]);
Expand Down
4 changes: 2 additions & 2 deletions types/src/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaccount | returns nothing | |
//! | getaccountaddress | returns nothing | |
//! | getaddressbyaccount | returns nothing | |
Expand Down Expand Up @@ -272,7 +272,7 @@ pub use self::{
},
wallet::{
AbortRescan, AddMultisigAddress, AddMultisigAddressError, AddressInformation, BumpFee,
BumpFeeError, CreateWallet, DumpPrivKey, DumpWallet, GetAddressInfo,
BumpFeeError, CreateWallet, DumpPrivKey, DumpWallet, EncryptWallet, GetAddressInfo,
GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetNewAddress, GetRawChangeAddress,
GetReceivedByAddress, GetTransaction, GetTransactionDetail, GetTransactionDetailError,
Expand Down
15 changes: 15 additions & 0 deletions types/src/v17/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ pub struct DumpWallet {
pub file_name: String,
}

/// Result of the JSON-RPC method `encryptwallet`.
///
/// > encryptwallet "passphrase"
/// >
/// > Encrypts the wallet with 'passphrase'. This is for first time encryption.
/// > After this, any calls that interact with private keys such as sending or signing
/// > will require the passphrase to be set prior the making these calls.
/// > Use the walletpassphrase call for this, and then walletlock call.
/// > If the wallet is already encrypted, use the walletpassphrasechange call.
/// >
/// > Arguments:
/// > 1. passphrase (string, required) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct EncryptWallet(pub String);

/// Result of the JSON-RPC method `getaddressesbylabel`.
///
/// > getaddressesbylabel "label"
Expand Down
12 changes: 6 additions & 6 deletions types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaddressesbylabel | version + model | |
//! | getaddressinfo | version + model | UNTESTED |
//! | getbalance | version + model | |
Expand Down Expand Up @@ -252,11 +252,11 @@ pub use crate::v17::{
BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus, CombinePsbt, CombineRawTransaction,
ConvertToPsbt, CreateMultisig, CreateMultisigError, CreatePsbt, CreateRawTransaction,
CreateWallet, DecodePsbt, DecodePsbtError, DecodeRawTransaction, DecodeScript,
DecodeScriptError, DumpPrivKey, DumpWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError,
FundRawTransaction, FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo,
GetAddressInfo, GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash, GetBlockCount,
GetBlockHash, GetBlockHeader, GetBlockHeaderError, GetBlockHeaderVerbose,
DecodeScriptError, DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee, FinalizePsbt,
FinalizePsbtError, FundRawTransaction, FundRawTransactionError, Generate, GenerateToAddress,
GetAddedNodeInfo, GetAddressInfo, GetAddressInfoEmbedded, GetAddressInfoEmbeddedError,
GetAddressInfoError, GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash,
GetBlockCount, GetBlockHash, GetBlockHeader, GetBlockHeaderError, GetBlockHeaderVerbose,
GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError, GetBlockTemplate,
GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError, GetBlockVerboseZero,
GetBlockchainInfo, GetBlockchainInfoError, GetChainTips, GetChainTxStats, GetChainTxStatsError,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaddressesbylabel | version + model | |
//! | getaddressinfo | version + model | UNTESTED |
//! | getbalance | version + model | |
Expand Down Expand Up @@ -247,7 +247,7 @@ pub use crate::v17::{
AddressInformation, Banned, BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus,
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisig, CreateMultisigError,
CreatePsbt, CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError,
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet,
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet, EncryptWallet,
EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction, FundRawTransactionError,
Generate, GenerateToAddress, GetAddedNodeInfo, GetAddressInfo, GetAddressInfoEmbedded,
GetAddressInfoEmbeddedError, GetAddressInfoError, GetAddressInfoLabel, GetAddressesByLabel,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaddressesbylabel | version + model | |
//! | getaddressinfo | version + model | UNTESTED |
//! | getbalance | version + model | |
Expand Down Expand Up @@ -242,7 +242,7 @@ pub use crate::{
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisig, CreateMultisigError,
CreatePsbt, CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError,
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet,
EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo, GetAddressInfo,
GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash, GetBlockCount,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaddressesbylabel | version + model | |
//! | getaddressinfo | version + model | UNTESTED |
//! | getbalance | version + model | |
Expand Down Expand Up @@ -244,7 +244,7 @@ pub use crate::{
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisig, CreateMultisigError,
CreatePsbt, CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError,
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet,
EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo, GetAddressInfo,
GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash, GetBlockCount,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaddressesbylabel | version + model | |
//! | getaddressinfo | version + model | UNTESTED |
//! | getbalance | version + model | |
Expand Down Expand Up @@ -259,7 +259,7 @@ pub use crate::{
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisig, CreateMultisigError,
CreatePsbt, CreateRawTransaction, CreateWallet, DecodePsbt, DecodePsbtError,
DecodeRawTransaction, DecodeScript, DecodeScriptError, DumpPrivKey, DumpWallet,
EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
EncryptWallet, EstimateSmartFee, FinalizePsbt, FinalizePsbtError, FundRawTransaction,
FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo, GetAddressInfo,
GetAddressInfoEmbedded, GetAddressInfoEmbeddedError, GetAddressInfoError,
GetAddressInfoLabel, GetAddressesByLabel, GetBalance, GetBestBlockHash, GetBlockCount,
Expand Down
4 changes: 2 additions & 2 deletions types/src/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
//! | createwallet | version + model | |
//! | dumpprivkey | version + model | |
//! | dumpwallet | version + model | |
//! | encryptwallet | returns nothing | |
//! | encryptwallet | version | |
//! | getaddressesbylabel | version + model | |
//! | getaddressinfo | version + model | UNTESTED |
//! | getbalance | version + model | |
Expand Down Expand Up @@ -253,7 +253,7 @@ pub use crate::{
AddressInformation, BumpFee, BumpFeeError, ChainTips, ChainTipsError, ChainTipsStatus,
CombinePsbt, CombineRawTransaction, ConvertToPsbt, CreateMultisig, CreateMultisigError,
CreatePsbt, CreateRawTransaction, CreateWallet, DecodeRawTransaction, DecodeScript,
DecodeScriptError, DumpPrivKey, DumpWallet, EstimateSmartFee, FinalizePsbt,
DecodeScriptError, DumpPrivKey, DumpWallet, EncryptWallet, EstimateSmartFee, FinalizePsbt,
FinalizePsbtError, FundRawTransaction, FundRawTransactionError, Generate,
GenerateToAddress, GetAddedNodeInfo, GetAddressInfo, GetAddressInfoEmbedded,
GetAddressInfoEmbeddedError, GetAddressInfoError, GetAddressInfoLabel, GetAddressesByLabel,
Expand Down
Loading