mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
Wallet: add more diagnostic info to InsufficientMoneyException
Add a new constructor that provides more information about available funds, total outputs, and fee in addition to amount missing. Use it in `Wallet.calculatFee` to provide more information when the exception occurs.
This commit is contained in:
parent
2f9ce85e07
commit
370c5d382c
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user