Skip to content

Commit

Permalink
Merge pull request #349 from yangby-cryptape/pr/fix-subtract-with-ove…
Browse files Browse the repository at this point in the history
…rflow

fix: attempt to subtract with overflow
  • Loading branch information
TheWaWaR authored Nov 11, 2020
2 parents f2bef1b + 63ee095 commit 2a770d9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/subcommands/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ impl<'a> WalletSubCommand<'a> {
let mut infos: Vec<LiveCellInfo> = Default::default();

fn enough_capacity(from_capacity: u64, to_capacity: u64, tx_fee: u64) -> bool {
let rest_capacity = from_capacity - to_capacity - tx_fee;
from_capacity >= to_capacity + tx_fee
&& (rest_capacity >= MIN_SECP_CELL_CAPACITY || tx_fee + rest_capacity < ONE_CKB)
if from_capacity < to_capacity + tx_fee {
false
} else {
let rest_capacity = from_capacity - to_capacity - tx_fee;
rest_capacity >= MIN_SECP_CELL_CAPACITY || tx_fee + rest_capacity < ONE_CKB
}
}
let mut terminator = |_, info: &LiveCellInfo| {
if enough_capacity(from_capacity, to_capacity, tx_fee) {
Expand Down

0 comments on commit 2a770d9

Please sign in to comment.