return zero total when some input values are not available

This commit is contained in:
Craig Raw 2021-12-15 14:13:29 +02:00
parent 8ac3f47380
commit d59da36506

View file

@ -91,7 +91,11 @@ public class WalletTransaction {
}
public long getTotal() {
return getSelectedUtxos().keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum();
return inputAmountsValid() ? getSelectedUtxos().keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum() : 0;
}
private boolean inputAmountsValid() {
return getSelectedUtxos().keySet().stream().allMatch(ref -> ref.getValue() > 0);
}
public Map<Sha256Hash, BlockTransaction> getInputTransactions() {
@ -103,7 +107,7 @@ public class WalletTransaction {
* @return the fee percentage
*/
public double getFeePercentage() {
return getFee() == 0 ? 0 : (double)getFee() / (getTotal() - getFee());
return getFee() <= 0 || getTotal() <= 0 ? 0 : (double)getFee() / (getTotal() - getFee());
}
public boolean isCoinControlUsed() {