Skip to content

Commit

Permalink
Add addl tx data to RBF. Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoquick committed Dec 21, 2023
1 parent 4ed58a9 commit 1e3c00c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ pub async fn bump_fee(
descriptor: &SecretString,
change_descriptor: &SecretString,
broadcast: bool,
) -> Result<TransactionDetails, BitcoinError> {
) -> Result<TransactionData, BitcoinError> {
let txid = Txid::from_str(&txid)?;

let wallet = get_wallet(descriptor, Some(change_descriptor)).await?;
Expand All @@ -643,6 +643,12 @@ pub async fn bump_fee(
builder.finish()?
};

let vsize = details
.transaction
.as_ref()
.expect("transaction exists")
.vsize();

if broadcast {
let _finalized = wallet
.lock()
Expand All @@ -654,17 +660,28 @@ pub async fn bump_fee(

let sent = tx.output.iter().fold(0, |sum, output| output.value + sum);

let txid = tx.txid();
let vsize = tx.vsize();

let details = TransactionDetails {
txid: tx.txid(),
txid,
transaction: Some(tx),
received: 0,
sent,
fee: details.fee,
confirmation_time: None,
};

Ok(details)
Ok(TransactionData {
details,
vsize,
fee_rate,
})
} else {
Ok(details)
Ok(TransactionData {
details,
vsize,
fee_rate,
})
}
}
4 changes: 2 additions & 2 deletions tests/web_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(target_arch = "wasm32")]
use bitmask_core::{
debug, info,
structs::{DecryptedWalletData, SecretString, TransactionDetails, WalletData},
structs::{DecryptedWalletData, SecretString, TransactionData, WalletData},
web::{
bitcoin::{
decrypt_wallet, encrypt_wallet, get_wallet_data, hash_password, new_wallet, send_sats,
Expand Down Expand Up @@ -186,7 +186,7 @@ async fn import_test_wallet() {
.await;

info!("Parse tx_details");
let tx_data: TransactionDetails = json_parse(&tx_details);
let tx_data: TransactionData = json_parse(&tx_details);

assert!(
tx_data.confirmation_time.is_none(),

Check failure on line 192 in tests/web_wallet.rs

View workflow job for this annotation

GitHub Actions / lint-wasm

error[E0609]: no field `confirmation_time` on type `bitmask_core::structs::TransactionData` --> tests/web_wallet.rs:192:17 | 192 | tx_data.confirmation_time.is_none(), | ^^^^^^^^^^^^^^^^^ unknown field | = note: available fields are: `details`, `vsize`, `fee_rate` help: one of the expressions' fields has a field of the same name | 192 | tx_data.details.confirmation_time.is_none(), | ++++++++
Expand Down

0 comments on commit 1e3c00c

Please sign in to comment.