diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fe51aca..3827607 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -144,7 +144,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPri { Object entry; - entry.push_back(Pair("txid", tx.GetHash().GetHex())); + //entry.push_back(Pair("txid", tx.GetHash().GetHex())); TxToJSON(tx, 0, entry); txinfo.push_back(entry); @@ -239,6 +239,10 @@ Value getblock(const Array& params, bool fHelp) 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"); @@ -246,7 +250,14 @@ Value getblock(const Array& params, bool fHelp) CBlockIndex* pblockindex = mapBlockIndex[hash]; block.ReadFromDisk(pblockindex, true); - return blockToJSON(block, pblockindex, params.size() > 1 ? params[1].get_bool() : false); + if (!fVerbose) { + CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); + ssBlock << block; + std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); + return strHex; + } + + return blockToJSON(block, pblockindex, fVerbose); } Value getblockbynumber(const Array& params, bool fHelp) diff --git a/src/rpcprotocol.cpp b/src/rpcprotocol.cpp index 13dd64e..aabb1fb 100644 --- a/src/rpcprotocol.cpp +++ b/src/rpcprotocol.cpp @@ -252,3 +252,11 @@ Object JSONRPCError(int code, const string& message) error.push_back(Pair("message", message)); return error; } + +int RPCSerializationFlags() +{ + int flag = 0; + if (GetArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0) + flag |= SERIALIZE_TRANSACTION_NO_WITNESS; + return flag; +} diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h index a5da6fe..d5a126b 100644 --- a/src/rpcprotocol.h +++ b/src/rpcprotocol.h @@ -137,4 +137,10 @@ json_spirit::Object JSONRPCReplyObj(const json_spirit::Value& result, const json std::string JSONRPCReply(const json_spirit::Value& result, const json_spirit::Value& error, const json_spirit::Value& id); json_spirit::Object JSONRPCError(int code, const std::string& message); +static const int DEFAULT_RPC_SERIALIZE_VERSION = 1; +static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000; + +// Retrieves any serialization flags requested in command line argument +int RPCSerializationFlags(); + #endif