Skip to content
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
11 changes: 8 additions & 3 deletions integration_test/tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ fn wallet__get_unconfirmed_balance__modelled() {
}

#[test]
#[cfg(feature = "v29_and_below")]
fn wallet__get_wallet_info__modelled() {
let node = Node::with_wallet(Wallet::Default, &[]);
node.mine_a_block();
Expand Down Expand Up @@ -815,7 +814,7 @@ fn wallet__list_unspent__modelled() {
}

#[test]
#[cfg(all(feature = "v29_and_below", not(feature = "v17")))]
#[cfg(not(feature = "v17"))]
fn wallet__list_wallet_dir() {
let wallet_name = "test-wallet";
let node = Node::with_wallet(Wallet::None, &[]);
Expand Down Expand Up @@ -865,6 +864,8 @@ fn wallet__lock_unspent() {
#[test]
#[cfg(all(feature = "v29_and_below", not(feature = "v23_and_below")))]
fn wallet__migrate_wallet() {
// In v30 it is no longer possible to create a legacy wallet.
// It is tested in v29 and has no documented changes in v30.
let node = Node::with_wallet(Wallet::None, &["-deprecatedrpc=create_bdb"]);
let wallet_name = "legacy_wallet";
node.client.create_legacy_wallet(wallet_name).expect("createlegacywallet");
Expand Down Expand Up @@ -1012,9 +1013,13 @@ fn wallet__send_to_address__modelled() {
}

#[test]
#[cfg(feature = "v29_and_below")]
#[cfg(feature = "v30_and_below")]
fn wallet__set_tx_fee() {
#[cfg(feature = "v29_and_below")]
let node = Node::with_wallet(Wallet::Default, &[]);
#[cfg(not(feature = "v29_and_below"))]
let node = Node::with_wallet(Wallet::Default, &["-deprecatedrpc=settxfee"]);

let fee_rate = FeeRate::from_sat_per_vb(2).expect("2 sat/vb is valid");

let json: SetTxFee = node.client.set_tx_fee(fee_rate).expect("settxfee");
Expand Down
19 changes: 11 additions & 8 deletions types/src/model/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,17 @@ pub struct GetWalletInfo {
pub wallet_version: u32,
/// Database format. v21 and later only.
pub format: Option<String>,
/// The total confirmed balance of the wallet in BTC.
pub balance: Amount,
/// The total unconfirmed balance of the wallet in BTC.
pub unconfirmed_balance: Amount,
/// The total immature balance of the wallet in BTC.
pub immature_balance: Amount,
/// The total number of transactions in the wallet
/// The total confirmed balance of the wallet in BTC. v17 to v29 only.
pub balance: Option<Amount>,
/// The total unconfirmed balance of the wallet in BTC. v17 to v29 only.
pub unconfirmed_balance: Option<Amount>,
/// The total immature balance of the wallet in BTC. v17 to v29 only.
pub immature_balance: Option<Amount>,
/// The total number of transactions in the wallet.
pub tx_count: u32,
/// The timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool.
pub keypool_oldest: u32,
/// v17 to v29 only.
pub keypool_oldest: Option<u32>,
/// How many new keys are pre-generated (only counts external keys).
pub keypool_size: u32,
/// How many new keys are pre-generated for internal use (used for change outputs, only appears
Expand All @@ -474,6 +475,8 @@ pub struct GetWalletInfo {
pub blank: Option<bool>,
/// The start time for blocks scanning. v26 and later only.
pub birthtime: Option<u32>,
/// The flags currently set on the wallet. v30 and later only.
pub flags: Option<Vec<String>>,
/// Hash and height of the block this information was generated on. v26 and later only.
pub last_processed_block: Option<LastProcessedBlock>,
}
Expand Down
9 changes: 5 additions & 4 deletions types/src/v17/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ impl GetWalletInfo {
wallet_name: self.wallet_name,
wallet_version,
format: None,
balance,
unconfirmed_balance,
immature_balance,
balance: Some(balance),
unconfirmed_balance: Some(unconfirmed_balance),
immature_balance: Some(immature_balance),
tx_count,
keypool_oldest,
keypool_oldest: Some(keypool_oldest),
keypool_size,
keypool_size_hd_internal,
unlocked_until: self.unlocked_until,
Expand All @@ -455,6 +455,7 @@ impl GetWalletInfo {
external_signer: None,
blank: None,
birthtime: None,
flags: None,
last_processed_block: None,
})
}
Expand Down
9 changes: 5 additions & 4 deletions types/src/v18/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ impl GetWalletInfo {
wallet_name: self.wallet_name,
wallet_version,
format: None,
balance,
unconfirmed_balance,
immature_balance,
balance: Some(balance),
unconfirmed_balance: Some(unconfirmed_balance),
immature_balance: Some(immature_balance),
tx_count,
keypool_oldest,
keypool_oldest: Some(keypool_oldest),
keypool_size,
keypool_size_hd_internal,
unlocked_until: self.unlocked_until,
Expand All @@ -208,6 +208,7 @@ impl GetWalletInfo {
external_signer: None,
blank: None,
birthtime: None,
flags: None,
last_processed_block: None,
})
}
Expand Down
9 changes: 5 additions & 4 deletions types/src/v19/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ impl GetWalletInfo {
wallet_name: self.wallet_name,
wallet_version,
format: None,
balance,
unconfirmed_balance,
immature_balance,
balance: Some(balance),
unconfirmed_balance: Some(unconfirmed_balance),
immature_balance: Some(immature_balance),
tx_count,
keypool_oldest,
keypool_oldest: Some(keypool_oldest),
keypool_size,
keypool_size_hd_internal,
unlocked_until: self.unlocked_until,
Expand All @@ -155,6 +155,7 @@ impl GetWalletInfo {
external_signer: None,
blank: None,
birthtime: None,
flags: None,
last_processed_block: None,
})
}
Expand Down
9 changes: 5 additions & 4 deletions types/src/v21/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl GetWalletInfo {
Ok(model::GetWalletInfo {
wallet_name: self.wallet_name,
wallet_version,
balance,
unconfirmed_balance,
immature_balance,
balance: Some(balance),
unconfirmed_balance: Some(unconfirmed_balance),
immature_balance: Some(immature_balance),
tx_count,
keypool_oldest,
keypool_oldest: Some(keypool_oldest),
keypool_size,
keypool_size_hd_internal,
unlocked_until: self.unlocked_until,
Expand All @@ -111,6 +111,7 @@ impl GetWalletInfo {
external_signer: None,
blank: None,
birthtime: None,
flags: None,
last_processed_block: None,
})
}
Expand Down
9 changes: 5 additions & 4 deletions types/src/v23/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ impl GetWalletInfo {
Ok(model::GetWalletInfo {
wallet_name: self.wallet_name,
wallet_version,
balance,
unconfirmed_balance,
immature_balance,
balance: Some(balance),
unconfirmed_balance: Some(unconfirmed_balance),
immature_balance: Some(immature_balance),
tx_count,
keypool_oldest: keypool_oldest.unwrap_or(0),
keypool_oldest: Some(keypool_oldest.unwrap_or(0)),
keypool_size,
keypool_size_hd_internal: keypool_size_hd_internal.unwrap_or(0),
unlocked_until: self.unlocked_until,
Expand All @@ -139,6 +139,7 @@ impl GetWalletInfo {
external_signer: Some(self.external_signer),
blank: None,
birthtime: None,
flags: None,
last_processed_block: None,
})
}
Expand Down
9 changes: 5 additions & 4 deletions types/src/v26/wallet/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ impl GetWalletInfo {
wallet_name: self.wallet_name,
wallet_version,
format: Some(self.format),
balance,
unconfirmed_balance,
immature_balance,
balance: Some(balance),
unconfirmed_balance: Some(unconfirmed_balance),
immature_balance: Some(immature_balance),
tx_count,
keypool_oldest: keypool_oldest.unwrap_or(0),
keypool_oldest: Some(keypool_oldest.unwrap_or(0)),
keypool_size,
keypool_size_hd_internal: keypool_size_hd_internal.unwrap_or(0),
unlocked_until: self.unlocked_until,
Expand All @@ -164,6 +164,7 @@ impl GetWalletInfo {
external_signer: Some(self.external_signer),
blank: Some(self.blank),
birthtime: self.birthtime,
flags: None,
last_processed_block,
})
}
Expand Down
21 changes: 12 additions & 9 deletions types/src/v30/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@
//! | getreceivedbyaddress | version + model | |
//! | getreceivedbylabel | version + model | |
//! | gettransaction | version + model | |
//! | getwalletinfo | version + model | TODO |
//! | getwalletinfo | version + model | |
//! | importdescriptors | version | |
//! | importprunedfunds | returns nothing | |
//! | keypoolrefill | returns nothing | |
//! | listaddressgroupings | version + model | |
//! | listdescriptors | version | |
//! | listlabels | version | |
//! | listlockunspent | version + model | |
//! | migratewallet | version | TODO |
//! | migratewallet | version | Untested in v30, unchanged from v29 |
//! | psbtbumpfee | version + model | |
//! | listreceivedbyaddress | version + model | |
//! | listreceivedbylabel | version + model | |
//! | listsinceblock | version + model | |
//! | listtransactions | version + model | |
//! | listunspent | version + model | |
//! | listwalletdir | version | TODO |
//! | listwalletdir | version | |
//! | listwallets | version + model | |
//! | loadwallet | version + model | |
//! | lockunspent | version | |
Expand All @@ -218,7 +218,7 @@
//! | sendmany | version + model | |
//! | sendtoaddress | version + model | |
//! | setlabel | returns nothing | |
//! | settxfee | version | TODO |
//! | settxfee | version | |
//! | setwalletflag | version | |
//! | signmessage | version + model | |
//! | signrawtransactionwithwallet | version + model | |
Expand All @@ -245,6 +245,7 @@
mod blockchain;
mod mining;
mod raw_transactions;
mod wallet;

#[doc(inline)]
pub use self::{
Expand All @@ -256,6 +257,10 @@ pub use self::{
TaprootLeaf, TaprootLeafError, TaprootScript, TaprootScriptError, TaprootScriptPathSig,
TaprootScriptPathSigError,
},
wallet::{
GetWalletInfo, GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock,
LastProcessedBlockError, ListWalletDir, ListWalletDirWallet,
},
};
#[doc(inline)]
pub use crate::{
Expand Down Expand Up @@ -289,8 +294,7 @@ pub use crate::{
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
AnalyzePsbtInputMissingError, DeriveAddresses, GetAddressInfoError, GetReceivedByLabel,
GetZmqNotifications, JoinPsbts, JsonRpcError, ListReceivedByAddress,
ListReceivedByAddressItem, ListReceivedByLabel, ListReceivedByLabelError, ListWalletDir,
ListWalletDirWallet, UtxoUpdatePsbt,
ListReceivedByAddressItem, ListReceivedByLabel, ListReceivedByLabelError, UtxoUpdatePsbt,
},
v19::{
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalancesMine,
Expand Down Expand Up @@ -325,9 +329,8 @@ pub use crate::{
v26::{
AddrManInfoNetwork, CreateWallet, DescriptorProcessPsbt, DescriptorProcessPsbtError,
DumpTxOutSet, DumpTxOutSetError, GetAddrManInfo, GetBalances, GetBalancesError,
GetPeerInfo, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock, LastProcessedBlockError,
LoadTxOutSet, LoadTxOutSetError, LoadWallet, PeerInfo, UnloadWallet, WalletProcessPsbt,
GetPeerInfo, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, LoadTxOutSet,
LoadTxOutSetError, LoadWallet, PeerInfo, UnloadWallet, WalletProcessPsbt,
WalletProcessPsbtError,
},
v27::{GetPrioritisedTransactions, PrioritisedTransaction},
Expand Down
79 changes: 79 additions & 0 deletions types/src/v30/wallet/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: CC0-1.0

use core::fmt;

use bitcoin::amount::ParseAmountError;
use bitcoin::hex;

use crate::error::write_err;
use crate::NumericError;

/// Error when converting a `GetWalletInfo` type into the model type.
#[derive(Debug)]
pub enum GetWalletInfoError {
/// Conversion of numeric type to expected type failed.
Numeric(NumericError),
/// Conversion of the `pay_tx_fee` field failed.
PayTxFee(ParseAmountError),
/// Conversion of the `last_processed_block` field failed.
LastProcessedBlock(LastProcessedBlockError),
}

impl fmt::Display for GetWalletInfoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Numeric(ref e) => write_err!(f, "numeric"; e),
Self::PayTxFee(ref e) =>
write_err!(f, "conversion of the `pay_tx_fee` field failed"; e),
Self::LastProcessedBlock(ref e) =>
write_err!(f, "conversion of the `last_processed_block` field failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for GetWalletInfoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Numeric(ref e) => Some(e),
Self::PayTxFee(ref e) => Some(e),
Self::LastProcessedBlock(ref e) => Some(e),
}
}
}

impl From<NumericError> for GetWalletInfoError {
fn from(e: NumericError) -> Self { Self::Numeric(e) }
}

/// Error when converting a `LastProcessedBlock` type into the model type.
#[derive(Debug)]
pub enum LastProcessedBlockError {
/// Conversion of the `hash` field failed.
Hash(hex::HexToArrayError),
/// Conversion of the `height` field failed.
Height(NumericError),
}

impl fmt::Display for LastProcessedBlockError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e),
Self::Height(ref e) => write_err!(f, "conversion of the `height` field failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for LastProcessedBlockError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Hash(ref e) => Some(e),
Self::Height(ref e) => Some(e),
}
}
}

impl From<NumericError> for LastProcessedBlockError {
fn from(e: NumericError) -> Self { Self::Height(e) }
}
Loading