Skip to content

Commit 64e0acc

Browse files
authored
Merge pull request #44 from TheWaWaR/fix-fee-calc
fix: transaction fee round
2 parents 850c90d + 8562704 commit 64e0acc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ckb-sdk"
3-
version = "2.3.0"
3+
version = "2.3.1"
44
authors = ["Linfeng Qian <thewawar@gmail.com>", "Nervos Core Dev <dev@nervos.org>"]
55
edition = "2018"
66
license = "MIT"

src/tx_builder/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,12 @@ pub fn balance_tx_capacity(
455455
// * second 4 bytes if for output data offset
456456
// * third 4 bytes is for output offset
457457
let output_header_extra = 4 + 4 + 4;
458+
// NOTE: extra_min_fee +1 is for `FeeRate::fee` round
458459
let extra_min_fee = balancer
459460
.fee_rate
460461
.fee(base_change_output.as_slice().len() + output_header_extra)
461-
.as_u64();
462+
.as_u64()
463+
+ 1;
462464
// The extra capacity (delta - extra_min_fee) is enough to hold the change cell.
463465
if delta >= base_change_occupied_capacity + extra_min_fee {
464466
// next loop round must return new_tx;
@@ -506,7 +508,9 @@ pub fn balance_tx_capacity(
506508
}
507509
}
508510
// fee is positive and `fee < min_fee`
509-
Ok(_fee) => {}
511+
Ok(fee) => {
512+
need_more_capacity = min_fee - fee;
513+
}
510514
Err(TransactionFeeError::CapacityOverflow(delta)) => {
511515
need_more_capacity = delta + min_fee;
512516
}

0 commit comments

Comments
 (0)