| 768 | }; |
| 769 | |
| 770 | static UniValue submitblock(const JSONRPCRequest& request) |
| 771 | { |
| 772 | // We allow 2 arguments for compliance with BIP22. Argument 2 is ignored. |
| 773 | if (request.fHelp || request.params.size() < 1 || request.params.size() > 3) { |
| 774 | throw std::runtime_error( |
| 775 | "submitblock \"hexdata\" ( \"dummy\" \"legacy\" )\n" |
| 776 | "\nAttempts to submit new block to network.\n" |
| 777 | "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n" |
| 778 | |
| 779 | "\nArguments\n" |
| 780 | "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n" |
| 781 | "2. \"dummy\" (optional) dummy value, for compatibility with BIP22. This value is ignored.\n" |
| 782 | "3. \"legacy\" (boolean, optional) indicates if the block is in legacy foramt. default: false.\n" |
| 783 | "\nResult:\n" |
| 784 | "\nExamples:\n" |
| 785 | + HelpExampleCli("submitblock", "\"mydata\"") |
| 786 | + HelpExampleRpc("submitblock", "\"mydata\"") |
| 787 | ); |
| 788 | } |
| 789 | |
| 790 | std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>(); |
| 791 | CBlock& block = *blockptr; |
| 792 | bool legacy_format = false; |
| 793 | if (request.params.size() == 3 && request.params[2].get_bool() == true) { |
| 794 | legacy_format = true; |
| 795 | } |
| 796 | if (!DecodeHexBlk(block, request.params[0].get_str(), legacy_format)) { |
| 797 | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); |
| 798 | } |
| 799 | |
| 800 | if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) { |
| 801 | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a coinbase"); |
| 802 | } |
| 803 | |
| 804 | uint256 hash = block.GetHash(); |
| 805 | { |
| 806 | LOCK(cs_main); |
| 807 | const CBlockIndex* pindex = LookupBlockIndex(hash); |
| 808 | if (pindex) { |
| 809 | if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) { |
| 810 | return "duplicate"; |
| 811 | } |
| 812 | if (pindex->nStatus & BLOCK_FAILED_MASK) { |
| 813 | return "duplicate-invalid"; |
| 814 | } |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | { |
| 819 | LOCK(cs_main); |
| 820 | const CBlockIndex* pindex = LookupBlockIndex(block.hashPrevBlock); |
| 821 | if (pindex) { |
| 822 | UpdateUncommittedBlockStructures(block, pindex, Params().GetConsensus()); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | bool new_block; |
| 827 | submitblock_StateCatcher sc(block.GetHash()); |
nothing calls this directly
no test coverage detected