Skip to content

Implement lockunspent method and test #278

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

Merged
merged 2 commits into from
Jul 1, 2025
Merged
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 @@ -143,6 +143,7 @@ crate::impl_client_v17__list_transactions!();
crate::impl_client_v17__list_unspent!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v17__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
Expand Down
16 changes: 16 additions & 0 deletions client/src/client_sync/v17/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,22 @@ macro_rules! impl_client_v17__load_wallet {
};
}

/// Implements Bitcoin Core JSON-RPC API method `loadwallet`.
#[macro_export]
macro_rules! impl_client_v17__lock_unspent {
() => {
impl Client {
pub fn lock_unspent(&self) -> Result<LockUnspent> {
self.call("lockunspent", &[into_json(false)?])
}

pub fn unlock_unspent(&self) -> Result<LockUnspent> {
self.call("lockunspent", &[into_json(true)?])
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `rescanblockchain`.
#[macro_export]
macro_rules! impl_client_v17__rescan_blockchain {
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 @@ -160,6 +160,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -156,6 +156,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v17__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -153,6 +153,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v17__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -155,6 +155,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v17__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -155,6 +155,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v17__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -157,6 +157,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -154,6 +154,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -154,6 +154,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -160,6 +160,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -156,6 +156,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -158,6 +158,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -158,6 +158,7 @@ crate::impl_client_v17__list_unspent!();
crate::impl_client_v18__list_wallet_dir!();
crate::impl_client_v17__list_wallets!();
crate::impl_client_v22__load_wallet!();
crate::impl_client_v17__lock_unspent!();
crate::impl_client_v17__rescan_blockchain!();
crate::impl_client_v17__send_many!();
crate::impl_client_v17__send_to_address!();
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 @@ -509,6 +509,18 @@ fn wallet__load_wallet__modelled() {
create_load_unload_wallet();
}

#[test]
fn wallet__lock_unspent() {
let node = Node::with_wallet(Wallet::Default, &[]);
node.fund_wallet();

let json: LockUnspent = node.client.lock_unspent().expect("lockunspent");
assert!(json.0);

let json: LockUnspent = node.client.unlock_unspent().expect("unlockunspent");
assert!(json.0);
}

// This is tested in raw_transactions.rs `create_sign_send()`.
#[test]
fn wallet__sign_raw_transaction_with_wallet__modelled() {}
Expand Down
8 changes: 4 additions & 4 deletions types/src/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
//! | listunspent | version + model | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | move | returns boolean | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
Expand Down Expand Up @@ -283,9 +283,9 @@ pub use self::{
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspent, ListUnspentItem,
ListUnspentItemError, ListWallets, LoadWallet, RescanBlockchain, SendMany, SendToAddress,
SignMessage, TransactionCategory, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
WalletProcessPsbt,
ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, RescanBlockchain, SendMany,
SendToAddress, SignMessage, TransactionCategory, WalletCreateFundedPsbt,
WalletCreateFundedPsbtError, WalletProcessPsbt,
},
zmq::GetZmqNotifications,
};
Expand Down
9 changes: 9 additions & 0 deletions types/src/v17/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,15 @@ impl LoadWallet {
pub fn name(self) -> String { self.into_model().name }
}

/// Result of JSON-RPC method `lockunspent`.
///
/// > lockunspent
/// >
/// > Arguments:
/// > 1. unlock (boolean, required) Whether to unlock (true) or lock (false) the specified transactions.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct LockUnspent(pub bool);

/// Result of the JSON-RPC method `rescanblockchain`.
///
/// > rescanblockchain ("start_height") ("stop_height")
Expand Down
6 changes: 3 additions & 3 deletions types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | sendmany | version + model | UNTESTED |
Expand Down Expand Up @@ -273,8 +273,8 @@ pub use crate::v17::{
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked, Logging,
MapMempoolEntryError, MempoolAcceptance, MempoolEntryError, MempoolEntryFees,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent, Locked,
Logging, MapMempoolEntryError, MempoolAcceptance, MempoolEntryError, MempoolEntryFees,
MempoolEntryFeesError, PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript, RawTransaction,
RawTransactionError, RawTransactionInput, RawTransactionOutput, RescanBlockchain, SendMany,
SendRawTransaction, SendToAddress, SetNetworkActive, SignFail, SignFailError, SignMessage,
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 @@ -195,7 +195,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | sendmany | version + model | UNTESTED |
Expand Down Expand Up @@ -274,7 +274,7 @@ pub use crate::v17::{
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet,
Locked, Logging, PruneBlockchain, RawTransactionError, RawTransactionInput,
LockUnspent, Locked, Logging, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget,
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 @@ -196,7 +196,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | sendmany | version + model | UNTESTED |
Expand Down Expand Up @@ -265,7 +265,7 @@ pub use crate::{
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
Expand Down
6 changes: 3 additions & 3 deletions types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | send | version + model | TODO |
Expand Down Expand Up @@ -271,8 +271,8 @@ pub use crate::{
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
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 @@ -210,7 +210,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | send | version + model | TODO |
Expand Down Expand Up @@ -281,7 +281,7 @@ pub use crate::{
ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError,
ListSinceBlockTransaction, ListSinceBlockTransactionError, ListTransactions,
ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError, ListWallets,
LoadWallet, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
LoadWallet, LockUnspent, Locked, PruneBlockchain, RawTransactionError, RawTransactionInput,
RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction, SendToAddress,
SetNetworkActive, SignMessage, SignMessageWithPrivKey, SignRawTransaction,
SignRawTransactionError, SoftforkReject, TestMempoolAccept, TransactionCategory,
Expand Down
6 changes: 3 additions & 3 deletions types/src/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | restorewallet | version + model | TODO |
Expand Down Expand Up @@ -280,8 +280,8 @@ pub use crate::{
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
Expand Down
6 changes: 3 additions & 3 deletions types/src/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
//! | listwalletdir | version | |
//! | listwallets | version + model | UNTESTED |
//! | loadwallet | version + model | |
//! | lockunspent | returns boolean | |
//! | lockunspent | version | |
//! | removeprunedfunds | returns nothing | |
//! | rescanblockchain | version + model | UNTESTED |
//! | restorewallet | version + model | TODO |
Expand Down Expand Up @@ -282,8 +282,8 @@ pub use crate::{
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked,
PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, LockUnspent,
Locked, PruneBlockchain, RawTransactionError, RawTransactionInput, RawTransactionOutput,
RescanBlockchain, SendMany, SendRawTransaction, SendToAddress, SetNetworkActive,
SignMessage, SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError,
SoftforkReject, TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress,
Expand Down
Loading