Transaction: Simplify error checking in verify().

This commit is contained in:
Matthew Leon 2019-04-17 19:18:25 -04:00 committed by Andreas Schildbach
parent 48cfd8c816
commit 7f72faed3e
2 changed files with 13 additions and 17 deletions

View file

@ -1622,25 +1622,25 @@ public class Transaction extends ChildMessage {
if (this.getMessageSize() > Block.MAX_BLOCK_SIZE)
throw new VerificationException.LargerThanMaxBlockSize();
Coin valueOut = Coin.ZERO;
HashSet<TransactionOutPoint> outpoints = new HashSet<>();
for (TransactionInput input : inputs) {
if (outpoints.contains(input.getOutpoint()))
throw new VerificationException.DuplicatedOutPoint();
outpoints.add(input.getOutpoint());
}
try {
for (TransactionOutput output : outputs) {
if (output.getValue().signum() < 0) // getValue() can throw IllegalStateException
throw new VerificationException.NegativeValueOutput();
valueOut = valueOut.add(output.getValue());
if (params.hasMaxMoney() && valueOut.compareTo(params.getMaxMoney()) > 0)
throw new IllegalArgumentException();
Coin valueOut = Coin.ZERO;
for (TransactionOutput output : outputs) {
Coin value = output.getValue();
if (value.signum() < 0)
throw new VerificationException.NegativeValueOutput();
try {
valueOut = valueOut.add(value);
} catch (ArithmeticException e) {
throw new VerificationException.ExcessiveValue();
}
} catch (IllegalStateException e) {
throw new VerificationException.ExcessiveValue();
} catch (IllegalArgumentException e) {
throw new VerificationException.ExcessiveValue();
if (params.hasMaxMoney() && valueOut.compareTo(params.getMaxMoney()) > 0)
throw new VerificationException.ExcessiveValue();
}
if (isCoinBase()) {

View file

@ -156,11 +156,7 @@ public class TransactionOutput extends ChildMessage {
* receives.
*/
public Coin getValue() {
try {
return Coin.valueOf(value);
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e.getMessage(), e);
}
return Coin.valueOf(value);
}
/**