| 977 | }; |
| 978 | |
| 979 | UniValue submitblock(const UniValue& params, bool fHelp) |
| 980 | { |
| 981 | if (fHelp || params.size() < 1 || params.size() > 2) { |
| 982 | throw runtime_error( |
| 983 | "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n" |
| 984 | "\nAttempts to submit new block to network.\n" |
| 985 | "The 'jsonparametersobject' parameter is currently ignored.\n" |
| 986 | "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n" |
| 987 | |
| 988 | "\nArguments\n" |
| 989 | "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n" |
| 990 | "2. \"jsonparametersobject\" (string, optional) object of optional parameters\n" |
| 991 | " {\n" |
| 992 | " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n" |
| 993 | " }\n" |
| 994 | "\nResult:\n" |
| 995 | "\nExamples:\n" + |
| 996 | HelpExampleCli("submitblock", "\"mydata\"") + HelpExampleRpc("submitblock", "\"mydata\"")); |
| 997 | } |
| 998 | |
| 999 | CBlock block; |
| 1000 | if (!DecodeHexBlk(block, params[0].get_str())) { |
| 1001 | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); |
| 1002 | } |
| 1003 | |
| 1004 | CValidationState state; |
| 1005 | bool fBlockPresent = false; |
| 1006 | int TheHeight = 0; |
| 1007 | { |
| 1008 | LOCK(cs_main); |
| 1009 | CBlockIndex* pindexPrev = LookupBlockIndex(block.hashPrevBlock); |
| 1010 | UpdateUncommittedBlockStructures(block, pindexPrev, Params().GetConsensus()); |
| 1011 | |
| 1012 | TheHeight = pindexPrev ? pindexPrev->nHeight + 1 : 0; |
| 1013 | uint256 hash = block.GetHash(TheHeight); |
| 1014 | CBlockIndex* pindex = LookupBlockIndex(hash); |
| 1015 | if (pindex) { |
| 1016 | if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) { |
| 1017 | return "duplicate"; |
| 1018 | } |
| 1019 | if (pindex->nStatus & BLOCK_FAILED_MASK) { |
| 1020 | return "duplicate-invalid"; |
| 1021 | } |
| 1022 | // Otherwise, we might only have the header - process the block before returning |
| 1023 | fBlockPresent = true; |
| 1024 | } |
| 1025 | bool fValid = TestBlockValidity(state, Params(), block, pindexPrev, false, true); |
| 1026 | if (!state.IsValid()) { |
| 1027 | LogPrintf("%s: block state is not valid!\n", __func__); |
| 1028 | } |
| 1029 | if (!fValid) { |
| 1030 | LogPrintf("%s: block is not valid!\n", __func__); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | submitblock_StateCatcher sc(block.GetHash(TheHeight), TheHeight); |
| 1035 | RegisterValidationInterface(&sc); |
| 1036 |
nothing calls this directly
no test coverage detected