Skip to content

Commit

Permalink
fix: transaction fee calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jul 26, 2024
1 parent 0d7e2a6 commit 4660214
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/utils/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ pub fn estimate_transaction_fees(
current_fee_rate.fee_vb(vbytes as u64).unwrap()
}

pub fn calculate_transaction_fees(transaction: &Transaction, current_fee_rate: FeeRate) -> Amount {
let vbytes = transaction.vsize();
current_fee_rate.fee_vb(vbytes as u64).unwrap()
}

fn estimate_vbytes(
inputs: usize,
script_type: ScriptType,
Expand Down
13 changes: 3 additions & 10 deletions src/wallet/builder/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use bitcoin::transaction::Version;
use bitcoin::{Address, Amount, FeeRate, ScriptBuf, Transaction, TxIn, TxOut};
use ordinals::{Edict, Etching, RuneId, Runestone as OrdRunestone};

use crate::fees::estimate_transaction_fees;
use crate::fees::calculate_transaction_fees;
use crate::wallet::builder::TxInputInfo;
use crate::wallet::ScriptType;
use crate::{OrdError, OrdTransactionBuilder};

/// Postage amount for rune transaction.
Expand Down Expand Up @@ -129,13 +128,7 @@ impl OrdTransactionBuilder {
output: outputs,
};

let fee_amount = estimate_transaction_fees(
ScriptType::P2TR,
unsigned_tx.input.len(),
args.fee_rate,
&None,
unsigned_tx.output.clone(),
);
let fee_amount = calculate_transaction_fees(&unsigned_tx, args.fee_rate);
let change_amount = args
.input_amount()
.checked_sub(fee_amount + RUNE_POSTAGE * 2)
Expand All @@ -161,7 +154,7 @@ mod tests {
use bitcoin::{Network, OutPoint, PrivateKey, PublicKey, Txid};

use super::*;
use crate::wallet::LocalSigner;
use crate::wallet::{LocalSigner, ScriptType};
use crate::Wallet;

#[tokio::test]
Expand Down

0 comments on commit 4660214

Please sign in to comment.