Skip to content

Conversation

@maciejka
Copy link
Collaborator

No description provided.


let xonly_pk = XOnlyPublicKey::from(*pk_signer);
let funding_script = get_funding_script(&x_only_pk);
fill_dummy_taproot_witness(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my experience, we used to estimate the gas fee based on the tx base size and witness data, since we know all them in advance.

Given that:

Est fee = fee rate * (vsize + 10)

signature: 64-byte

vsize = vweight/4
vweight = tx_base_size * 3 + tx_total_size
tx_total_size ~= tx_base_size + signature + redeem_script + control_block
control_block_size (byte) = 1 + 32 + 32 × depth

   let mut tx = build_spending_tx(
        funding_tx.txid(),
        0,
        taproot_addr,
        funding_tx.output[0].value,
    );
    // base_size is tx size with witness stripped.   assume there are 3 signature. 
    let vsize = (tx.base_size() as u64 * 4 + (redeem_script.to_bytes().len() as u64 + 64 * 3 + 33))/4 + 10;
    println!("spending tx size: {}", vsize);
    tx.output[0].value = tx.output[0].value - fee_rate * vsize;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fee rate:

let estimate_smart_fee_result = rpc_client.estimate_smart_fee(6, None).unwrap();
    let fee_rate = if let Some(fee_rate) = estimate_smart_fee_result.fee_rate {
        fee_rate
    } else {
        // If you're on regtest, this may not work well (always returns null), so fallback to a constant (e.g., 5–10 sat/vB).
        Amount::from_sat(5)
    };
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants