aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rest.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/rest.cpp b/src/rest.cpp
index 6ba15172fa..7792844992 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -157,13 +157,13 @@ static bool rest_headers(HTTPRequest* req,
}
}
- CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
- for (const CBlockIndex *pindex : headers) {
- ssHeader << pindex->GetBlockHeader();
- }
-
switch (rf) {
case RetFormat::BINARY: {
+ CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
+ for (const CBlockIndex *pindex : headers) {
+ ssHeader << pindex->GetBlockHeader();
+ }
+
std::string binaryHeader = ssHeader.str();
req->WriteHeader("Content-Type", "application/octet-stream");
req->WriteReply(HTTP_OK, binaryHeader);
@@ -171,6 +171,11 @@ static bool rest_headers(HTTPRequest* req,
}
case RetFormat::HEX: {
+ CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
+ for (const CBlockIndex *pindex : headers) {
+ ssHeader << pindex->GetBlockHeader();
+ }
+
std::string strHex = HexStr(ssHeader.begin(), ssHeader.end()) + "\n";
req->WriteHeader("Content-Type", "text/plain");
req->WriteReply(HTTP_OK, strHex);
@@ -224,11 +229,10 @@ static bool rest_block(HTTPRequest* req,
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
}
- CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
- ssBlock << block;
-
switch (rf) {
case RetFormat::BINARY: {
+ CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
+ ssBlock << block;
std::string binaryBlock = ssBlock.str();
req->WriteHeader("Content-Type", "application/octet-stream");
req->WriteReply(HTTP_OK, binaryBlock);
@@ -236,6 +240,8 @@ static bool rest_block(HTTPRequest* req,
}
case RetFormat::HEX: {
+ CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
+ ssBlock << block;
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()) + "\n";
req->WriteHeader("Content-Type", "text/plain");
req->WriteReply(HTTP_OK, strHex);
@@ -360,11 +366,11 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
- CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
- ssTx << tx;
-
switch (rf) {
case RetFormat::BINARY: {
+ CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
+ ssTx << tx;
+
std::string binaryTx = ssTx.str();
req->WriteHeader("Content-Type", "application/octet-stream");
req->WriteReply(HTTP_OK, binaryTx);
@@ -372,6 +378,9 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
}
case RetFormat::HEX: {
+ CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
+ ssTx << tx;
+
std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n";
req->WriteHeader("Content-Type", "text/plain");
req->WriteReply(HTTP_OK, strHex);