aboutsummaryrefslogtreecommitdiff
path: root/src/rpcblockchain.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@bitpay.com>2013-06-10 08:16:39 -0700
committerJeff Garzik <jgarzik@bitpay.com>2013-06-10 08:16:39 -0700
commit543d70a676cd9f8fa75b1063b0adf78708e9cbb1 (patch)
treef00a875597eff276c4f7c3504615dc640faf5b93 /src/rpcblockchain.cpp
parentf59530ce6eb5a889e6eb750024ddb20e7b0df9d7 (diff)
parent23319521418691ddfcb228684c900c389f3f114d (diff)
downloadbitcoin-543d70a676cd9f8fa75b1063b0adf78708e9cbb1.tar.xz
Merge pull request #2747 from luke-jr/getblock_verbose0
Add verbose flag to getblock RPC so it is possible to get hex dumps of blocks
Diffstat (limited to 'src/rpcblockchain.cpp')
-rw-r--r--src/rpcblockchain.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
index b1b0c1ac16..a0ddc4d9ee 100644
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -144,14 +144,20 @@ Value getblockhash(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(
- "getblock <hash>\n"
- "Returns details of a block with given block-hash.");
+ "getblock <hash> [verbose=true]\n"
+ "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();
uint256 hash(strHash);
+ bool fVerbose = true;
+ if (params.size() > 1)
+ fVerbose = params[1].get_bool();
+
if (mapBlockIndex.count(hash) == 0)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
@@ -159,6 +165,14 @@ Value getblock(const Array& params, bool fHelp)
CBlockIndex* pblockindex = mapBlockIndex[hash];
block.ReadFromDisk(pblockindex);
+ if (!fVerbose)
+ {
+ CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
+ ssBlock << block;
+ std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
+ return strHex;
+ }
+
return blockToJSON(block, pblockindex);
}