mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
TransactionOutput: tighter checks on values when constructing (don't allow negative values, etc).
This commit is contained in:
parent
b09c4cbe09
commit
9953bbe5cb
@ -1014,7 +1014,7 @@ public class Transaction extends ChildMessage implements Serializable {
|
|||||||
// that position are "nulled out". Unintuitively, the value in a "null" transaction is set to -1.
|
// that position are "nulled out". Unintuitively, the value in a "null" transaction is set to -1.
|
||||||
this.outputs = new ArrayList<TransactionOutput>(this.outputs.subList(0, inputIndex + 1));
|
this.outputs = new ArrayList<TransactionOutput>(this.outputs.subList(0, inputIndex + 1));
|
||||||
for (int i = 0; i < inputIndex; i++)
|
for (int i = 0; i < inputIndex; i++)
|
||||||
this.outputs.set(i, new TransactionOutput(params, this, BigInteger.valueOf(-1), new byte[] {}));
|
this.outputs.set(i, new TransactionOutput(params, this, NEGATIVE_ONE, new byte[] {}));
|
||||||
// The signature isn't broken by new versions of the transaction issued by other parties.
|
// The signature isn't broken by new versions of the transaction issued by other parties.
|
||||||
for (int i = 0; i < inputs.size(); i++)
|
for (int i = 0; i < inputs.size(); i++)
|
||||||
if (i != inputIndex)
|
if (i != inputIndex)
|
||||||
|
@ -28,6 +28,7 @@ import java.io.OutputStream;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
@ -107,6 +108,10 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
|||||||
|
|
||||||
public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, byte[] scriptBytes) {
|
public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, byte[] scriptBytes) {
|
||||||
super(params);
|
super(params);
|
||||||
|
// Negative values obviously make no sense, except for -1 which is used as a sentinel value when calculating
|
||||||
|
// SIGHASH_SINGLE signatures, so unfortunately we have to allow that here.
|
||||||
|
checkArgument(value.compareTo(BigInteger.ZERO) >= 0 || value.equals(Utils.NEGATIVE_ONE), "Negative values not allowed");
|
||||||
|
checkArgument(value.compareTo(NetworkParameters.MAX_MONEY) < 0, "Values larger than MAX_MONEY not allowed");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.scriptBytes = scriptBytes;
|
this.scriptBytes = scriptBytes;
|
||||||
parentTransaction = parent;
|
parentTransaction = parent;
|
||||||
|
@ -38,6 +38,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
* To enable debug logging from the library, run with -Dbitcoinj.logging=true on your command line.
|
* To enable debug logging from the library, run with -Dbitcoinj.logging=true on your command line.
|
||||||
*/
|
*/
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
public static final BigInteger NEGATIVE_ONE = BigInteger.valueOf(-1);
|
||||||
private static final MessageDigest digest;
|
private static final MessageDigest digest;
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user