chore: bump rust bdk to alpha 11

This commit is contained in:
Matthew 2024-05-11 14:30:15 -05:00
parent f27bada9c9
commit 97d9bb6fbf
No known key found for this signature in database
GPG Key ID: 8D4FCD82DD54DDD2
21 changed files with 269 additions and 85 deletions

View File

@ -3,6 +3,9 @@ Changelog information can also be found in each release's git tag (which can be
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.0-alpha.11]
This release adds the new `Amount` type, as well as more fine-grain errors.
## [1.0.0-alpha.7]
This release brings back into the 1.0 API a number of APIs from the 0.31 release, and adds the new flat file persistence feature, as well as more fine-grain errors.

View File

@ -33,9 +33,9 @@ class LiveTxBuilderTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}
@ -59,9 +59,9 @@ class LiveTxBuilderTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}

View File

@ -33,11 +33,11 @@ class LiveWalletTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
val balance: Balance = wallet.getBalance()
println("Balance: $balance")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}
@ -60,9 +60,9 @@ class LiveWalletTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address} and try again."
}

View File

@ -72,7 +72,7 @@ class OfflineWalletTest {
assertEquals(
expected = 0uL,
actual = wallet.getBalance().total
actual = wallet.getBalance().total.toSat()
)
}
}

20
bdk-ffi/Cargo.lock generated
View File

@ -138,9 +138,9 @@ dependencies = [
[[package]]
name = "bdk"
version = "1.0.0-alpha.10"
version = "1.0.0-alpha.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66fc0ebc2a63463f709cfdfbb7e7877b9975bcaea9d2d4f02f97ad012de37e3b"
checksum = "65c23f2903ac5dbb7b35934ae319aadc946201e4fa51b652440bd1c8fa3080ee"
dependencies = [
"anyhow",
"bdk_chain",
@ -170,9 +170,9 @@ dependencies = [
[[package]]
name = "bdk_chain"
version = "0.13.0"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e879c03ebf3a64643295152a19a8b0e0a3af22e25539d2bc56ce07d07b059c33"
checksum = "440ec5b1c8911f126b540e05c98493b699b497a3cb90c5e9c5eee21cdd8d1e01"
dependencies = [
"bitcoin",
"miniscript",
@ -181,9 +181,9 @@ dependencies = [
[[package]]
name = "bdk_esplora"
version = "0.12.0"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0aad9d99b103cd9c67ce1f4702720f2813db7aeba72abc9628ae9b00462a492"
checksum = "9fb5b46f8c256bc083640342bd0d35ec1963971f18800c3fee1a9189eda60ecd"
dependencies = [
"bdk_chain",
"esplora-client",
@ -191,9 +191,9 @@ dependencies = [
[[package]]
name = "bdk_file_store"
version = "0.10.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "492a011ee853773bce14f2d899fa34fe3ac3b5f39eeb1504d0d2b28de448bd73"
checksum = "5dfd7e9a5edb8d384ea1836b0bcd4febdd3211815acc058d64c7e284776d69ab"
dependencies = [
"anyhow",
"bdk_chain",
@ -204,9 +204,9 @@ dependencies = [
[[package]]
name = "bdk_persist"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f7d6b38071ee828329434f86799e0bb6aaa5a4256e225480c2c53b7b2df295"
checksum = "aba103c2108dd0f0b452650043d21c449ae07ce866dbaea29a9c59899a5964f0"
dependencies = [
"anyhow",
"bdk_chain",

View File

@ -18,9 +18,9 @@ path = "uniffi-bindgen.rs"
default = ["uniffi/cli"]
[dependencies]
bdk = { version = "1.0.0-alpha.10", features = ["all-keys", "keys-bip39"] }
bdk_esplora = { version = "0.12.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
bdk_file_store = { version = "0.10.0" }
bdk = { version = "1.0.0-alpha.11", features = ["all-keys", "keys-bip39"] }
bdk_esplora = { version = "0.13.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
bdk_file_store = { version = "0.11.0" }
uniffi = { version = "=0.26.1" }
bitcoin-internals = { version = "0.2.0", features = ["alloc"] }

View File

@ -131,6 +131,19 @@ enum FeeRateError {
"ArithmeticOverflow"
};
[Error]
interface ParseAmountError {
Negative();
TooBig();
TooPrecise();
InvalidFormat();
InputTooLarge();
InvalidCharacter(string error_message);
UnknownDenomination(string error_message);
PossiblyConfusingDenomination(string error_message);
OtherParseAmountErr();
};
[Error]
interface PersistenceError {
Write(string error_message);
@ -185,6 +198,7 @@ interface WalletCreationError {
NotInitialized();
LoadedGenesisDoesNotMatch(string expected, string got);
LoadedNetworkDoesNotMatch(Network expected, Network? got);
LoadedDescriptorDoesNotMatch(string got, KeychainKind keychain);
};
// ------------------------------------------------------------------------
@ -203,17 +217,17 @@ dictionary AddressInfo {
};
dictionary Balance {
u64 immature;
Amount immature;
u64 trusted_pending;
Amount trusted_pending;
u64 untrusted_pending;
Amount untrusted_pending;
u64 confirmed;
Amount confirmed;
u64 trusted_spendable;
Amount trusted_spendable;
u64 total;
Amount total;
};
dictionary LocalOutput {
@ -302,7 +316,7 @@ interface Update {};
interface TxBuilder {
constructor();
TxBuilder add_recipient([ByRef] Script script, u64 amount);
TxBuilder add_recipient([ByRef] Script script, Amount amount);
TxBuilder set_recipients(sequence<ScriptAmount> recipients);
@ -456,12 +470,12 @@ interface EsploraClient {
dictionary ScriptAmount {
Script script;
u64 amount;
Amount amount;
};
dictionary SentAndReceivedValues {
u64 sent;
u64 received;
Amount sent;
Amount received;
};
// ------------------------------------------------------------------------
@ -543,6 +557,18 @@ dictionary OutPoint {
u32 vout;
};
interface Amount {
[Name=from_sat]
constructor(u64 from_sat);
[Name=from_btc, Throws=ParseAmountError]
constructor(f64 from_btc);
u64 to_sat();
f64 to_btc();
};
interface FeeRate {
[Name=from_sat_per_vb, Throws=FeeRateError]
constructor(u64 sat_per_vb);

View File

@ -18,6 +18,43 @@ use std::io::Cursor;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use bdk::bitcoin::amount::ParseAmountError;
use bdk::bitcoin::Amount as BdkAmount;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Amount(pub(crate) BdkAmount);
impl Amount {
pub fn from_sat(sat: u64) -> Self {
Amount(BdkAmount::from_sat(sat))
}
pub fn from_btc(btc: f64) -> Result<Self, ParseAmountError> {
let bdk_amount = BdkAmount::from_btc(btc).map_err(ParseAmountError::from)?;
Ok(Amount(bdk_amount))
}
pub fn to_sat(&self) -> u64 {
self.0.to_sat()
}
pub fn to_btc(&self) -> f64 {
self.0.to_btc()
}
}
impl From<Amount> for BdkAmount {
fn from(amount: Amount) -> Self {
amount.0
}
}
impl From<BdkAmount> for Amount {
fn from(amount: BdkAmount) -> Self {
Amount(amount)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Script(pub(crate) BdkScriptBuf);

View File

@ -17,12 +17,15 @@ use bdk_esplora::esplora_client::{Error as BdkEsploraError, Error};
use bdk_file_store::FileError as BdkFileError;
use bitcoin_internals::hex::display::DisplayHex;
use bdk::bitcoin::amount::ParseAmountError as BdkParseAmountError;
use std::convert::TryInto;
use bdk::bitcoin::address::Error as BdkAddressError;
use bdk::bitcoin::consensus::encode::Error as BdkEncodeError;
use bdk::bitcoin::psbt::ExtractTxError as BdkExtractTxError;
use bdk::chain::local_chain::CannotConnectError as BdkCannotConnectError;
use bdk::KeychainKind;
// ------------------------------------------------------------------------
// error definitions
@ -317,6 +320,37 @@ pub enum FeeRateError {
ArithmeticOverflow,
}
#[derive(Debug, thiserror::Error)]
pub enum ParseAmountError {
#[error("amount is negative")]
Negative,
#[error("amount is too large")]
TooBig,
#[error("amount is too precise")]
TooPrecise,
#[error("invalid amount format")]
InvalidFormat,
#[error("input is too large")]
InputTooLarge,
#[error("invalid character: {error_message}")]
InvalidCharacter { error_message: String },
#[error("unknown denomination: {error_message}")]
UnknownDenomination { error_message: String },
#[error("possibly confusing denomination: {error_message}")]
PossiblyConfusingDenomination { error_message: String },
// Has to handle non-exhaustive
#[error("unknown parse amount error")]
OtherParseAmountErr,
}
#[derive(Debug, thiserror::Error)]
pub enum PersistenceError {
#[error("writing to persistence error: {error_message}")]
@ -434,6 +468,9 @@ pub enum WalletCreationError {
expected: Network,
got: Option<Network>,
},
#[error("loaded descriptor '{got}' does not match what was provided '{keychain:?}'")]
LoadedDescriptorDoesNotMatch { got: String, keychain: KeychainKind },
}
// ------------------------------------------------------------------------
@ -800,6 +837,28 @@ impl From<BdkExtractTxError> for ExtractTxError {
}
}
impl From<BdkParseAmountError> for ParseAmountError {
fn from(error: BdkParseAmountError) -> Self {
match error {
BdkParseAmountError::Negative => ParseAmountError::Negative,
BdkParseAmountError::TooBig => ParseAmountError::TooBig,
BdkParseAmountError::InvalidFormat => ParseAmountError::InvalidFormat,
BdkParseAmountError::TooPrecise => ParseAmountError::TooPrecise,
BdkParseAmountError::InputTooLarge => ParseAmountError::InputTooLarge,
BdkParseAmountError::InvalidCharacter(c) => ParseAmountError::InvalidCharacter {
error_message: c.to_string(),
},
BdkParseAmountError::UnknownDenomination(s) => {
ParseAmountError::UnknownDenomination { error_message: s }
}
BdkParseAmountError::PossiblyConfusingDenomination(s) => {
ParseAmountError::PossiblyConfusingDenomination { error_message: s }
}
_ => ParseAmountError::OtherParseAmountErr,
}
}
}
impl From<std::io::Error> for PersistenceError {
fn from(error: std::io::Error) -> Self {
PersistenceError::Write {
@ -902,6 +961,12 @@ impl From<NewOrLoadError> for WalletCreationError {
NewOrLoadError::LoadedNetworkDoesNotMatch { expected, got } => {
WalletCreationError::LoadedNetworkDoesNotMatch { expected, got }
}
NewOrLoadError::LoadedDescriptorDoesNotMatch { got, keychain } => {
WalletCreationError::LoadedDescriptorDoesNotMatch {
got: format!("{:?}", got),
keychain,
}
}
}
}
}
@ -914,13 +979,14 @@ impl From<NewOrLoadError> for WalletCreationError {
mod test {
use crate::error::{
AddressError, Bip32Error, Bip39Error, CannotConnectError, CreateTxError, DescriptorError,
DescriptorKeyError, EsploraError, ExtractTxError, FeeRateError, PersistenceError,
PsbtParseError, TransactionError, TxidParseError, WalletCreationError,
DescriptorKeyError, EsploraError, ExtractTxError, FeeRateError, ParseAmountError,
PersistenceError, PsbtParseError, TransactionError, TxidParseError, WalletCreationError,
};
use crate::CalculateFeeError;
use crate::OutPoint;
use crate::SignerError;
use bdk::bitcoin::Network;
use bdk::KeychainKind;
#[test]
fn test_error_address() {
@ -1418,6 +1484,43 @@ mod test {
}
}
#[test]
fn test_error_parse_amount() {
let cases = vec![
(ParseAmountError::Negative, "amount is negative"),
(ParseAmountError::TooBig, "amount is too large"),
(ParseAmountError::TooPrecise, "amount is too precise"),
(ParseAmountError::InvalidFormat, "invalid amount format"),
(ParseAmountError::InputTooLarge, "input is too large"),
(
ParseAmountError::InvalidCharacter {
error_message: "invalid char".to_string(),
},
"invalid character: invalid char",
),
(
ParseAmountError::UnknownDenomination {
error_message: "unknown denom".to_string(),
},
"unknown denomination: unknown denom",
),
(
ParseAmountError::PossiblyConfusingDenomination {
error_message: "confusing denom".to_string(),
},
"possibly confusing denomination: confusing denom",
),
(
ParseAmountError::OtherParseAmountErr,
"unknown parse amount error",
),
];
for (error, expected_message) in cases {
assert_eq!(error.to_string(), expected_message);
}
}
#[test]
fn test_persistence_error() {
let cases = vec![
@ -1605,6 +1708,13 @@ mod test {
},
"loaded network type is not bitcoin, got Some(Testnet)".to_string(),
),
(
WalletCreationError::LoadedDescriptorDoesNotMatch {
got: "def".to_string(),
keychain: KeychainKind::External,
},
"loaded descriptor 'def' does not match what was provided 'External'".to_string(),
),
];
for (error, expected) in errors {

View File

@ -7,6 +7,7 @@ mod types;
mod wallet;
use crate::bitcoin::Address;
use crate::bitcoin::Amount;
use crate::bitcoin::FeeRate;
use crate::bitcoin::OutPoint;
use crate::bitcoin::Psbt;
@ -25,6 +26,7 @@ use crate::error::DescriptorKeyError;
use crate::error::EsploraError;
use crate::error::ExtractTxError;
use crate::error::FeeRateError;
use crate::error::ParseAmountError;
use crate::error::PersistenceError;
use crate::error::PsbtParseError;
use crate::error::SignerError;

View File

@ -11,6 +11,8 @@ use bdk::LocalOutput as BdkLocalOutput;
use std::sync::{Arc, Mutex};
use crate::bitcoin::Amount;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChainPosition {
Confirmed { height: u32, timestamp: u64 },
@ -45,7 +47,7 @@ impl From<BdkCanonicalTx<'_, Arc<bdk::bitcoin::Transaction>, ConfirmationTimeHei
pub struct ScriptAmount {
pub script: Arc<Script>,
pub amount: u64,
pub amount: Arc<Amount>,
}
pub struct AddressInfo {
@ -65,23 +67,23 @@ impl From<BdkAddressInfo> for AddressInfo {
}
pub struct Balance {
pub immature: u64,
pub trusted_pending: u64,
pub untrusted_pending: u64,
pub confirmed: u64,
pub trusted_spendable: u64,
pub total: u64,
pub immature: Arc<Amount>,
pub trusted_pending: Arc<Amount>,
pub untrusted_pending: Arc<Amount>,
pub confirmed: Arc<Amount>,
pub trusted_spendable: Arc<Amount>,
pub total: Arc<Amount>,
}
impl From<BdkBalance> for Balance {
fn from(bdk_balance: BdkBalance) -> Self {
Balance {
immature: bdk_balance.immature,
trusted_pending: bdk_balance.trusted_pending,
untrusted_pending: bdk_balance.untrusted_pending,
confirmed: bdk_balance.confirmed,
trusted_spendable: bdk_balance.trusted_spendable(),
total: bdk_balance.total(),
immature: Arc::new(bdk_balance.immature.into()),
trusted_pending: Arc::new(bdk_balance.trusted_pending.into()),
untrusted_pending: Arc::new(bdk_balance.untrusted_pending.into()),
confirmed: Arc::new(bdk_balance.confirmed.into()),
trusted_spendable: Arc::new(bdk_balance.trusted_spendable().into()),
total: Arc::new(bdk_balance.total().into()),
}
}
}

View File

@ -1,3 +1,4 @@
use crate::bitcoin::Amount;
use crate::bitcoin::{FeeRate, OutPoint, Psbt, Script, Transaction};
use crate::descriptor::Descriptor;
use crate::error::{
@ -8,6 +9,7 @@ use crate::types::{
AddressInfo, Balance, CanonicalTx, FullScanRequest, LocalOutput, ScriptAmount, SyncRequest,
};
use bdk::bitcoin::amount::Amount as BdkAmount;
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::Network;
use bdk::bitcoin::Psbt as BdkPsbt;
@ -82,7 +84,7 @@ impl Wallet {
}
pub fn get_balance(&self) -> Balance {
let bdk_balance: bdk::wallet::Balance = self.get_wallet().get_balance();
let bdk_balance = self.get_wallet().get_balance();
Balance::from(bdk_balance)
}
@ -102,8 +104,11 @@ impl Wallet {
}
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues {
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.into());
SentAndReceivedValues { sent, received }
let (sent, received) = self.get_wallet().sent_and_received(&tx.into());
SentAndReceivedValues {
sent: Arc::new(sent.into()),
received: Arc::new(received.into()),
}
}
pub fn transactions(&self) -> Vec<CanonicalTx> {
@ -152,15 +157,15 @@ impl Wallet {
}
pub struct SentAndReceivedValues {
pub sent: u64,
pub received: u64,
pub sent: Arc<Amount>,
pub received: Arc<Amount>,
}
pub struct Update(pub(crate) BdkUpdate);
#[derive(Clone, Debug)]
pub struct TxBuilder {
pub(crate) recipients: Vec<(BdkScriptBuf, u64)>,
pub(crate) recipients: Vec<(BdkScriptBuf, BdkAmount)>,
pub(crate) utxos: Vec<OutPoint>,
pub(crate) unspendable: HashSet<OutPoint>,
pub(crate) change_policy: ChangeSpendPolicy,
@ -190,9 +195,9 @@ impl TxBuilder {
}
}
pub(crate) fn add_recipient(&self, script: &Script, amount: u64) -> Arc<Self> {
let mut recipients: Vec<(BdkScriptBuf, u64)> = self.recipients.clone();
recipients.append(&mut vec![(script.0.clone(), amount)]);
pub(crate) fn add_recipient(&self, script: &Script, amount: Arc<Amount>) -> Arc<Self> {
let mut recipients: Vec<(BdkScriptBuf, BdkAmount)> = self.recipients.clone();
recipients.append(&mut vec![(script.0.clone(), amount.0)]);
Arc::new(TxBuilder {
recipients,
@ -203,7 +208,7 @@ impl TxBuilder {
pub(crate) fn set_recipients(&self, recipients: Vec<ScriptAmount>) -> Arc<Self> {
let recipients = recipients
.iter()
.map(|script_amount| (script_amount.script.0.clone(), script_amount.amount))
.map(|script_amount| (script_amount.script.0.clone(), script_amount.amount.0)) //;
.collect();
Arc::new(TxBuilder {
recipients,

View File

@ -31,15 +31,15 @@ class LiveTxBuilderTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}
val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET)
val psbt: Psbt = TxBuilder()
.addRecipient(recipient.scriptPubkey(), 4200uL)
.addRecipient(recipient.scriptPubkey(), Amount.fromSat(4200uL))
.feeRate(FeeRate.fromSatPerVb(2uL))
.finish(wallet)
@ -58,17 +58,17 @@ class LiveTxBuilderTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}
val recipient1: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET)
val recipient2: Address = Address("tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", Network.SIGNET)
val allRecipients: List<ScriptAmount> = listOf(
ScriptAmount(recipient1.scriptPubkey(), 4200uL),
ScriptAmount(recipient2.scriptPubkey(), 4200uL),
ScriptAmount(recipient1.scriptPubkey(), Amount.fromSat(4200uL)),
ScriptAmount(recipient2.scriptPubkey(), Amount.fromSat(4200uL)),
)
val psbt: Psbt = TxBuilder()

View File

@ -31,9 +31,9 @@ class LiveWalletTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}
@ -56,16 +56,16 @@ class LiveWalletTest {
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
wallet.applyUpdate(update)
wallet.commit()
println("Balance: ${wallet.getBalance().total}")
println("Balance: ${wallet.getBalance().total.toSat()}")
assert(wallet.getBalance().total > 0uL) {
assert(wallet.getBalance().total.toSat() > 0uL) {
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address.asString()} and try again."
}
val recipient: Address = Address("tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", Network.SIGNET)
val psbt: Psbt = TxBuilder()
.addRecipient(recipient.scriptPubkey(), 4200uL)
.addRecipient(recipient.scriptPubkey(), Amount.fromSat(4200uL))
.feeRate(FeeRate.fromSatPerVb(2uL))
.finish(wallet)

View File

@ -70,7 +70,7 @@ class OfflineWalletTest {
assertEquals(
expected = 0uL,
actual = wallet.getBalance().total
actual = wallet.getBalance().total.toSat()
)
}
}

View File

@ -33,7 +33,7 @@ class LiveTxBuilderTest(unittest.TestCase):
wallet.commit()
self.assertGreater(
wallet.get_balance().total,
wallet.get_balance().total.to_sat(),
0,
f"Wallet balance must be greater than 0! Please send funds to {wallet.reveal_next_address(bdk.KeychainKind.EXTERNAL).address.as_string()} and try again."
)
@ -73,7 +73,7 @@ class LiveTxBuilderTest(unittest.TestCase):
wallet.commit()
self.assertGreater(
wallet.get_balance().total,
wallet.get_balance().total.to_sat(),
0,
f"Wallet balance must be greater than 0! Please send funds to {wallet.reveal_next_address(bdk.KeychainKind.EXTERNAL).address.as_string()} and try again."
)

View File

@ -33,7 +33,7 @@ class LiveWalletTest(unittest.TestCase):
wallet.commit()
self.assertGreater(
wallet.get_balance().total,
wallet.get_balance().total.to_sat(),
0,
f"Wallet balance must be greater than 0! Please send funds to {wallet.reveal_next_address(bdk.KeychainKind.EXTERNAL).address.as_string()} and try again."
)
@ -69,7 +69,7 @@ class LiveWalletTest(unittest.TestCase):
wallet.commit()
self.assertGreater(
wallet.get_balance().total,
wallet.get_balance().total.to_sat(),
0,
f"Wallet balance must be greater than 0! Please send funds to {wallet.reveal_next_address(bdk.KeychainKind.EXTERNAL).address.as_string()} and try again."
)

View File

@ -40,7 +40,7 @@ class OfflineWalletTest(unittest.TestCase):
bdk.Network.TESTNET
)
self.assertEqual(wallet.get_balance().total, 0)
self.assertEqual(wallet.get_balance().total.to_sat(), 0)
if __name__ == '__main__':
unittest.main()

View File

@ -49,14 +49,14 @@ final class LiveTxBuilderTests: XCTestCase {
let address = try wallet.revealNextAddress(keychain: KeychainKind.external).address.asString()
XCTAssertGreaterThan(
wallet.getBalance().total,
wallet.getBalance().total.toSat(),
UInt64(0),
"Wallet must have positive balance, please send funds to \(address)"
)
let recipient: Address = try Address(address: "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", network: .signet)
let psbt: Psbt = try TxBuilder()
.addRecipient(script: recipient.scriptPubkey(), amount: 4200)
.addRecipient(script: recipient.scriptPubkey(), amount: Amount.fromSat(fromSat: 4200))
.feeRate(feeRate: FeeRate.fromSatPerVb(satPerVb: 2))
.finish(wallet: wallet)
@ -91,7 +91,7 @@ final class LiveTxBuilderTests: XCTestCase {
let address = try wallet.revealNextAddress(keychain: KeychainKind.external).address.asString()
XCTAssertGreaterThan(
wallet.getBalance().total,
wallet.getBalance().total.toSat(),
UInt64(0),
"Wallet must have positive balance, please send funds to \(address)"
)
@ -99,8 +99,8 @@ final class LiveTxBuilderTests: XCTestCase {
let recipient1: Address = try Address(address: "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", network: .signet)
let recipient2: Address = try Address(address: "tb1qw2c3lxufxqe2x9s4rdzh65tpf4d7fssjgh8nv6", network: .signet)
let allRecipients: [ScriptAmount] = [
ScriptAmount(script: recipient1.scriptPubkey(), amount: 4200),
ScriptAmount(script: recipient2.scriptPubkey(), amount: 4200)
ScriptAmount(script: recipient1.scriptPubkey(), amount: Amount.fromSat(fromSat: 4200)),
ScriptAmount(script: recipient2.scriptPubkey(), amount: Amount.fromSat(fromSat: 4200))
]
let psbt: Psbt = try TxBuilder()

View File

@ -49,7 +49,7 @@ final class LiveWalletTests: XCTestCase {
let address = try wallet.revealNextAddress(keychain: KeychainKind.external).address.asString()
XCTAssertGreaterThan(
wallet.getBalance().total,
wallet.getBalance().total.toSat(),
UInt64(0),
"Wallet must have positive balance, please send funds to \(address)"
)
@ -87,18 +87,17 @@ final class LiveWalletTests: XCTestCase {
let address = try wallet.revealNextAddress(keychain: KeychainKind.external).address.asString()
XCTAssertGreaterThan(
wallet.getBalance().total,
wallet.getBalance().total.toSat(),
UInt64(0),
"Wallet must have positive balance, please send funds to \(address)"
)
print("Balance: \(wallet.getBalance().total)")
let recipient: Address = try Address(address: "tb1qrnfslnrve9uncz9pzpvf83k3ukz22ljgees989", network: .signet)
let psbt: Psbt = try
TxBuilder()
.addRecipient(script: recipient.scriptPubkey(), amount: 4200)
.addRecipient(script: recipient.scriptPubkey(), amount: Amount.fromSat(fromSat: 4200))
.feeRate(feeRate: FeeRate.fromSatPerVb(satPerVb: 2))
.finish(wallet: wallet)

View File

@ -60,6 +60,6 @@ final class OfflineWalletTests: XCTestCase {
network: .testnet
)
XCTAssertEqual(wallet.getBalance().total, 0)
XCTAssertEqual(wallet.getBalance().total.toSat(), 0)
}
}