MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / submitblock

Function submitblock

src/rpcmining.cpp:614–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

612};
613
614UniValue 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 }

Callers

nothing calls this directly

Calls 14

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
DecodeHexBlkFunction · 0.85
JSONRPCErrorFunction · 0.85
ProcessNewBlockFunction · 0.85
BIP22ValidationResultFunction · 0.85
get_strMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected