From 3ee01055edd15c843e663272593fccaf129595d4 Mon Sep 17 00:00:00 2001 From: Quentin Le Sceller Date: Thu, 2 Aug 2018 12:05:38 -0400 Subject: [PATCH] Fixes #1299 - Fails to send transaction when not enough funds for fee (#1311) --- wallet/src/libwallet/internal/selection.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index 701622688..4633f0ab4 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -258,8 +258,16 @@ where })?; } - // Check if we need to use a change address - if total > amount_with_fee { + // The amount with fee is more than the total values of our max outputs + if total < amount_with_fee && coins.len() == max_outputs { + return Err(ErrorKind::NotEnoughFunds { + available: total, + needed: amount_with_fee as u64, + })?; + } + + // We need to add a change address or amount with fee is more than total + if total != amount_with_fee { fee = tx_fee(coins.len(), 2, None); amount_with_fee = amount + fee;