DefaultCoinSelector: use checked add to sum up output values

This commit is contained in:
Andreas Schildbach 2022-07-19 10:28:10 +02:00
parent f6cb6c15d1
commit 26f343a607

View file

@ -17,6 +17,7 @@
package org.bitcoinj.wallet; package org.bitcoinj.wallet;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.math.LongMath;
import org.bitcoinj.base.BitcoinNetwork; import org.bitcoinj.base.BitcoinNetwork;
import org.bitcoinj.base.Coin; import org.bitcoinj.base.Coin;
import org.bitcoinj.core.Transaction; import org.bitcoinj.core.Transaction;
@ -57,7 +58,7 @@ public class DefaultCoinSelector implements CoinSelector {
// Only pick chain-included transactions, or transactions that are ours and pending. // Only pick chain-included transactions, or transactions that are ours and pending.
if (!shouldSelect(output.getParentTransaction())) continue; if (!shouldSelect(output.getParentTransaction())) continue;
selected.add(output); selected.add(output);
total += output.getValue().value; total = LongMath.checkedAdd(total, output.getValue().value);
} }
// Total may be lower than target here, if the given candidates were insufficient to create to requested // Total may be lower than target here, if the given candidates were insufficient to create to requested
// transaction. // transaction.