feat: update wallet::Balance to use bitcoin::Amount

- update all fields `immature`, ` trusted_pending`, `unstrusted_pending`
  and `confirmed` to use the `bitcoin::Amount` instead of `u64`
- update all `impl Balance` methods to use `bitcoin::Amount`
- update all tests that relies on `keychain::Balance`
This commit is contained in:
Leonardo Lima
2024-04-24 18:12:45 -03:00
parent 08fac47c29
commit 8a33d98db9
15 changed files with 127 additions and 120 deletions

View File

@@ -506,11 +506,11 @@ where
let chain = &*chain.lock().unwrap();
fn print_balances<'a>(
title_str: &'a str,
items: impl IntoIterator<Item = (&'a str, u64)>,
items: impl IntoIterator<Item = (&'a str, Amount)>,
) {
println!("{}:", title_str);
for (name, amount) in items.into_iter() {
println!(" {:<10} {:>12} sats", name, amount)
println!(" {:<10} {:>12} sats", name, amount.to_sat())
}
}

View File

@@ -6,7 +6,7 @@ const BATCH_SIZE: usize = 5;
use std::io::Write;
use std::str::FromStr;
use bdk::bitcoin::Address;
use bdk::bitcoin::{Address, Amount};
use bdk::wallet::Update;
use bdk::{bitcoin::Network, Wallet};
use bdk::{KeychainKind, SignOptions};
@@ -81,7 +81,8 @@ fn main() -> Result<(), anyhow::Error> {
let balance = wallet.get_balance();
println!("Wallet balance after syncing: {} sats", balance.total());
if balance.total() < SEND_AMOUNT {
// TODO: (@leonardo) Should we format here, or update on constant and TxBuilder::add_recipient() instead ?
if balance.total() < Amount::from_sat(SEND_AMOUNT) {
println!(
"Please send at least {} sats to the receiving address",
SEND_AMOUNT

View File

@@ -1,7 +1,7 @@
use std::{collections::BTreeSet, io::Write, str::FromStr};
use bdk::{
bitcoin::{Address, Network, Script},
bitcoin::{Address, Amount, Network, Script},
KeychainKind, SignOptions, Wallet,
};
use bdk_esplora::{esplora_client, EsploraAsyncExt};
@@ -81,7 +81,8 @@ async fn main() -> Result<(), anyhow::Error> {
let balance = wallet.get_balance();
println!("Wallet balance after syncing: {} sats", balance.total());
if balance.total() < SEND_AMOUNT {
// TODO: (@leonardo) Should we format here, or update on constant and TxBuilder::add_recipient() instead ?
if balance.total() < Amount::from_sat(SEND_AMOUNT) {
println!(
"Please send at least {} sats to the receiving address",
SEND_AMOUNT

View File

@@ -6,7 +6,7 @@ const PARALLEL_REQUESTS: usize = 1;
use std::{collections::BTreeSet, io::Write, str::FromStr};
use bdk::{
bitcoin::{Address, Network},
bitcoin::{Address, Amount, Network},
KeychainKind, SignOptions, Wallet,
};
use bdk_esplora::{esplora_client, EsploraExt};
@@ -57,7 +57,8 @@ fn main() -> Result<(), anyhow::Error> {
let balance = wallet.get_balance();
println!("Wallet balance after syncing: {} sats", balance.total());
if balance.total() < SEND_AMOUNT {
// TODO: (@leonardo) Should we format here, or update on constant and TxBuilder::add_recipient() instead ?
if balance.total() < Amount::from_sat(SEND_AMOUNT) {
println!(
"Please send at least {} sats to the receiving address",
SEND_AMOUNT