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

Function submitblock

src/rpc/rpcmining.cpp:131–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131Value submitblock(const Array& params, bool fHelp) {
132 if (fHelp || params.size() < 1 || params.size() > 2)
133 throw runtime_error(
134 "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n"
135 "\nAttempts to submit new block to network.\n"
136 "The 'jsonparametersobject' parameter is currently ignored.\n"
137 "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
138
139 "\nArguments\n"
140 "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n"
141 "2. \"jsonparametersobject\" (string, optional) object of optional parameters\n"
142 " {\n"
143 " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with "
144 "submissions\n"
145 " }\n"
146 "\nResult:\n"
147 "\nExamples:\n" +
148 HelpExampleCli("submitblock", "\"mydata\"") + "\nAs json rpc call\n" +
149 HelpExampleRpc("submitblock", "\"mydata\""));
150
151 vector<unsigned char> blockData(ParseHex(params[0].get_str()));
152 CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
153 CBlock pBlock;
154 try {
155 ssBlock >> pBlock;
156 }
157 catch (std::exception &e) {
158 throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
159 }
160
161 CValidationState state;
162 bool fAccepted = ProcessBlock(state, NULL, &pBlock);
163 Object obj;
164 if (!fAccepted) {
165 obj.push_back(Pair("status", "rejected"));
166 obj.push_back(Pair("reject_code", state.GetRejectCode()));
167 obj.push_back(Pair("info", state.GetRejectReason()));
168 } else {
169
170 obj.push_back(Pair("status", "OK"));
171 obj.push_back(Pair("txid", pBlock.GetHash().ToString()));
172 }
173 return obj;
174}
175
176
177Value getminedblocks(const Array& params, bool fHelp) {

Callers

nothing calls this directly

Calls 12

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
ParseHexFunction · 0.85
JSONRPCErrorFunction · 0.85
ProcessBlockFunction · 0.85
PairClass · 0.85
push_backMethod · 0.80
GetRejectCodeMethod · 0.80
GetRejectReasonMethod · 0.80
sizeMethod · 0.45
ToStringMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected