From 8aeb5d3b1cfc01c3220034ea8bd4ea5162e9601b Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Thu, 30 Mar 2023 22:49:54 +0200 Subject: [PATCH] TransactionInput: remove `params` from constructors --- .../main/java/org/bitcoinj/core/Block.java | 6 ++-- .../java/org/bitcoinj/core/Transaction.java | 8 ++--- .../org/bitcoinj/core/TransactionInput.java | 23 ++++++------ .../org/bitcoinj/testing/FakeTxBuilder.java | 2 +- .../main/java/org/bitcoinj/wallet/Wallet.java | 2 +- .../wallet/WalletProtobufSerializer.java | 2 +- .../bitcoinj/core/FullBlockTestGenerator.java | 35 +++++++++---------- .../org/bitcoinj/core/TransactionTest.java | 4 +-- .../payments/PaymentSessionTest.java | 6 ++-- .../java/org/bitcoinj/script/ScriptTest.java | 6 ++-- .../wallet/DefaultRiskAnalysisTest.java | 8 ++--- .../java/org/bitcoinj/wallet/WalletTest.java | 4 +-- .../test/java/org/bitcoinj/core/PeerTest.java | 10 +++--- 13 files changed, 56 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Block.java b/core/src/main/java/org/bitcoinj/core/Block.java index 29470f9e7..5d295d773 100644 --- a/core/src/main/java/org/bitcoinj/core/Block.java +++ b/core/src/main/java/org/bitcoinj/core/Block.java @@ -260,7 +260,7 @@ public class Block extends Message { private static Transaction createGenesisTransaction(NetworkParameters n, byte[] inputScriptBytes, Coin amount, byte[] scriptPubKeyBytes) { Transaction t = new Transaction(n); - t.addInput(new TransactionInput(n, t, inputScriptBytes)); + t.addInput(new TransactionInput(t, inputScriptBytes)); t.addOutput(new TransactionOutput(n, t, amount, scriptPubKeyBytes)); return t; } @@ -891,7 +891,7 @@ public class Block extends Message { // // Here we will do things a bit differently so a new address isn't needed every time. We'll put a simple // counter in the scriptSig so every transaction has a different hash. - coinbase.addInput(new TransactionInput(params, coinbase, + coinbase.addInput(new TransactionInput(coinbase, inputBuilder.build().getProgram())); coinbase.addOutput(new TransactionOutput(params, coinbase, value, ScriptBuilder.createP2PKOutputScript(ECKey.fromPublicOnly(pubKeyTo)).getProgram())); @@ -935,7 +935,7 @@ public class Block extends Message { if (prevOut == null) { prevOut = new TransactionOutPoint(0, nextTestOutPointHash()); } - input = new TransactionInput(params, t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES), prevOut); + input = new TransactionInput(t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES), prevOut); t.addInput(input); b.addTransaction(t); } diff --git a/core/src/main/java/org/bitcoinj/core/Transaction.java b/core/src/main/java/org/bitcoinj/core/Transaction.java index 45d3d8f54..2e15d7c19 100644 --- a/core/src/main/java/org/bitcoinj/core/Transaction.java +++ b/core/src/main/java/org/bitcoinj/core/Transaction.java @@ -693,7 +693,7 @@ public class Transaction extends Message { int numInputs = numInputsVarInt.intValue(); inputs = new ArrayList<>(Math.min((int) numInputs, Utils.MAX_INITIAL_ARRAY_LENGTH)); for (long i = 0; i < numInputs; i++) { - TransactionInput input = new TransactionInput(params, this, payload.slice()); + TransactionInput input = new TransactionInput(this, payload.slice()); inputs.add(input); // intentionally read again, due to the slice above Buffers.skipBytes(payload, TransactionOutPoint.MESSAGE_LENGTH); @@ -953,7 +953,7 @@ public class Transaction extends Message { * @return the newly created input. */ public TransactionInput addInput(TransactionOutput from) { - return addInput(new TransactionInput(params, this, from)); + return addInput(new TransactionInput(this, from)); } /** @@ -972,7 +972,7 @@ public class Transaction extends Message { * @return the newly created input. */ public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) { - return addInput(new TransactionInput(params, this, script.getProgram(), new TransactionOutPoint(outputIndex, spendTxHash))); + return addInput(new TransactionInput(this, script.getProgram(), new TransactionOutPoint(outputIndex, spendTxHash))); } /** @@ -998,7 +998,7 @@ public class Transaction extends Message { if (amount == null || amount.value <= 0) { log.warn("Illegal amount value. Amount is required for SegWit transactions."); } - TransactionInput input = new TransactionInput(params, this, new byte[] {}, prevOut, amount); + TransactionInput input = new TransactionInput(this, new byte[] {}, prevOut, amount); addInput(input); int inputIndex = inputs.size() - 1; if (ScriptPattern.isP2PK(scriptPubKey)) { diff --git a/core/src/main/java/org/bitcoinj/core/TransactionInput.java b/core/src/main/java/org/bitcoinj/core/TransactionInput.java index 8e164039a..0b37d89d6 100644 --- a/core/src/main/java/org/bitcoinj/core/TransactionInput.java +++ b/core/src/main/java/org/bitcoinj/core/TransactionInput.java @@ -93,18 +93,18 @@ public class TransactionInput extends Message { /** * Creates an input that connects to nothing - used only in creation of coinbase transactions. */ - public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] scriptBytes) { - this(params, parentTransaction, scriptBytes, new TransactionOutPoint(UNCONNECTED, (Transaction) null)); + public TransactionInput(@Nullable Transaction parentTransaction, byte[] scriptBytes) { + this(parentTransaction, scriptBytes, new TransactionOutPoint(UNCONNECTED, (Transaction) null)); } - public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] scriptBytes, + public TransactionInput(@Nullable Transaction parentTransaction, byte[] scriptBytes, TransactionOutPoint outpoint) { - this(params, parentTransaction, scriptBytes, outpoint, null); + this(parentTransaction, scriptBytes, outpoint, null); } - public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] scriptBytes, + public TransactionInput(@Nullable Transaction parentTransaction, byte[] scriptBytes, TransactionOutPoint outpoint, @Nullable Coin value) { - super(params); + super(); this.scriptBytes = scriptBytes; this.outpoint = outpoint; this.sequence = NO_SEQUENCE; @@ -115,8 +115,8 @@ public class TransactionInput extends Message { /** * Creates an UNSIGNED input that links to the given output */ - TransactionInput(NetworkParameters params, Transaction parentTransaction, TransactionOutput output) { - super(params); + TransactionInput(Transaction parentTransaction, TransactionOutput output) { + super(); long outputIndex = output.getIndex(); if(output.getParentTransaction() != null ) { outpoint = new TransactionOutPoint(outputIndex, output.getParentTransaction()); @@ -131,12 +131,11 @@ public class TransactionInput extends Message { /** * Deserializes an input message. This is usually part of a transaction message. - * @param params NetworkParameters object. * @param payload Bitcoin protocol formatted byte array containing message content. * @throws ProtocolException */ - public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, ByteBuffer payload) throws ProtocolException { - super(params, payload); + public TransactionInput(@Nullable Transaction parentTransaction, ByteBuffer payload) throws ProtocolException { + super(payload); setParent(parentTransaction); this.value = null; } @@ -500,7 +499,7 @@ public class TransactionInput extends Message { /** Returns a copy of the input detached from its containing transaction, if need be. */ public TransactionInput duplicateDetached() { - return new TransactionInput(params, null, ByteBuffer.wrap(bitcoinSerialize())); + return new TransactionInput(null, ByteBuffer.wrap(bitcoinSerialize())); } /** diff --git a/core/src/main/java/org/bitcoinj/testing/FakeTxBuilder.java b/core/src/main/java/org/bitcoinj/testing/FakeTxBuilder.java index f03466434..67f30f046 100644 --- a/core/src/main/java/org/bitcoinj/testing/FakeTxBuilder.java +++ b/core/src/main/java/org/bitcoinj/testing/FakeTxBuilder.java @@ -75,7 +75,7 @@ public class FakeTxBuilder { /** Create a fake coinbase transaction. */ public static Transaction createFakeCoinbaseTx(final NetworkParameters params) { TransactionOutPoint outpoint = new TransactionOutPoint(ByteUtils.MAX_UNSIGNED_INTEGER, Sha256Hash.ZERO_HASH); - TransactionInput input = new TransactionInput(params, null, new byte[0], outpoint); + TransactionInput input = new TransactionInput(null, new byte[0], outpoint); Transaction tx = new Transaction(params); tx.addInput(input); TransactionOutput outputToMe = new TransactionOutput(params, tx, Coin.FIFTY_COINS, diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index e9aa7c594..91bdbb5ec 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -5359,7 +5359,7 @@ public class Wallet extends BaseTaggableObject private void addSuppliedInputs(Transaction tx, List originalInputs) { for (TransactionInput input : originalInputs) - tx.addInput(new TransactionInput(params, tx, input.bitcoinSerialize())); + tx.addInput(new TransactionInput(tx, input.bitcoinSerialize())); } private int estimateVirtualBytesForSigning(CoinSelection selection) { diff --git a/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java b/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java index dd7430e6b..fb98708d0 100644 --- a/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java +++ b/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java @@ -650,7 +650,7 @@ public class WalletProtobufSerializer { byteStringToHash(inputProto.getTransactionOutPointHash()) ); Coin value = inputProto.hasValue() ? Coin.valueOf(inputProto.getValue()) : null; - TransactionInput input = new TransactionInput(params, tx, scriptBytes, outpoint, value); + TransactionInput input = new TransactionInput(tx, scriptBytes, outpoint, value); if (inputProto.hasSequence()) input.setSequenceNumber(0xffffffffL & inputProto.getSequence()); if (inputProto.hasWitness()) { diff --git a/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java b/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java index 3cb15c7e9..13d8a2de6 100644 --- a/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java +++ b/core/src/test/java/org/bitcoinj/core/FullBlockTestGenerator.java @@ -724,7 +724,7 @@ public class FullBlockTestGenerator { lastOutputValue = lastOutputValue.subtract(SATOSHI); tx.addOutput(new TransactionOutput(params, tx, SATOSHI, scriptPubKey.toByteArray())); tx.addOutput(new TransactionOutput(params, tx, lastOutputValue, new byte[]{OP_1})); - tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint)); + tx.addInput(new TransactionInput(tx, new byte[]{OP_1}, lastOutPoint)); lastOutPoint = new TransactionOutPoint(1, tx.getTxId()); if (b39.block.getMessageSize() + tx.getMessageSize() < Block.MAX_BLOCK_SIZE) { @@ -756,9 +756,9 @@ public class FullBlockTestGenerator { for (int i = 1; i <= numTxes; i++) { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, SATOSHI, new byte[] {OP_1})); - tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint)); + tx.addInput(new TransactionInput(tx, new byte[]{OP_1}, lastOutPoint)); - TransactionInput input = new TransactionInput(params, tx, new byte[]{}, + TransactionInput input = new TransactionInput(tx, new byte[]{}, new TransactionOutPoint(0, b39.block.getTransactions().get(i).getTxId())); tx.addInput(input); @@ -793,7 +793,7 @@ public class FullBlockTestGenerator { sigOps += numTxes * b39sigOpsPerOutput; Transaction tx = new Transaction(params); - tx.addInput(new TransactionInput(params, tx, new byte[]{OP_1}, lastOutPoint)); + tx.addInput(new TransactionInput(tx, new byte[]{OP_1}, lastOutPoint)); byte[] scriptPubKey = new byte[Block.MAX_BLOCK_SIGOPS - sigOps + 1]; Arrays.fill(scriptPubKey, (byte) OP_CHECKSIG); tx.addOutput(new TransactionOutput(params, tx, ZERO, scriptPubKey)); @@ -823,12 +823,10 @@ public class FullBlockTestGenerator { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, Coin .SATOSHI, new byte[] {OP_1})); - tx.addInput(new TransactionInput(params, tx, - new byte[] {OP_1}, lastOutPoint)); + tx.addInput(new TransactionInput(tx, new byte[] { OP_1 }, lastOutPoint)); - TransactionInput input = new TransactionInput(params, tx, - new byte[] {}, new TransactionOutPoint(0, - b39.block.getTransactions().get(i).getTxId())); + TransactionInput input = new TransactionInput(tx, new byte[] {}, + new TransactionOutPoint(0, b39.block.getTransactions().get(i).getTxId())); tx.addInput(input); if (scriptSig == null) { @@ -869,8 +867,7 @@ public class FullBlockTestGenerator { sigOps += numTxes * b39sigOpsPerOutput; Transaction tx = new Transaction(params); - tx.addInput(new TransactionInput(params, tx, - new byte[] {OP_1}, lastOutPoint)); + tx.addInput(new TransactionInput(tx, new byte[] { OP_1 }, lastOutPoint)); byte[] scriptPubKey = new byte[Block.MAX_BLOCK_SIGOPS - sigOps]; Arrays.fill(scriptPubKey, (byte) OP_CHECKSIG); tx.addOutput(new TransactionOutput(params, tx, ZERO, scriptPubKey)); @@ -1010,7 +1007,7 @@ public class FullBlockTestGenerator { NewBlock b51 = createNextBlock(b44, chainHeadHeight + 16, out15, null); { Transaction coinbase = new Transaction(params); - coinbase.addInput(new TransactionInput(params, coinbase, new byte[]{(byte) 0xff, 110, 1})); + coinbase.addInput(new TransactionInput(coinbase, new byte[]{(byte) 0xff, 110, 1})); coinbase.addOutput(new TransactionOutput(params, coinbase, SATOSHI, outScriptBytes)); b51.block.addTransaction(coinbase, false); } @@ -1527,7 +1524,7 @@ public class FullBlockTestGenerator { b83.addTransaction(tx1); Transaction tx2 = new Transaction(params); tx2.addOutput(new TransactionOutput(params, tx2, ZERO, new byte[]{OP_TRUE})); - tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_FALSE}, + tx2.addInput(new TransactionInput(tx2, new byte[] { OP_FALSE }, new TransactionOutPoint(0, tx1.getTxId()))); b83.addTransaction(tx2); } @@ -1558,24 +1555,24 @@ public class FullBlockTestGenerator { Transaction tx2 = new Transaction(params); tx2.addOutput(new TransactionOutput(params, tx2, ZERO, new byte[]{OP_RETURN})); tx2.addOutput(new TransactionOutput(params, tx2, ZERO, new byte[]{OP_RETURN})); - tx2.addInput(new TransactionInput(params, tx2, new byte[]{OP_TRUE}, new TransactionOutPoint(1, b84tx1))); + tx2.addInput(new TransactionInput(tx2, new byte[]{OP_TRUE}, new TransactionOutPoint(1, b84tx1))); b84.addTransaction(tx2); Transaction tx3 = new Transaction(params); tx3.addOutput(new TransactionOutput(params, tx3, ZERO, new byte[]{OP_RETURN})); tx3.addOutput(new TransactionOutput(params, tx3, ZERO, new byte[]{OP_TRUE})); - tx3.addInput(new TransactionInput(params, tx3, new byte[]{OP_TRUE}, new TransactionOutPoint(2, b84tx1))); + tx3.addInput(new TransactionInput(tx3, new byte[]{OP_TRUE}, new TransactionOutPoint(2, b84tx1))); b84.addTransaction(tx3); Transaction tx4 = new Transaction(params); tx4.addOutput(new TransactionOutput(params, tx4, ZERO, new byte[]{OP_TRUE})); tx4.addOutput(new TransactionOutput(params, tx4, ZERO, new byte[]{OP_RETURN})); - tx4.addInput(new TransactionInput(params, tx4, new byte[]{OP_TRUE}, new TransactionOutPoint(3, b84tx1))); + tx4.addInput(new TransactionInput(tx4, new byte[]{OP_TRUE}, new TransactionOutPoint(3, b84tx1))); b84.addTransaction(tx4); Transaction tx5 = new Transaction(params); tx5.addOutput(new TransactionOutput(params, tx5, ZERO, new byte[]{OP_RETURN})); - tx5.addInput(new TransactionInput(params, tx5, new byte[]{OP_TRUE}, new TransactionOutPoint(4, b84tx1))); + tx5.addInput(new TransactionInput(tx5, new byte[]{OP_TRUE}, new TransactionOutPoint(4, b84tx1))); b84.addTransaction(tx5); } b84.solve(); @@ -1600,7 +1597,7 @@ public class FullBlockTestGenerator { { Transaction tx = new Transaction(params); tx.addOutput(new TransactionOutput(params, tx, ZERO, new byte[] {OP_TRUE})); - tx.addInput(new TransactionInput(params, tx, new byte[]{OP_TRUE}, new TransactionOutPoint(0, b84tx1))); + tx.addInput(new TransactionInput(tx, new byte[]{OP_TRUE}, new TransactionOutPoint(0, b84tx1))); b89.addTransaction(tx); b89.solve(); } @@ -1798,7 +1795,7 @@ public class FullBlockTestGenerator { } private void addOnlyInputToTransaction(Transaction t, TransactionOutPointWithValue prevOut, long sequence) throws ScriptException { - TransactionInput input = new TransactionInput(params, t, new byte[]{}, prevOut.outpoint); + TransactionInput input = new TransactionInput(t, new byte[]{}, prevOut.outpoint); input.setSequenceNumber(sequence); t.addInput(input); diff --git a/core/src/test/java/org/bitcoinj/core/TransactionTest.java b/core/src/test/java/org/bitcoinj/core/TransactionTest.java index 1a2c1b5f1..a0227ad74 100644 --- a/core/src/test/java/org/bitcoinj/core/TransactionTest.java +++ b/core/src/test/java/org/bitcoinj/core/TransactionTest.java @@ -168,7 +168,7 @@ public class TransactionTest { int length = tx.getMessageSize(); // add fake transaction input - TransactionInput input = new TransactionInput(TESTNET, null, ScriptBuilder.createEmpty().getProgram(), + TransactionInput input = new TransactionInput(null, ScriptBuilder.createEmpty().getProgram(), new TransactionOutPoint(0, Sha256Hash.ZERO_HASH)); tx.addInput(input); length += input.getMessageSize(); @@ -489,7 +489,7 @@ public class TransactionTest { @Test public void testToStringWhenIteratingOverAnInputCatchesAnException() { Transaction tx = FakeTxBuilder.createFakeTx(TESTNET); - TransactionInput ti = new TransactionInput(TESTNET, tx, new byte[0]) { + TransactionInput ti = new TransactionInput(tx, new byte[0]) { @Override public Script getScriptSig() throws ScriptException { throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, ""); diff --git a/core/src/test/java/org/bitcoinj/protocols/payments/PaymentSessionTest.java b/core/src/test/java/org/bitcoinj/protocols/payments/PaymentSessionTest.java index 873b3b0d2..6f04cacec 100644 --- a/core/src/test/java/org/bitcoinj/protocols/payments/PaymentSessionTest.java +++ b/core/src/test/java/org/bitcoinj/protocols/payments/PaymentSessionTest.java @@ -90,7 +90,7 @@ public class PaymentSessionTest { // Send the payment and verify that the correct information is sent. // Add a dummy input to tx so it is considered valid. - tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes())); + tx.addInput(new TransactionInput(tx, outputToMe.getScriptBytes())); ArrayList txns = new ArrayList<>(); txns.add(tx); Address refundAddr = serverKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET); @@ -130,7 +130,7 @@ public class PaymentSessionTest { assertTrue(paymentSession.isExpired()); // Send the payment and verify that an exception is thrown. // Add a dummy input to tx so it is considered valid. - tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes())); + tx.addInput(new TransactionInput(tx, outputToMe.getScriptBytes())); ArrayList txns = new ArrayList<>(); txns.add(tx); @@ -169,7 +169,7 @@ public class PaymentSessionTest { // Send the payment and verify that the correct information is sent. // Add a dummy input to tx so it is considered valid. - tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes())); + tx.addInput(new TransactionInput(tx, outputToMe.getScriptBytes())); ArrayList txns = new ArrayList<>(); txns.add(tx); Address refundAddr = serverKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET); diff --git a/core/src/test/java/org/bitcoinj/script/ScriptTest.java b/core/src/test/java/org/bitcoinj/script/ScriptTest.java index 4195dcff5..5ced2307b 100644 --- a/core/src/test/java/org/bitcoinj/script/ScriptTest.java +++ b/core/src/test/java/org/bitcoinj/script/ScriptTest.java @@ -248,7 +248,7 @@ public class ScriptTest { public void testOp0() { // Check that OP_0 doesn't NPE and pushes an empty stack frame. Transaction tx = new Transaction(TESTNET); - tx.addInput(new TransactionInput(TESTNET, tx, new byte[] {})); + tx.addInput(new TransactionInput(tx, new byte[] {})); Script script = new ScriptBuilder().smallNum(0).build(); LinkedList stack = new LinkedList<>(); @@ -353,7 +353,7 @@ public class ScriptTest { tx.setVersion(1); tx.setLockTime(0); - TransactionInput txInput = new TransactionInput(TESTNET, null, + TransactionInput txInput = new TransactionInput(null, new ScriptBuilder().number(0).number(0).build().getProgram()); txInput.setSequenceNumber(TransactionInput.NO_SEQUENCE); tx.addInput(txInput); @@ -369,7 +369,7 @@ public class ScriptTest { tx.setVersion(1); tx.setLockTime(0); - TransactionInput txInput = new TransactionInput(TESTNET, creditingTransaction, scriptSig.getProgram()); + TransactionInput txInput = new TransactionInput(creditingTransaction, scriptSig.getProgram()); txInput.setSequenceNumber(TransactionInput.NO_SEQUENCE); tx.addInput(txInput); diff --git a/core/src/test/java/org/bitcoinj/wallet/DefaultRiskAnalysisTest.java b/core/src/test/java/org/bitcoinj/wallet/DefaultRiskAnalysisTest.java index 0d15c188d..b0a653801 100644 --- a/core/src/test/java/org/bitcoinj/wallet/DefaultRiskAnalysisTest.java +++ b/core/src/test/java/org/bitcoinj/wallet/DefaultRiskAnalysisTest.java @@ -161,7 +161,7 @@ public class DefaultRiskAnalysisTest { // Test non-standard script as an input. Transaction tx = new Transaction(MAINNET); assertEquals(DefaultRiskAnalysis.RuleViolation.NONE, DefaultRiskAnalysis.isStandard(tx)); - tx.addInput(new TransactionInput(MAINNET, null, nonStandardScript)); + tx.addInput(new TransactionInput(null, nonStandardScript)); assertEquals(DefaultRiskAnalysis.RuleViolation.SHORTEST_POSSIBLE_PUSHDATA, DefaultRiskAnalysis.isStandard(tx)); // Test non-standard script as an output. tx.clearInputs(); @@ -175,14 +175,14 @@ public class DefaultRiskAnalysisTest { TransactionSignature sig = TransactionSignature.dummy(); Script scriptOk = ScriptBuilder.createInputScript(sig); assertEquals(RuleViolation.NONE, - DefaultRiskAnalysis.isInputStandard(new TransactionInput(MAINNET, null, scriptOk.getProgram()))); + DefaultRiskAnalysis.isInputStandard(new TransactionInput(null, scriptOk.getProgram()))); byte[] sigBytes = sig.encodeToBitcoin(); // Appending a zero byte makes the signature uncanonical without violating DER encoding. Script scriptUncanonicalEncoding = new ScriptBuilder().data(Arrays.copyOf(sigBytes, sigBytes.length + 1)) .build(); assertEquals(RuleViolation.SIGNATURE_CANONICAL_ENCODING, - DefaultRiskAnalysis.isInputStandard(new TransactionInput(MAINNET, null, scriptUncanonicalEncoding + DefaultRiskAnalysis.isInputStandard(new TransactionInput(null, scriptUncanonicalEncoding .getProgram()))); } @@ -193,7 +193,7 @@ public class DefaultRiskAnalysisTest { Script scriptHighS = ScriptBuilder .createInputScript(new TransactionSignature(sig.r, ECKey.CURVE.getN().subtract(sig.s))); assertEquals(RuleViolation.SIGNATURE_CANONICAL_ENCODING, - DefaultRiskAnalysis.isInputStandard(new TransactionInput(MAINNET, null, scriptHighS.getProgram()))); + DefaultRiskAnalysis.isInputStandard(new TransactionInput(null, scriptHighS.getProgram()))); // This is a real transaction. Its signatures S component is "low". Transaction tx1 = new Transaction(MAINNET, ByteBuffer.wrap(ByteUtils.parseHex( diff --git a/core/src/test/java/org/bitcoinj/wallet/WalletTest.java b/core/src/test/java/org/bitcoinj/wallet/WalletTest.java index 6426bf0e1..61f626f81 100644 --- a/core/src/test/java/org/bitcoinj/wallet/WalletTest.java +++ b/core/src/test/java/org/bitcoinj/wallet/WalletTest.java @@ -751,7 +751,7 @@ public class WalletTest extends TestWithWallet { TransactionOutput to = createMock(TransactionOutput.class); EasyMock.expect(to.isAvailableForSpending()).andReturn(true); EasyMock.expect(to.isMineOrWatched(wallet)).andReturn(true); - EasyMock.expect(to.getSpentBy()).andReturn(new TransactionInput(TESTNET, null, new byte[0])); + EasyMock.expect(to.getSpentBy()).andReturn(new TransactionInput(null, new byte[0])); Transaction tx = FakeTxBuilder.createFakeTxWithoutChange(TESTNET, to); @@ -2774,7 +2774,7 @@ public class WalletTest extends TestWithWallet { // However, if there is no connected output, we will grab a COIN output anyway and add the CENT to fee SendRequest request3 = SendRequest.to(OTHER_ADDRESS, CENT); - request3.tx.addInput(new TransactionInput(TESTNET, request3.tx, new byte[]{}, new TransactionOutPoint(0, tx3.getTxId()))); + request3.tx.addInput(new TransactionInput(request3.tx, new byte[] {}, new TransactionOutPoint(0, tx3.getTxId()))); // Now completeTx will result in two inputs, two outputs and a fee of a CENT // Note that it is simply assumed that the inputs are correctly signed, though in fact the first is not request3.shuffleOutputs = false; diff --git a/integration-test/src/test/java/org/bitcoinj/core/PeerTest.java b/integration-test/src/test/java/org/bitcoinj/core/PeerTest.java index 2449708ab..c0c4fd77c 100644 --- a/integration-test/src/test/java/org/bitcoinj/core/PeerTest.java +++ b/integration-test/src/test/java/org/bitcoinj/core/PeerTest.java @@ -573,9 +573,9 @@ public class PeerTest extends TestWithNetworkConnections { t1.addInput(t2.getOutput(0)); t1.addInput(t3.getOutput(0)); Sha256Hash t7hash = Sha256Hash.wrap("2b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6"); - t1.addInput(new TransactionInput(TESTNET, t1, new byte[]{}, new TransactionOutPoint(0, t7hash))); + t1.addInput(new TransactionInput(t1, new byte[]{}, new TransactionOutPoint(0, t7hash))); Sha256Hash t8hash = Sha256Hash.wrap("3b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6"); - t1.addInput(new TransactionInput(TESTNET, t1, new byte[]{}, new TransactionOutPoint(1, t8hash))); + t1.addInput(new TransactionInput(t1, new byte[]{}, new TransactionOutPoint(1, t8hash))); t1.addOutput(COIN, to); t1 = roundTripTransaction(TESTNET, t1); t2 = roundTripTransaction(TESTNET, t2); @@ -648,7 +648,7 @@ public class PeerTest extends TestWithNetworkConnections { // The ones in brackets are assumed to be in the chain and are represented only by hashes. Sha256Hash t4hash = Sha256Hash.wrap("2b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6"); Transaction t3 = new Transaction(TESTNET); - t3.addInput(new TransactionInput(TESTNET, t3, new byte[]{}, new TransactionOutPoint(0, t4hash))); + t3.addInput(new TransactionInput(t3, new byte[]{}, new TransactionOutPoint(0, t4hash))); t3.addOutput(COIN, new ECKey()); t3 = roundTripTransaction(TESTNET, t3); Transaction t2 = new Transaction(TESTNET); @@ -751,7 +751,7 @@ public class PeerTest extends TestWithNetworkConnections { t2.setLockTime(999999); // Add a fake input to t3 that goes nowhere. Sha256Hash t3 = Sha256Hash.of("abc".getBytes(StandardCharsets.UTF_8)); - t2.addInput(new TransactionInput(TESTNET, t2, new byte[]{}, new TransactionOutPoint(0, t3))); + t2.addInput(new TransactionInput(t2, new byte[]{}, new TransactionOutPoint(0, t3))); t2.getInput(0).setSequenceNumber(0xDEADBEEF); t2.addOutput(COIN, new ECKey()); Transaction t1 = new Transaction(TESTNET); @@ -824,7 +824,7 @@ public class PeerTest extends TestWithNetworkConnections { }); connect(); Transaction t1 = new Transaction(TESTNET); - t1.addInput(new TransactionInput(TESTNET, t1, new byte[]{})); + t1.addInput(new TransactionInput(t1, new byte[]{})); t1.addOutput(COIN, new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)); Transaction t2 = new Transaction(TESTNET); t2.addInput(t1.getOutput(0));