From 76277ad8af05195aa27d731d568ed06a4366a1f0 Mon Sep 17 00:00:00 2001 From: Jay Graber Date: Thu, 14 Jun 2018 03:50:52 -0700 Subject: [PATCH] Take expiryheight as param to createrawtransaction --- src/rpc/client.cpp | 2 +- src/rpc/rawtransaction.cpp | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 3fc68ee6f..5288d977e 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -77,6 +77,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "createrawtransaction", 0 }, { "createrawtransaction", 1 }, { "createrawtransaction", 2 }, + { "createrawtransaction", 3 }, { "signrawtransaction", 1 }, { "signrawtransaction", 2 }, { "sendrawtransaction", 1 }, @@ -189,4 +190,3 @@ UniValue RPCConvertValues(const std::string &strMethod, const std::vector 3) + if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,...} ( locktime )\n" "\nCreate a transaction spending the given inputs and sending to the given addresses.\n" @@ -434,6 +434,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) " ,...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" + "4. expiryheight (numeric, optional, default=0) Expiry height of transaction\n" "\nResult:\n" "\"transaction\" (string) hex string of the transaction\n" @@ -443,7 +444,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) ); LOCK(cs_main); - RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM), true); + RPCTypeCheck(params, boost::assign::list_of(UniValue::VARR)(UniValue::VOBJ)(UniValue::VNUM)(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"); @@ -453,12 +454,6 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) int nextBlockHeight = chainActive.Height() + 1; CMutableTransaction rawTx = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); - - if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { - if (rawTx.nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD){ - throw JSONRPCError(RPC_INVALID_PARAMETER, "nExpiryHeight must be less than TX_EXPIRY_HEIGHT_THRESHOLD."); - } - } if (params.size() > 2 && !params[2].isNull()) { int64_t nLockTime = params[2].get_int64(); @@ -466,6 +461,16 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range"); rawTx.nLockTime = nLockTime; } + + if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { + if (params.size() > 3 && !params[3].isNull()) { + int64_t nExpiryHeight = params[3].get_int64(); + if (nExpiryHeight < 0 || nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, nExpiryHeight must be less than TX_EXPIRY_HEIGHT_THRESHOLD."); + } + rawTx.nExpiryHeight = nExpiryHeight; + } + } for (size_t idx = 0; idx < inputs.size(); idx++) { const UniValue& input = inputs[idx];