Skip to content

Commit

Permalink
Merge pull request #44 from TheWaWaR/fix-fee-calc
Browse files Browse the repository at this point in the history
fix: transaction fee round
  • Loading branch information
TheWaWaR authored Nov 20, 2022
2 parents 850c90d + 8562704 commit 64e0acc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ckb-sdk"
version = "2.3.0"
version = "2.3.1"
authors = ["Linfeng Qian <[email protected]>", "Nervos Core Dev <[email protected]>"]
edition = "2018"
license = "MIT"
Expand Down
8 changes: 6 additions & 2 deletions src/tx_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,12 @@ pub fn balance_tx_capacity(
// * second 4 bytes if for output data offset
// * third 4 bytes is for output offset
let output_header_extra = 4 + 4 + 4;
// NOTE: extra_min_fee +1 is for `FeeRate::fee` round
let extra_min_fee = balancer
.fee_rate
.fee(base_change_output.as_slice().len() + output_header_extra)
.as_u64();
.as_u64()
+ 1;
// The extra capacity (delta - extra_min_fee) is enough to hold the change cell.
if delta >= base_change_occupied_capacity + extra_min_fee {
// next loop round must return new_tx;
Expand Down Expand Up @@ -506,7 +508,9 @@ pub fn balance_tx_capacity(
}
}
// fee is positive and `fee < min_fee`
Ok(_fee) => {}
Ok(fee) => {
need_more_capacity = min_fee - fee;
}
Err(TransactionFeeError::CapacityOverflow(delta)) => {
need_more_capacity = delta + min_fee;
}
Expand Down

0 comments on commit 64e0acc

Please sign in to comment.