Skip to content

Commit e279038

Browse files
committed
Use createrawtx locktime parm in txn_clone
Streamlines the test and serves as a test of the createrawtransaction locktime parameter.
1 parent 8ea5ef1 commit e279038

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

qa/rpc-tests/txn_clone.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,10 @@ def run_test(self):
5757
clone_inputs = [{"txid":rawtx1["vin"][0]["txid"],"vout":rawtx1["vin"][0]["vout"]}]
5858
clone_outputs = {rawtx1["vout"][0]["scriptPubKey"]["addresses"][0]:rawtx1["vout"][0]["value"],
5959
rawtx1["vout"][1]["scriptPubKey"]["addresses"][0]:rawtx1["vout"][1]["value"]}
60-
clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs)
60+
clone_locktime = rawtx1["locktime"]
61+
clone_raw = self.nodes[0].createrawtransaction(clone_inputs, clone_outputs, clone_locktime)
6162

62-
# 3 hex manipulations on the clone are required
63-
64-
# manipulation 1. sequence is at version+#inputs+input+sigstub
65-
posseq = 2*(4+1+36+1)
66-
seqbe = '%08x' % rawtx1["vin"][0]["sequence"]
67-
clone_raw = clone_raw[:posseq] + seqbe[6:8] + seqbe[4:6] + seqbe[2:4] + seqbe[0:2] + clone_raw[posseq + 8:]
68-
69-
# manipulation 2. createrawtransaction randomizes the order of its outputs, so swap them if necessary.
63+
# createrawtransaction randomizes the order of its outputs, so swap them if necessary.
7064
# output 0 is at version+#inputs+input+sigstub+sequence+#outputs
7165
# 40 BTC serialized is 00286bee00000000
7266
pos0 = 2*(4+1+36+1+4+1)
@@ -78,11 +72,6 @@ def run_test(self):
7872
output1 = clone_raw[pos0 + output_len : pos0 + 2 * output_len]
7973
clone_raw = clone_raw[:pos0] + output1 + output0 + clone_raw[pos0 + 2 * output_len:]
8074

81-
# manipulation 3. locktime is after outputs
82-
poslt = pos0 + 2 * output_len
83-
ltbe = '%08x' % rawtx1["locktime"]
84-
clone_raw = clone_raw[:poslt] + ltbe[6:8] + ltbe[4:6] + ltbe[2:4] + ltbe[0:2] + clone_raw[poslt + 8:]
85-
8675
# Use a different signature hash type to sign. This creates an equivalent but malleated clone.
8776
# Don't send the clone anywhere yet
8877
tx1_clone = self.nodes[0].signrawtransaction(clone_raw, None, None, "ALL|ANYONECANPAY")

0 commit comments

Comments
 (0)