@@ -316,9 +316,9 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp)
316316
317317UniValue createrawtransaction (const UniValue& params, bool fHelp )
318318{
319- if (fHelp || params.size () != 2 )
319+ if (fHelp || params.size () < 2 || params. size () > 3 )
320320 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 "
322322 " \n Create a transaction spending the given inputs and creating new outputs.\n "
323323 " Outputs can be addresses or data.\n "
324324 " Returns hex-encoded raw transaction.\n "
@@ -340,6 +340,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
340340 " \" data\" : \" hex\" , (string, required) The key is \" data\" , the value is hex encoded data\n "
341341 " ...\n "
342342 " }\n "
343+ " 3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n "
343344 " \n Result:\n "
344345 " \" transaction\" (string) hex string of the transaction\n "
345346
@@ -351,13 +352,22 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
351352 );
352353
353354 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" );
355358
356359 UniValue inputs = params[0 ].get_array ();
357360 UniValue sendTo = params[1 ].get_obj ();
358361
359362 CMutableTransaction rawTx;
360363
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+
361371 for (unsigned int idx = 0 ; idx < inputs.size (); idx++) {
362372 const UniValue& input = inputs[idx];
363373 const UniValue& o = input.get_obj ();
@@ -371,7 +381,9 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
371381 if (nOutput < 0 )
372382 throw JSONRPCError (RPC_INVALID_PARAMETER, " Invalid parameter, vout must be positive" );
373383
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+
375387 rawTx.vin .push_back (in);
376388 }
377389
0 commit comments