mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 11:45:51 +00:00
TransactionInput: Add public clearScriptBytes() method, as this seems to be a relevant use case.
It also saves some calls to the semi-private setScriptBytes().
This commit is contained in:
parent
17140d462f
commit
d092922e64
@ -950,7 +950,7 @@ public class Transaction extends ChildMessage {
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
inputScripts[i] = inputs.get(i).getScriptBytes();
|
||||
inputSequenceNumbers[i] = inputs.get(i).getSequenceNumber();
|
||||
inputs.get(i).setScriptBytes(TransactionInput.EMPTY_ARRAY);
|
||||
inputs.get(i).clearScriptBytes();
|
||||
}
|
||||
|
||||
// This step has no purpose beyond being synchronized with Bitcoin Core's bugs. OP_CODESEPARATOR
|
||||
|
@ -42,7 +42,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
public class TransactionInput extends ChildMessage {
|
||||
/** Magic sequence number that indicates there is no sequence number. */
|
||||
public static final long NO_SEQUENCE = 0xFFFFFFFFL;
|
||||
public static final byte[] EMPTY_ARRAY = new byte[0];
|
||||
private static final byte[] EMPTY_ARRAY = new byte[0];
|
||||
// Magic outpoint index that indicates the input is in fact unconnected.
|
||||
private static final long UNCONNECTED = 0xFFFFFFFFL;
|
||||
|
||||
@ -230,6 +230,11 @@ public class TransactionInput extends ChildMessage {
|
||||
return scriptBytes;
|
||||
}
|
||||
|
||||
/** Clear input scripts, e.g. in preparation for signing. */
|
||||
public void clearScriptBytes() {
|
||||
setScriptBytes(TransactionInput.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scriptBytes the scriptBytes to set
|
||||
*/
|
||||
|
@ -148,7 +148,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
|
||||
t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, new byte[] {}));
|
||||
TransactionInput input = t.addInput(spendableOutput);
|
||||
// Invalid script.
|
||||
input.setScriptBytes(new byte[]{});
|
||||
input.clearScriptBytes();
|
||||
rollingBlock.addTransaction(t);
|
||||
rollingBlock.solve();
|
||||
chain.setRunScripts(false);
|
||||
|
@ -164,7 +164,7 @@ public class BlockTest {
|
||||
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {(byte) ScriptOpCodes.OP_FALSE, (byte) ScriptOpCodes.OP_FALSE});
|
||||
assertEquals(block.length, origBlockLen + tx.length);
|
||||
assertEquals(tx.length, origTxLength + 1);
|
||||
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {});
|
||||
block.getTransactions().get(1).getInputs().get(0).clearScriptBytes();
|
||||
assertEquals(block.length, block.bitcoinSerialize().length);
|
||||
assertEquals(block.length, origBlockLen + tx.length);
|
||||
assertEquals(tx.length, origTxLength - 1);
|
||||
|
@ -472,7 +472,7 @@ public class FullBlockTestGenerator {
|
||||
//
|
||||
NewBlock b26 = createNextBlock(b15, chainHeadHeight + 7, out6, null);
|
||||
// 1 is too small, but we already generate every other block with 2, so that is tested
|
||||
b26.block.getTransactions().get(0).getInputs().get(0).setScriptBytes(new byte[] {0});
|
||||
b26.block.getTransactions().get(0).getInputs().get(0).clearScriptBytes();
|
||||
b26.block.setMerkleRoot(null);
|
||||
b26.solve();
|
||||
blocks.add(new BlockAndValidity(b26, false, true, b23.getHash(), chainHeadHeight + 7, "b26"));
|
||||
|
@ -3268,7 +3268,7 @@ public class WalletTest extends TestWithWallet {
|
||||
wallet.completeTx(req);
|
||||
// Delete the sigs
|
||||
for (TransactionInput input : req.tx.getInputs())
|
||||
input.setScriptBytes(new byte[]{});
|
||||
input.clearScriptBytes();
|
||||
Wallet watching = Wallet.fromWatchingKey(params, wallet.getWatchingKey().dropParent().dropPrivateBytes());
|
||||
watching.completeTx(Wallet.SendRequest.forTx(req.tx));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user