Skip to content

Commit a946bb6

Browse files
committed
[RPC] createrawtransaction: add option to set the sequence number per input
1 parent 08b37c5 commit a946bb6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

qa/rpc-tests/rawtransactions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,11 @@ def run_test(self):
137137
self.sync_all()
138138
assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
139139

140+
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 1000}]
141+
outputs = { self.nodes[0].getnewaddress() : 1 }
142+
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
143+
decrawtx= self.nodes[0].decoderawtransaction(rawtx)
144+
assert_equal(decrawtx['vin'][0]['sequence'], 1000)
145+
140146
if __name__ == '__main__':
141147
RawTransactionsTest().main()

src/rpc/rawtransaction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
334334
" {\n"
335335
" \"txid\":\"id\", (string, required) The transaction id\n"
336336
" \"vout\":n (numeric, required) The output number\n"
337+
" \"sequence\":n (numeric, optional) The sequence number\n"
337338
" }\n"
338339
" ,...\n"
339340
" ]\n"
@@ -384,6 +385,12 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
384385
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
385386

386387
uint32_t nSequence = (rawTx.nLockTime ? std::numeric_limits<uint32_t>::max() - 1 : std::numeric_limits<uint32_t>::max());
388+
389+
// set the sequence number if passed in the parameters object
390+
const UniValue& sequenceObj = find_value(o, "sequence");
391+
if (sequenceObj.isNum())
392+
nSequence = sequenceObj.get_int();
393+
387394
CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
388395

389396
rawTx.vin.push_back(in);

0 commit comments

Comments
 (0)