mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
testproposedblock option to reject non-standard block
This commit is contained in:
parent
904d35f899
commit
047629873a
2 changed files with 16 additions and 2 deletions
|
|
@ -136,6 +136,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||
{ "getmempoolancestors", 1, "verbose" },
|
||||
{ "getmempooldescendants", 1, "verbose" },
|
||||
{ "bumpfee", 1, "options" },
|
||||
{ "testproposedblock", 1, "acceptnonstd" },
|
||||
// Echo with conversion (For testing only)
|
||||
{ "echojson", 0, "arg0" },
|
||||
{ "echojson", 1, "arg1" },
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "validationinterface.h"
|
||||
#include "policy/policy.h"
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
#include "wallet/wallet.h"
|
||||
|
|
@ -336,12 +337,13 @@ std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
|
|||
|
||||
UniValue testproposedblock(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() != 1)
|
||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
|
||||
throw std::runtime_error(
|
||||
"testproposedblock \"blockhex\"\n"
|
||||
"\nChecks a block proposal for validity, and that it extends chaintip\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"blockhex\" (string, required) The hex-encoded block from getnewblockhex\n"
|
||||
"2. \"acceptnonstd\" (bool, optional) If set false, returns error if block contains non-standard transaction. Default is set via `-acceptnonstdtxn`\n"
|
||||
"\nResult\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("testproposedblock", "<hex>")
|
||||
|
|
@ -371,6 +373,17 @@ UniValue testproposedblock(const JSONRPCRequest& request)
|
|||
throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
|
||||
}
|
||||
|
||||
const CChainParams& chainparams = Params();
|
||||
if ((!request.params[1].isNull() && !request.params[1].get_bool()) ||
|
||||
(request.params[1].isNull() && !GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()))) {
|
||||
for (auto& transaction : block.vtx) {
|
||||
std::string reason;
|
||||
if (!IsStandardTx(*transaction, reason)) {
|
||||
throw JSONRPCError(RPC_VERIFY_ERROR, "Block proposal included a non-standard transaction: " + reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
|
|
@ -994,7 +1007,7 @@ static const CRPCCommand commands[] =
|
|||
{ "mining", "prioritisetransaction", &prioritisetransaction, true, {"txid","priority_delta","fee_delta"} },
|
||||
{ "mining", "getblocktemplate", &getblocktemplate, true, {"template_request"} },
|
||||
{ "mining", "submitblock", &submitblock, true, {"hexdata","parameters"} },
|
||||
{ "mining", "testproposedblock", &testproposedblock, true, {} },
|
||||
{ "mining", "testproposedblock", &testproposedblock, true, {"blockhex", "acceptnonstd"} },
|
||||
|
||||
{ "generating", "generate", &generate, true, {"nblocks","maxtries"} },
|
||||
{ "generating", "combineblocksigs", &combineblocksigs, true, {} },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue