Skip to content

Commit

Permalink
[RPC] createrawtransaction: add option to set the sequence number per…
Browse files Browse the repository at this point in the history
… input
  • Loading branch information
jonasschnelli authored and str4d committed Apr 13, 2018
1 parent e8f5b02 commit 216e94f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qa/rpc-tests/rawtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,11 @@ def run_test(self):
self.sync_all()
assert_equal(self.nodes[0].getbalance(), bal+Decimal('10.00000000')+Decimal('2.19900000')) #block reward + tx

inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 1000}]
outputs = { self.nodes[0].getnewaddress() : 1 }
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
decrawtx= self.nodes[0].decoderawtransaction(rawtx)
assert_equal(decrawtx['vin'][0]['sequence'], 1000)

if __name__ == '__main__':
RawTransactionsTest().main()
7 changes: 7 additions & 0 deletions src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
" {\n"
" \"txid\":\"id\", (string, required) The transaction id\n"
" \"vout\":n (numeric, required) The output number\n"
" \"sequence\":n (numeric, optional) The sequence number\n"
" }\n"
" ,...\n"
" ]\n"
Expand Down Expand Up @@ -478,6 +479,12 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");

uint32_t nSequence = (rawTx.nLockTime ? std::numeric_limits<uint32_t>::max() - 1 : std::numeric_limits<uint32_t>::max());

// set the sequence number if passed in the parameters object
const UniValue& sequenceObj = find_value(o, "sequence");
if (sequenceObj.isNum())
nSequence = sequenceObj.get_int();

CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);

rawTx.vin.push_back(in);
Expand Down

0 comments on commit 216e94f

Please sign in to comment.