|
|
@ -141,14 +141,20 @@ Value getblockhash(const Array& params, bool fHelp) |
|
|
|
|
|
|
|
|
|
|
|
Value getblock(const Array& params, bool fHelp) |
|
|
|
Value getblock(const Array& params, bool fHelp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (fHelp || params.size() != 1) |
|
|
|
if (fHelp || params.size() < 1 || params.size() > 2) |
|
|
|
throw runtime_error( |
|
|
|
throw runtime_error( |
|
|
|
"getblock <hash>\n" |
|
|
|
"getblock <hash> [verbose=true]\n" |
|
|
|
"Returns details of a block with given block-hash."); |
|
|
|
"If verbose is false, returns a string that is serialized, hex-encoded data for block <hash>.\n" |
|
|
|
|
|
|
|
"If verbose is true, returns an Object with information about block <hash>." |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
std::string strHash = params[0].get_str(); |
|
|
|
std::string strHash = params[0].get_str(); |
|
|
|
uint256 hash(strHash); |
|
|
|
uint256 hash(strHash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool fVerbose = true; |
|
|
|
|
|
|
|
if (params.size() > 1) |
|
|
|
|
|
|
|
fVerbose = params[1].get_bool(); |
|
|
|
|
|
|
|
|
|
|
|
if (mapBlockIndex.count(hash) == 0) |
|
|
|
if (mapBlockIndex.count(hash) == 0) |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); |
|
|
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); |
|
|
|
|
|
|
|
|
|
|
@ -156,6 +162,14 @@ Value getblock(const Array& params, bool fHelp) |
|
|
|
CBlockIndex* pblockindex = mapBlockIndex[hash]; |
|
|
|
CBlockIndex* pblockindex = mapBlockIndex[hash]; |
|
|
|
block.ReadFromDisk(pblockindex, true); |
|
|
|
block.ReadFromDisk(pblockindex, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!fVerbose) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); |
|
|
|
|
|
|
|
ssBlock << block; |
|
|
|
|
|
|
|
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); |
|
|
|
|
|
|
|
return strHex; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return blockToJSON(block, pblockindex); |
|
|
|
return blockToJSON(block, pblockindex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|