mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-15 04:11:51 +01:00
TransactionOutput: make field scriptBytes
immutable
This commit is contained in:
parent
acd0faaec7
commit
b237a34d8b
2 changed files with 8 additions and 6 deletions
|
@ -1387,8 +1387,9 @@ public class Transaction extends BaseMessage {
|
||||||
BigInteger.valueOf(output.getValue().getValue()),
|
BigInteger.valueOf(output.getValue().getValue()),
|
||||||
bosHashOutputs
|
bosHashOutputs
|
||||||
);
|
);
|
||||||
bosHashOutputs.write(VarInt.of(output.getScriptBytes().length).serialize());
|
byte[] scriptBytes = output.getScriptBytes();
|
||||||
bosHashOutputs.write(output.getScriptBytes());
|
bosHashOutputs.write(VarInt.of(scriptBytes.length).serialize());
|
||||||
|
bosHashOutputs.write(scriptBytes);
|
||||||
}
|
}
|
||||||
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
||||||
} else if (basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) {
|
} else if (basicSigHashType == SigHash.SINGLE.value && inputIndex < outputs.size()) {
|
||||||
|
@ -1397,8 +1398,9 @@ public class Transaction extends BaseMessage {
|
||||||
BigInteger.valueOf(this.outputs.get(inputIndex).getValue().getValue()),
|
BigInteger.valueOf(this.outputs.get(inputIndex).getValue().getValue()),
|
||||||
bosHashOutputs
|
bosHashOutputs
|
||||||
);
|
);
|
||||||
bosHashOutputs.write(VarInt.of(this.outputs.get(inputIndex).getScriptBytes().length).serialize());
|
byte[] scriptBytes = this.outputs.get(inputIndex).getScriptBytes();
|
||||||
bosHashOutputs.write(this.outputs.get(inputIndex).getScriptBytes());
|
bosHashOutputs.write(VarInt.of(scriptBytes.length).serialize());
|
||||||
|
bosHashOutputs.write(scriptBytes);
|
||||||
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
hashOutputs = Sha256Hash.hashTwice(bosHashOutputs.toByteArray());
|
||||||
}
|
}
|
||||||
writeInt32LE(version, bos);
|
writeInt32LE(version, bos);
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class TransactionOutput {
|
||||||
|
|
||||||
// A transaction output has a script used for authenticating that the redeemer is allowed to spend
|
// A transaction output has a script used for authenticating that the redeemer is allowed to spend
|
||||||
// this output.
|
// this output.
|
||||||
private byte[] scriptBytes;
|
private final byte[] scriptBytes;
|
||||||
|
|
||||||
// The script bytes are parsed and turned into a Script on demand.
|
// The script bytes are parsed and turned into a Script on demand.
|
||||||
private Script scriptPubKey;
|
private Script scriptPubKey;
|
||||||
|
@ -308,7 +308,7 @@ public class TransactionOutput {
|
||||||
* @return the scriptBytes
|
* @return the scriptBytes
|
||||||
*/
|
*/
|
||||||
public byte[] getScriptBytes() {
|
public byte[] getScriptBytes() {
|
||||||
return scriptBytes;
|
return Arrays.copyOf(scriptBytes, scriptBytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue