From 63ee0954b7a14cb34aadc96e8ef51284964089a6 Mon Sep 17 00:00:00 2001 From: Boyu Yang Date: Sun, 8 Nov 2020 20:30:29 +0800 Subject: [PATCH] fix: attempt to subtract with overflow --- src/subcommands/wallet/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/subcommands/wallet/mod.rs b/src/subcommands/wallet/mod.rs index 381f166e..d3b68252 100644 --- a/src/subcommands/wallet/mod.rs +++ b/src/subcommands/wallet/mod.rs @@ -364,9 +364,12 @@ impl<'a> WalletSubCommand<'a> { let mut infos: Vec = 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) {