Add optional locktime to createrawtransaction
A non-zero locktime also causes input sequences to be set to non-max, activating the locktime.
This commit is contained in:
parent
3eaaf71fe7
commit
212bcca920
@ -76,6 +76,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "getrawtransaction", 1 },
|
{ "getrawtransaction", 1 },
|
||||||
{ "createrawtransaction", 0 },
|
{ "createrawtransaction", 0 },
|
||||||
{ "createrawtransaction", 1 },
|
{ "createrawtransaction", 1 },
|
||||||
|
{ "createrawtransaction", 2 },
|
||||||
{ "signrawtransaction", 1 },
|
{ "signrawtransaction", 1 },
|
||||||
{ "signrawtransaction", 2 },
|
{ "signrawtransaction", 2 },
|
||||||
{ "sendrawtransaction", 1 },
|
{ "sendrawtransaction", 1 },
|
||||||
|
@ -316,9 +316,9 @@ UniValue verifytxoutproof(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
UniValue createrawtransaction(const UniValue& params, bool fHelp)
|
UniValue createrawtransaction(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() != 2)
|
if (fHelp || params.size() < 2 || params.size() > 3)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...}\n"
|
"createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n"
|
||||||
"\nCreate a transaction spending the given inputs and creating new outputs.\n"
|
"\nCreate a transaction spending the given inputs and creating new outputs.\n"
|
||||||
"Outputs can be addresses or data.\n"
|
"Outputs can be addresses or data.\n"
|
||||||
"Returns hex-encoded raw transaction.\n"
|
"Returns hex-encoded raw transaction.\n"
|
||||||
@ -340,6 +340,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
|
|||||||
" \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n"
|
" \"data\": \"hex\", (string, required) The key is \"data\", the value is hex encoded data\n"
|
||||||
" ...\n"
|
" ...\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
"3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n"
|
||||||
"\nResult:\n"
|
"\nResult:\n"
|
||||||
"\"transaction\" (string) hex string of the transaction\n"
|
"\"transaction\" (string) hex string of the transaction\n"
|
||||||
|
|
||||||
@ -351,13 +352,22 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
|
|||||||
);
|
);
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ));
|
RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM), true);
|
||||||
|
if (params[0].isNull() || params[1].isNull())
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
|
||||||
|
|
||||||
UniValue inputs = params[0].get_array();
|
UniValue inputs = params[0].get_array();
|
||||||
UniValue sendTo = params[1].get_obj();
|
UniValue sendTo = params[1].get_obj();
|
||||||
|
|
||||||
CMutableTransaction rawTx;
|
CMutableTransaction rawTx;
|
||||||
|
|
||||||
|
if (params.size() > 2 && !params[2].isNull()) {
|
||||||
|
int64_t nLockTime = params[2].get_int64();
|
||||||
|
if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
|
||||||
|
rawTx.nLockTime = nLockTime;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
|
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
|
||||||
const UniValue& input = inputs[idx];
|
const UniValue& input = inputs[idx];
|
||||||
const UniValue& o = input.get_obj();
|
const UniValue& o = input.get_obj();
|
||||||
@ -371,7 +381,9 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
|
|||||||
if (nOutput < 0)
|
if (nOutput < 0)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
|
||||||
|
|
||||||
CTxIn in(COutPoint(txid, nOutput));
|
uint32_t nSequence = (rawTx.nLockTime ? std::numeric_limits<uint32_t>::max() - 1 : std::numeric_limits<uint32_t>::max());
|
||||||
|
CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);
|
||||||
|
|
||||||
rawTx.vin.push_back(in);
|
rawTx.vin.push_back(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user