|
10 | 10 | #include <consensus/params.h>
|
11 | 11 | #include <consensus/validation.h>
|
12 | 12 | #include <core_io.h>
|
13 |
| -#include <validation.h> |
14 | 13 | #include <key_io.h>
|
15 | 14 | #include <miner.h>
|
16 | 15 | #include <net.h>
|
|
23 | 22 | #include <txmempool.h>
|
24 | 23 | #include <util.h>
|
25 | 24 | #include <utilstrencodings.h>
|
| 25 | +#include <validation.h> |
26 | 26 | #include <validationinterface.h>
|
27 | 27 | #include <warnings.h>
|
28 | 28 |
|
@@ -763,6 +763,42 @@ static UniValue submitblock(const JSONRPCRequest& request)
|
763 | 763 | return BIP22ValidationResult(sc.state);
|
764 | 764 | }
|
765 | 765 |
|
| 766 | +static UniValue submitheader(const JSONRPCRequest& request) |
| 767 | +{ |
| 768 | + if (request.fHelp || request.params.size() != 1) { |
| 769 | + throw std::runtime_error( |
| 770 | + "submitheader \"hexdata\"\n" |
| 771 | + "\nDecode the given hexdata as a header and submit it as a candidate chain tip if valid." |
| 772 | + "\nThrows when the header is invalid.\n" |
| 773 | + "\nArguments\n" |
| 774 | + "1. \"hexdata\" (string, required) the hex-encoded block header data\n" |
| 775 | + "\nResult:\n" |
| 776 | + "None" |
| 777 | + "\nExamples:\n" + |
| 778 | + HelpExampleCli("submitheader", "\"aabbcc\"") + |
| 779 | + HelpExampleRpc("submitheader", "\"aabbcc\"")); |
| 780 | + } |
| 781 | + |
| 782 | + CBlockHeader h; |
| 783 | + if (!DecodeHexBlockHeader(h, request.params[0].get_str())) { |
| 784 | + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block header decode failed"); |
| 785 | + } |
| 786 | + { |
| 787 | + LOCK(cs_main); |
| 788 | + if (!LookupBlockIndex(h.hashPrevBlock)) { |
| 789 | + throw JSONRPCError(RPC_VERIFY_ERROR, "Must submit previous header (" + h.hashPrevBlock.GetHex() + ") first"); |
| 790 | + } |
| 791 | + } |
| 792 | + |
| 793 | + CValidationState state; |
| 794 | + ProcessNewBlockHeaders({h}, state, Params(), /* ppindex */ nullptr, /* first_invalid */ nullptr); |
| 795 | + if (state.IsValid()) return NullUniValue; |
| 796 | + if (state.IsError()) { |
| 797 | + throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state)); |
| 798 | + } |
| 799 | + throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason()); |
| 800 | +} |
| 801 | + |
766 | 802 | static UniValue estimatefee(const JSONRPCRequest& request)
|
767 | 803 | {
|
768 | 804 | throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee was removed in v0.17.\n"
|
@@ -940,6 +976,7 @@ static const CRPCCommand commands[] =
|
940 | 976 | { "mining", "prioritisetransaction", &prioritisetransaction, {"txid","dummy","fee_delta"} },
|
941 | 977 | { "mining", "getblocktemplate", &getblocktemplate, {"template_request"} },
|
942 | 978 | { "mining", "submitblock", &submitblock, {"hexdata","dummy"} },
|
| 979 | + { "mining", "submitheader", &submitheader, {"hexdata"} }, |
943 | 980 |
|
944 | 981 |
|
945 | 982 | { "generating", "generatetoaddress", &generatetoaddress, {"nblocks","address","maxtries"} },
|
|
0 commit comments