Skip to content

Commit

Permalink
fix: bump fee
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Dec 27, 2023
1 parent 6f065f0 commit 4e932a9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/web/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const drainWallet = async (
export const bumpFee = async (
txid: string,
feeRate: number,
broadcast: boolean,
descriptor: string,
changeDescriptor: string,
broadcast: boolean
changeDescriptor?: string,
): Promise<TransactionData> =>
JSON.parse(
await BMC.bump_fee(txid, feeRate, descriptor, changeDescriptor, broadcast)
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,12 @@ pub async fn bump_fee(
txid: String,
fee_rate: f32,
descriptor: &SecretString,
change_descriptor: &SecretString,
change_descriptor: Option<&SecretString>,
broadcast: bool,
) -> Result<TransactionData, BitcoinError> {
let txid = Txid::from_str(&txid)?;

let wallet = get_wallet(descriptor, Some(change_descriptor)).await?;
let wallet = get_wallet(descriptor, change_descriptor).await?;

if broadcast {
sync_wallet(&wallet).await?;
Expand Down
5 changes: 3 additions & 2 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,18 @@ pub mod bitcoin {
txid: String,
fee_rate: f32,
descriptor: String,
change_descriptor: String,
change_descriptor: Option<String>,
broadcast: bool,
) -> Promise {
set_panic_hook();

future_to_promise(async move {
let change_descriptor = change_descriptor.map(SecretString);
match crate::bitcoin::bump_fee(
txid,
fee_rate,
&SecretString(descriptor),
&SecretString(change_descriptor),
change_descriptor.as_ref(),
broadcast,
)
.await
Expand Down
18 changes: 5 additions & 13 deletions tests/rgb/integration/rbf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![cfg(not(target_arch = "wasm32"))]
use std::str::FromStr;

use anyhow::Result;
use bdk::{
database::MemoryDatabase,
Expand All @@ -9,12 +7,12 @@ use bdk::{
SignOptions, SyncOptions,
};
use bitcoin::{secp256k1::Secp256k1, Network, Txid};
use bitcoin_hashes::hex::{Case, DisplayHex};
use bitmask_core::{
bitcoin::{bump_fee, get_blockchain, new_mnemonic, sign_and_publish_psbt_file},
rgb::{get_contract, structs::ContractAmount},
structs::{PsbtFeeRequest, PsbtResponse, SecretString, SignPsbtRequest},
};
use std::str::FromStr;

use crate::rgb::integration::utils::{
create_new_psbt_v2, issuer_issue_contract_v2, send_some_coins, UtxoFilter,
Expand Down Expand Up @@ -165,19 +163,15 @@ pub async fn create_bdk_rbf_transaction() -> Result<()> {
let (mut psbt, _) = builder.finish()?;

let _ = user_wallet_data.sign(&mut psbt, SignOptions::default())?;
// println!("{:#?}", signed);

let tx = psbt.extract_tx();

blockchain.broadcast(&tx).await?;

user_wallet_data
.sync(&blockchain, SyncOptions::default())
.await?;

let txs = user_wallet_data.list_transactions(false)?;
// println!("{:#?}", txs);

assert_eq!(2, txs.len());

let tx_1_utxos: Vec<String> = tx
Expand All @@ -188,10 +182,10 @@ pub async fn create_bdk_rbf_transaction() -> Result<()> {
.collect();

bump_fee(
tx.txid().to_hex_string(Case::Lower),
tx.txid().to_string(),
5.0,
&SecretString(user_keys.private.btc_descriptor_xprv.to_owned()),
&SecretString(user_keys.private.btc_change_descriptor_xprv.to_owned()),
None,
true,
)
.await?;
Expand All @@ -201,8 +195,6 @@ pub async fn create_bdk_rbf_transaction() -> Result<()> {
.await?;

let txs = user_wallet_data.list_transactions(false)?;
// println!("{:#?}", txs);

assert_eq!(2, txs.len());

let tx_2_utxos: Vec<String> = tx
Expand All @@ -211,8 +203,8 @@ pub async fn create_bdk_rbf_transaction() -> Result<()> {
.map(|u| u.previous_output.to_string())
.collect();

println!("tx 1 utxos: {:#?}", tx_1_utxos);
println!("tx 2 utxos: {:#?}", tx_2_utxos);
// println!("tx 1 utxos: {:#?}", tx_1_utxos);
// println!("tx 2 utxos: {:#?}", tx_2_utxos);
assert_eq!(tx_1_utxos, tx_2_utxos);

Ok(())
Expand Down

0 comments on commit 4e932a9

Please sign in to comment.