@@ -316,9 +316,9 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp)
316
316
317
317
UniValue createrawtransaction (const UniValue& params, bool fHelp )
318
318
{
319
- if (fHelp || params.size () != 2 )
319
+ if (fHelp || params.size () < 2 || params. size () > 3 )
320
320
throw runtime_error (
321
- " createrawtransaction [{\" txid\" :\" id\" ,\" vout\" :n},...] {\" address\" :amount,\" data\" :\" hex\" ,...}\n "
321
+ " createrawtransaction [{\" txid\" :\" id\" ,\" vout\" :n},...] {\" address\" :amount,\" data\" :\" hex\" ,...} ( locktime ) \n "
322
322
" \n Create a transaction spending the given inputs and creating new outputs.\n "
323
323
" Outputs can be addresses or data.\n "
324
324
" Returns hex-encoded raw transaction.\n "
@@ -340,6 +340,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
340
340
" \" data\" : \" hex\" , (string, required) The key is \" data\" , the value is hex encoded data\n "
341
341
" ...\n "
342
342
" }\n "
343
+ " 3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n "
343
344
" \n Result:\n "
344
345
" \" transaction\" (string) hex string of the transaction\n "
345
346
@@ -351,13 +352,22 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
351
352
);
352
353
353
354
LOCK (cs_main);
354
- RPCTypeCheck (params, boost::assign::list_of (UniValue::VARR)(UniValue::VOBJ));
355
+ RPCTypeCheck (params, boost::assign::list_of (UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM), true );
356
+ if (params[0 ].isNull () || params[1 ].isNull ())
357
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, arguments 1 and 2 must be non-null" );
355
358
356
359
UniValue inputs = params[0 ].get_array ();
357
360
UniValue sendTo = params[1 ].get_obj ();
358
361
359
362
CMutableTransaction rawTx;
360
363
364
+ if (params.size () > 2 && !params[2 ].isNull ()) {
365
+ int64_t nLockTime = params[2 ].get_int64 ();
366
+ if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t >::max ())
367
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, locktime out of range" );
368
+ rawTx.nLockTime = nLockTime;
369
+ }
370
+
361
371
for (unsigned int idx = 0 ; idx < inputs.size (); idx++) {
362
372
const UniValue& input = inputs[idx];
363
373
const UniValue& o = input.get_obj ();
@@ -371,7 +381,9 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
371
381
if (nOutput < 0 )
372
382
throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, vout must be positive" );
373
383
374
- CTxIn in (COutPoint (txid, nOutput));
384
+ uint32_t nSequence = (rawTx.nLockTime ? std::numeric_limits<uint32_t >::max () - 1 : std::numeric_limits<uint32_t >::max ());
385
+ CTxIn in (COutPoint (txid, nOutput), CScript (), nSequence);
386
+
375
387
rawTx.vin .push_back (in);
376
388
}
377
389
0 commit comments