Merge bitcoindevkit/bdk#1455: refactor(wallet): rename get_balance() to balance()

50137b0425fe9c9aac8caaacf099bfe6c69859c2 refactor(wallet): rename get_balance() to balance() (Steve Myers)

Pull request description:

  ### Description

  fixes #1221

  ### Notes to the reviewers

  See discussion in #1221.

  ### Changelog notice

  Changed

  - Wallet::get_balance() renamed to Wallet::balance()

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  LagginTimes:
    ACK 50137b0425fe9c9aac8caaacf099bfe6c69859c2
  oleonardolima:
    ACK 50137b0425fe9c9aac8caaacf099bfe6c69859c2
  evanlinjin:
    ACK 50137b0425fe9c9aac8caaacf099bfe6c69859c2

Tree-SHA512: 20d188a32c79eca37b4f269e5bcdb8c2ecd595911558cb74812a37da13a4f39b603deed3bc11356aa6523b16417a2a025046b3dd4df5bd7247f39c29d7f48ac2
This commit is contained in:
Steve Myers 2024-06-04 17:07:13 -05:00
commit 363d9f42e5
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
8 changed files with 14 additions and 14 deletions

View File

@ -101,7 +101,7 @@ fn main() {
<!-- wallet.sync(&blockchain, SyncOptions::default())?; --> <!-- wallet.sync(&blockchain, SyncOptions::default())?; -->
<!-- println!("Descriptor balance: {} SAT", wallet.get_balance()?); --> <!-- println!("Descriptor balance: {} SAT", wallet.balance()?); -->
<!-- Ok(()) --> <!-- Ok(()) -->
<!-- } --> <!-- } -->

View File

@ -1215,7 +1215,7 @@ impl Wallet {
/// Return the balance, separated into available, trusted-pending, untrusted-pending and immature /// Return the balance, separated into available, trusted-pending, untrusted-pending and immature
/// values. /// values.
pub fn get_balance(&self) -> Balance { pub fn balance(&self) -> Balance {
self.indexed_graph.graph().balance( self.indexed_graph.graph().balance(
&self.chain, &self.chain,
self.chain.tip().block_id(), self.chain.tip().block_id(),

View File

@ -171,7 +171,7 @@ fn test_psbt_multiple_internalkey_signers() {
let keypair = Keypair::from_secret_key(&secp, &prv.inner); let keypair = Keypair::from_secret_key(&secp, &prv.inner);
let (mut wallet, _) = get_funded_wallet(&desc); let (mut wallet, _) = get_funded_wallet(&desc);
let to_spend = wallet.get_balance().total(); let to_spend = wallet.balance().total();
let send_to = wallet.peek_address(KeychainKind::External, 0); let send_to = wallet.peek_address(KeychainKind::External, 0);
let mut builder = wallet.build_tx(); let mut builder = wallet.build_tx();
builder.drain_to(send_to.script_pubkey()).drain_wallet(); builder.drain_to(send_to.script_pubkey()).drain_wallet();

View File

@ -292,7 +292,7 @@ fn test_get_funded_wallet_balance() {
// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000 // The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
// to a foreign address and one returning 50_000 back to the wallet as change. The remaining 1000 // to a foreign address and one returning 50_000 back to the wallet as change. The remaining 1000
// sats are the transaction fee. // sats are the transaction fee.
assert_eq!(wallet.get_balance().confirmed, Amount::from_sat(50_000)); assert_eq!(wallet.balance().confirmed, Amount::from_sat(50_000));
} }
#[test] #[test]
@ -3713,7 +3713,7 @@ fn test_spend_coinbase() {
let not_yet_mature_time = confirmation_height + COINBASE_MATURITY - 1; let not_yet_mature_time = confirmation_height + COINBASE_MATURITY - 1;
let maturity_time = confirmation_height + COINBASE_MATURITY; let maturity_time = confirmation_height + COINBASE_MATURITY;
let balance = wallet.get_balance(); let balance = wallet.balance();
assert_eq!( assert_eq!(
balance, balance,
Balance { Balance {
@ -3764,7 +3764,7 @@ fn test_spend_coinbase() {
hash: BlockHash::all_zeros(), hash: BlockHash::all_zeros(),
}) })
.unwrap(); .unwrap();
let balance = wallet.get_balance(); let balance = wallet.balance();
assert_eq!( assert_eq!(
balance, balance,
Balance { Balance {

View File

@ -33,7 +33,7 @@ fn main() -> Result<(), anyhow::Error> {
let address = wallet.next_unused_address(KeychainKind::External)?; let address = wallet.next_unused_address(KeychainKind::External)?;
println!("Generated Address: {}", address); println!("Generated Address: {}", address);
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance before syncing: {} sats", balance.total()); println!("Wallet balance before syncing: {} sats", balance.total());
print!("Syncing..."); print!("Syncing...");
@ -65,7 +65,7 @@ fn main() -> Result<(), anyhow::Error> {
wallet.apply_update(update)?; wallet.apply_update(update)?;
wallet.commit()?; wallet.commit()?;
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance after syncing: {} sats", balance.total()); println!("Wallet balance after syncing: {} sats", balance.total());
if balance.total() < SEND_AMOUNT { if balance.total() < SEND_AMOUNT {

View File

@ -30,7 +30,7 @@ async fn main() -> Result<(), anyhow::Error> {
let address = wallet.next_unused_address(KeychainKind::External)?; let address = wallet.next_unused_address(KeychainKind::External)?;
println!("Generated Address: {}", address); println!("Generated Address: {}", address);
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance before syncing: {} sats", balance.total()); println!("Wallet balance before syncing: {} sats", balance.total());
print!("Syncing..."); print!("Syncing...");
@ -78,7 +78,7 @@ async fn main() -> Result<(), anyhow::Error> {
wallet.commit()?; wallet.commit()?;
println!(); println!();
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance after syncing: {} sats", balance.total()); println!("Wallet balance after syncing: {} sats", balance.total());
if balance.total() < SEND_AMOUNT { if balance.total() < SEND_AMOUNT {

View File

@ -29,7 +29,7 @@ fn main() -> Result<(), anyhow::Error> {
let address = wallet.next_unused_address(KeychainKind::External)?; let address = wallet.next_unused_address(KeychainKind::External)?;
println!("Generated Address: {}", address); println!("Generated Address: {}", address);
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance before syncing: {} sats", balance.total()); println!("Wallet balance before syncing: {} sats", balance.total());
print!("Syncing..."); print!("Syncing...");
@ -55,7 +55,7 @@ fn main() -> Result<(), anyhow::Error> {
wallet.commit()?; wallet.commit()?;
println!(); println!();
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance after syncing: {} sats", balance.total()); println!("Wallet balance after syncing: {} sats", balance.total());
if balance.total() < SEND_AMOUNT { if balance.total() < SEND_AMOUNT {

View File

@ -100,7 +100,7 @@ fn main() -> anyhow::Result<()> {
start_load_wallet.elapsed().as_secs_f32() start_load_wallet.elapsed().as_secs_f32()
); );
let balance = wallet.get_balance(); let balance = wallet.balance();
println!("Wallet balance before syncing: {} sats", balance.total()); println!("Wallet balance before syncing: {} sats", balance.total());
let wallet_tip = wallet.latest_checkpoint(); let wallet_tip = wallet.latest_checkpoint();
@ -163,7 +163,7 @@ fn main() -> anyhow::Result<()> {
} }
} }
let wallet_tip_end = wallet.latest_checkpoint(); let wallet_tip_end = wallet.latest_checkpoint();
let balance = wallet.get_balance(); let balance = wallet.balance();
println!( println!(
"Synced {} blocks in {}s", "Synced {} blocks in {}s",
blocks_received, blocks_received,