diff --git a/core/src/main/java/org/bitcoinj/core/InsufficientMoneyException.java b/core/src/main/java/org/bitcoinj/core/InsufficientMoneyException.java index dbb8ac2df..627536205 100644 --- a/core/src/main/java/org/bitcoinj/core/InsufficientMoneyException.java +++ b/core/src/main/java/org/bitcoinj/core/InsufficientMoneyException.java @@ -41,4 +41,19 @@ public class InsufficientMoneyException extends Exception { super(message); this.missing = Objects.requireNonNull(missing); } + + public InsufficientMoneyException(Coin missing, Coin available, Coin outputs, Coin fee) { + this(missing, format(missing, available, outputs, fee)); + } + + /** + * @param missing Amount missing + * @param available Amount available (e.g. found by CoinSelector) + * @param outputs total amount of output requested + * @param fee calculated fee required for transaction + * @return An exception message + */ + static String format(Coin missing, Coin available, Coin outputs, Coin fee) { + return String.format("Insufficient money, missing %s (available: %s, total outputs: %s, fee: %s)", missing.toFriendlyString(), available.toFriendlyString(), outputs.toFriendlyString(), fee.toFriendlyString()); + } } diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index f6ffd6750..5c56bc2d2 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -5483,7 +5483,7 @@ public class Wallet extends BaseTaggableObject // Can we afford this? if (selection.totalValue().compareTo(valueNeeded) < 0) { Coin valueMissing = valueNeeded.subtract(selection.totalValue()); - throw new InsufficientMoneyException(valueMissing); + throw new InsufficientMoneyException(valueMissing, selection.totalValue(), value, fee); } Coin change = selection.totalValue().subtract(valueNeeded); if (change.isGreaterThan(Coin.ZERO)) {