Allow passing branchId when calling signrawtransaction
This commit is contained in:
parent
40b9527301
commit
36a490677c
|
@ -82,6 +82,15 @@ uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) {
|
||||||
return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId;
|
return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsConsensusBranchId(int branchId) {
|
||||||
|
for (int idx = Consensus::BASE_SPROUT; idx < Consensus::MAX_NETWORK_UPGRADES; idx++) {
|
||||||
|
if (branchId == NetworkUpgradeInfo[idx].nBranchId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsActivationHeight(
|
bool IsActivationHeight(
|
||||||
int nHeight,
|
int nHeight,
|
||||||
const Consensus::Params& params,
|
const Consensus::Params& params,
|
||||||
|
|
|
@ -63,6 +63,12 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params);
|
||||||
*/
|
*/
|
||||||
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params);
|
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if a given branch id is a valid nBranchId for one of the network
|
||||||
|
* upgrades contained in NetworkUpgradeInfo.
|
||||||
|
*/
|
||||||
|
bool IsConsensusBranchId(int branchId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given block height is the activation height for the given
|
* Returns true if the given block height is the activation height for the given
|
||||||
* upgrade.
|
* upgrade.
|
||||||
|
|
|
@ -673,7 +673,7 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::
|
||||||
|
|
||||||
UniValue signrawtransaction(const UniValue& params, bool fHelp)
|
UniValue signrawtransaction(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || params.size() < 1 || params.size() > 4)
|
if (fHelp || params.size() < 1 || params.size() > 5)
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
|
"signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
|
||||||
"\nSign inputs for raw transaction (serialized, hex-encoded).\n"
|
"\nSign inputs for raw transaction (serialized, hex-encoded).\n"
|
||||||
|
@ -710,6 +710,8 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
|
||||||
" \"ALL|ANYONECANPAY\"\n"
|
" \"ALL|ANYONECANPAY\"\n"
|
||||||
" \"NONE|ANYONECANPAY\"\n"
|
" \"NONE|ANYONECANPAY\"\n"
|
||||||
" \"SINGLE|ANYONECANPAY\"\n"
|
" \"SINGLE|ANYONECANPAY\"\n"
|
||||||
|
"5. \"branchid\" (string, optional) The hex representation of the consensus branch id to sign with."
|
||||||
|
" This can be used to force signing with consensus rules that are ahead of the node's current height.\n"
|
||||||
|
|
||||||
"\nResult:\n"
|
"\nResult:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -737,7 +739,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
|
||||||
#else
|
#else
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
#endif
|
#endif
|
||||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
|
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR)(UniValue::VSTR), true);
|
||||||
|
|
||||||
vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
|
vector<unsigned char> txData(ParseHexV(params[0], "argument 1"));
|
||||||
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
@ -880,6 +882,13 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
|
||||||
// Grab the current consensus branch ID
|
// Grab the current consensus branch ID
|
||||||
auto consensusBranchId = CurrentEpochBranchId(chainHeight, Params().GetConsensus());
|
auto consensusBranchId = CurrentEpochBranchId(chainHeight, Params().GetConsensus());
|
||||||
|
|
||||||
|
if (params.size() > 4 && !params[4].isNull()) {
|
||||||
|
consensusBranchId = ParseHexToUInt32(params[4].get_str());
|
||||||
|
if (!IsConsensusBranchId(consensusBranchId)) {
|
||||||
|
throw runtime_error(params[4].get_str() + " is not a valid consensus branch id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Script verification errors
|
// Script verification errors
|
||||||
UniValue vErrors(UniValue::VARR);
|
UniValue vErrors(UniValue::VARR);
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,8 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
|
||||||
BOOST_CHECK_NO_THROW(CallRPC(string("signrawtransaction ")+rawtx+" null null NONE|ANYONECANPAY"));
|
BOOST_CHECK_NO_THROW(CallRPC(string("signrawtransaction ")+rawtx+" null null NONE|ANYONECANPAY"));
|
||||||
BOOST_CHECK_NO_THROW(CallRPC(string("signrawtransaction ")+rawtx+" [] [] NONE|ANYONECANPAY"));
|
BOOST_CHECK_NO_THROW(CallRPC(string("signrawtransaction ")+rawtx+" [] [] NONE|ANYONECANPAY"));
|
||||||
BOOST_CHECK_THROW(CallRPC(string("signrawtransaction ")+rawtx+" null null badenum"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC(string("signrawtransaction ")+rawtx+" null null badenum"), runtime_error);
|
||||||
|
BOOST_CHECK_NO_THROW(CallRPC(string("signrawtransaction ")+rawtx+" [] [] NONE|ANYONECANPAY 5ba81b19"));
|
||||||
|
BOOST_CHECK_THROW(CallRPC(string("signrawtransaction ")+rawtx+" [] [] ALL NONE|ANYONECANPAY 123abc"), runtime_error);
|
||||||
|
|
||||||
// Only check failure cases for sendrawtransaction, there's no network to send to...
|
// Only check failure cases for sendrawtransaction, there's no network to send to...
|
||||||
BOOST_CHECK_THROW(CallRPC("sendrawtransaction"), runtime_error);
|
BOOST_CHECK_THROW(CallRPC("sendrawtransaction"), runtime_error);
|
||||||
|
|
Loading…
Reference in New Issue