Dynamically calculate fees using electrum's estimate_fee.

Electrum has an estimate-fee feature which takes as input the block you want a tx to be included.
The result is a recommendation of BTC/vbyte.
Using this recommendation and the knowledge about the size of our transactions we compute an appropriate fee.
The size of the transactions were taken from real transactions as published on bitcoin testnet.
Note: in reality these sizes might fluctuate a bit but not for much.
This commit is contained in:
Philipp Hoenisch 2021-05-01 10:08:54 +10:00
parent 38540b4de5
commit ee90c228b4
No known key found for this signature in database
GPG key ID: E5F8E74C672BC666
11 changed files with 163 additions and 66 deletions

View file

@ -66,8 +66,12 @@ async fn next_state(
Ok(match state {
BobState::Started { btc_amount } => {
let bitcoin_refund_address = bitcoin_wallet.new_address().await?;
let tx_refund_fee = bitcoin_wallet.estimate_fee(bitcoin::ESTIMATED_WEIGHT_TX_REDEEM);
let tx_cancel_fee = bitcoin_wallet.estimate_fee(bitcoin::ESTIMATED_WEIGHT_TX_CANCEL);
let tx_refund_fee = bitcoin_wallet
.estimate_fee(bitcoin::ESTIMATED_WEIGHT_TX_REDEEM)
.await?;
let tx_cancel_fee = bitcoin_wallet
.estimate_fee(bitcoin::ESTIMATED_WEIGHT_TX_CANCEL)
.await?;
let state2 = request_price_and_setup(
swap_id,