diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-12-11 10:32:36 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-12-11 10:33:11 +0100 |
commit | 5e521d3e4ed8467b147179af0814b3b4de92e9e3 (patch) | |
tree | 265375ce7d9e1113bd6eb89319ae21bc62a00b34 /src | |
parent | 34468066ff54881eedd06e9aca39c3aa455cfe7c (diff) | |
parent | 932ef50f775b5f514941e6ee9dc91d0dcf89321f (diff) |
Merge pull request #5391
932ef50 [REST] JSON output: remove block infos from tx details if it is nested in block (Jonas Schnelli)
cae5486 [REST] added /rest/block/notxdetails/<hash> into REST-interface.md documentation (Jonas Schnelli)
73351c3 [REST] /rest/block response with full tx details (Jonas Schnelli)
Diffstat (limited to 'src')
-rw-r--r-- | src/rest.cpp | 26 | ||||
-rw-r--r-- | src/rpcblockchain.cpp | 14 |
2 files changed, 34 insertions, 6 deletions
diff --git a/src/rest.cpp b/src/rest.cpp index 6285784af5..6329b44c53 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -42,7 +42,7 @@ public: }; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry); -extern Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex); +extern Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false); static RestErr RESTERR(enum HTTPStatusCode status, string message) { @@ -92,7 +92,8 @@ static bool ParseHashStr(const string& strReq, uint256& v) static bool rest_block(AcceptedConnection* conn, string& strReq, map<string, string>& mapHeaders, - bool fRun) + bool fRun, + bool showTxDetails) { vector<string> params; enum RetFormat rf = ParseDataFormat(params, strReq); @@ -131,7 +132,7 @@ static bool rest_block(AcceptedConnection* conn, } case RF_JSON: { - Object objBlock = blockToJSON(block, pblockindex); + Object objBlock = blockToJSON(block, pblockindex, showTxDetails); string strJSON = write_string(Value(objBlock), false) + "\n"; conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush; return true; @@ -146,6 +147,22 @@ static bool rest_block(AcceptedConnection* conn, return true; // continue to process further HTTP reqs on this cxn } +static bool rest_block_extended(AcceptedConnection* conn, + string& strReq, + map<string, string>& mapHeaders, + bool fRun) +{ + return rest_block(conn, strReq, mapHeaders, fRun, true); +} + +static bool rest_block_notxdetails(AcceptedConnection* conn, + string& strReq, + map<string, string>& mapHeaders, + bool fRun) +{ + return rest_block(conn, strReq, mapHeaders, fRun, false); +} + static bool rest_tx(AcceptedConnection* conn, string& strReq, map<string, string>& mapHeaders, @@ -205,7 +222,8 @@ static const struct { bool fRun); } uri_prefixes[] = { {"/rest/tx/", rest_tx}, - {"/rest/block/", rest_block}, + {"/rest/block/notxdetails/", rest_block_notxdetails}, + {"/rest/block/", rest_block_extended}, }; bool HTTPReq_REST(AcceptedConnection* conn, diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 924f416904..66e86ebace 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -16,6 +16,7 @@ using namespace json_spirit; using namespace std; +extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex); double GetDifficulty(const CBlockIndex* blockindex) @@ -50,7 +51,7 @@ double GetDifficulty(const CBlockIndex* blockindex) } -Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex) +Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { Object result; result.push_back(Pair("hash", block.GetHash().GetHex())); @@ -65,7 +66,16 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex) result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); Array txs; BOOST_FOREACH(const CTransaction&tx, block.vtx) - txs.push_back(tx.GetHash().GetHex()); + { + if(txDetails) + { + Object objTx; + TxToJSON(tx, uint256(0), objTx); + txs.push_back(objTx); + } + else + txs.push_back(tx.GetHash().GetHex()); + } result.push_back(Pair("tx", txs)); result.push_back(Pair("time", block.GetBlockTime())); result.push_back(Pair("nonce", (uint64_t)block.nNonce)); |