Add support for requesting headers in binary or hexadecimal format. This is faster than requesting full blocks.
No JSON format defined for now, and I'm not sure whether we need one.
Add support for requesting headers in binary or hexadecimal format. This is faster than requesting full blocks.
No JSON format defined for now, and I'm not sure whether we need one.
Code looks good to me.
However, it's still a lot of HTTP overhead, even with keep-alive, to request one header per HTTP request. /rest/headers/ seems more appropriate, a la 'getutxos'.
Suggestion: GET /rest/headers/$hash.ext gets 2000 headers, unless a "?limit=N" qualifier is added.
Would /rest/headers/limit/2000/<hash>.ext be a overkill?
But maybe the query string parameter is more clear.
109 | + throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found"); 110 | + header = mapBlockIndex[hash]->GetBlockHeader(); 111 | + } 112 | + 113 | + CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION); 114 | + ssBlock << header;
shouldn't ssBlock be ssHeader?
114 | + ssBlock << header; 115 | + 116 | + switch (rf) { 117 | + case RF_BINARY: { 118 | + string binaryHeader = ssHeader.str(); 119 | + conn->stream() << HTTPReplyHeader(HTTP_OK, fRun, binaryBlock.size(), "application/octet-stream") << binaryBlock << std::flush;
shouldn't binaryBlock be ssBlock?
?= parameters. ?= parameters are non-canonical in that they can be provided in any order, which introduces a kind of aliasing that messes with cachingRegarding JSON: Is there a reason to not support JSON? I think there are many potential REST users using script programming languages like Python or PHP. The unpacking of the byte array is somehow annoying in these languages and people might tend to have a overhead in the information transmission protocol (TCP/HTTP/JSON in this case) and save some development effort. We could even say HTTP is a overhead (because its plaintext and line based). Then we would end up in a raw TCP socket and might be very close to the P2P protocol. IMO we should distinct both "APIs".
I would find it a bad idea to have a potential JSON output format which does not support all possible methods.
A feasible step would to drop JSON support completely for the REST API. But we might have to come out of our byte-optimized-land and see what others expect from a API.
Packing/unpacking byte arrays is well-supported in Python, I do that all the time, that's a bit of a strawman. See also https://github.com/petertodd/python-bitcoinlib .
Anyhow: headers have a well-defined format, and for hashing and such you really need the canonical, raw data. A "cooked" version would be much less useful. It could be added later but I doubt there is actual demand for it.
Updated.
needs rebase
tested (rebase is trivial).
ACK