| 612 | }; |
| 613 | |
| 614 | UniValue submitblock(const UniValue& params, bool fHelp) |
| 615 | { |
| 616 | if (fHelp || params.size() < 1 || params.size() > 2) |
| 617 | throw runtime_error( |
| 618 | "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n" |
| 619 | "\nAttempts to submit new block to network.\n" |
| 620 | "The 'jsonparametersobject' parameter is currently ignored.\n" |
| 621 | "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n" |
| 622 | |
| 623 | "\nArguments\n" |
| 624 | "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n" |
| 625 | "2. \"jsonparametersobject\" (string, optional) object of optional parameters\n" |
| 626 | " {\n" |
| 627 | " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n" |
| 628 | " }\n" |
| 629 | "\nResult:\n" |
| 630 | "\nExamples:\n" |
| 631 | + HelpExampleCli("submitblock", "\"mydata\"") |
| 632 | + HelpExampleRpc("submitblock", "\"mydata\"") |
| 633 | ); |
| 634 | |
| 635 | CBlock block; |
| 636 | if (!DecodeHexBlk(block, params[0].get_str())) |
| 637 | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); |
| 638 | |
| 639 | uint256 hash = block.GetHash(); |
| 640 | bool fBlockPresent = false; |
| 641 | { |
| 642 | LOCK(cs_main); |
| 643 | BlockMap::iterator mi = mapBlockIndex.find(hash); |
| 644 | if (mi != mapBlockIndex.end()) { |
| 645 | CBlockIndex *pindex = mi->second; |
| 646 | if (pindex->IsValid(BLOCK_VALID_SCRIPTS)) |
| 647 | return "duplicate"; |
| 648 | if (pindex->nStatus & BLOCK_FAILED_MASK) |
| 649 | return "duplicate-invalid"; |
| 650 | // Otherwise, we might only have the header - process the block before returning |
| 651 | fBlockPresent = true; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | CValidationState state; |
| 656 | submitblock_StateCatcher sc(block.GetHash()); |
| 657 | RegisterValidationInterface(&sc); |
| 658 | bool fAccepted = ProcessNewBlock(state, BlockSource{}, &block, true, NULL); |
| 659 | UnregisterValidationInterface(&sc); |
| 660 | if (fBlockPresent) |
| 661 | { |
| 662 | if (fAccepted && !sc.found) |
| 663 | return "duplicate-inconclusive"; |
| 664 | return "duplicate"; |
| 665 | } |
| 666 | if (fAccepted) |
| 667 | { |
| 668 | if (!sc.found) |
| 669 | return "inconclusive"; |
| 670 | state = sc.state; |
| 671 | } |
nothing calls this directly
no test coverage detected