allow rest/block/height.json

changes from review, added integration test
updated cache size


fixed nullptr from merge
This commit is contained in:
Brannon King 2019-05-13 17:29:32 -06:00
parent d7a092a46a
commit d1293d8e70
5 changed files with 26 additions and 9 deletions

View file

@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 12)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2016)
define(_COPYRIGHT_HOLDERS,[The %s developers])

View file

@ -14,10 +14,16 @@ Given a transaction hash: returns a transaction in binary, hex-encoded binary, o
For full TX query capability, one must enable the transaction index via "txindex=1" command line / configuration option.
#### Blocks
`GET /rest/block/tip.<bin|hex|json>`
`GET /rest/block/<BLOCK-HASH>.<bin|hex|json>`
`GET /rest/block/<BLOCK-HEIGHT>.<bin|hex|json>`
`GET /rest/block/notxdetails/tip.<bin|hex|json>`
`GET /rest/block/notxdetails/<BLOCK-HASH>.<bin|hex|json>`
`GET /rest/block/notxdetails/<BLOCK-HEIGHT>.<bin|hex|json>`
Given a block hash: returns a block, in binary, hex-encoded binary or JSON formats.
You can give a block height instead of a hash. Height 0 is not available,
but can be negative to go back that many blocks from the tip.
The HTTP request and response are both handled entirely in-memory, thus making maximum memory usage at least 2.66MB (1 MB max block, plus hex encoding) per request.

View file

@ -304,7 +304,7 @@ class CClaimTrie
{
public:
CClaimTrie(bool fMemory = false, bool fWipe = false, int nProportionalDelayFactor = 32)
: db(GetDataDir() / "claimtrie", 100, fMemory, fWipe, false), nCurrentHeight(0),
: db(GetDataDir() / "claimtrie", 20 * 1024 * 1024, fMemory, fWipe, false), nCurrentHeight(0),
nExpirationTime(Params().GetConsensus().nOriginalClaimExpirationTime),
nProportionalDelayFactor(nProportionalDelayFactor),
root(uint256S("0000000000000000000000000000000000000000000000000000000000000001"))

View file

@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 12
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 0
#define CLIENT_VERSION_BUILD 1
//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true

View file

@ -210,17 +210,28 @@ static bool rest_block(HTTPRequest* req,
const RetFormat rf = ParseDataFormat(hashStr, strURIPart);
uint256 hash;
if (!ParseHashStr(hashStr, hash))
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
long int blockHeight = 0;
if (hashStr != "tip") {
blockHeight = hashStr.size() < 12 ? std::strtol(hashStr.c_str(), NULL, 10) : 0;
if (blockHeight == 0 && !ParseHashStr(hashStr, hash))
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash or block height: " + hashStr);
}
CBlock block;
CBlockIndex* pblockindex = NULL;
{
LOCK(cs_main);
if (mapBlockIndex.count(hash) == 0)
if (blockHeight < 0) // negative block heights take us back from current tip
blockHeight += chainActive.Height();
if (blockHeight > 0 && blockHeight <= chainActive.Height())
pblockindex = chainActive[blockHeight];
else if (blockHeight != 0)
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash or block height: " + hashStr);
else if (hashStr == "tip")
pblockindex = chainActive.Tip();
else if (mapBlockIndex.count(hash))
pblockindex = mapBlockIndex[hash];
if (!pblockindex)
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
pblockindex = mapBlockIndex[hash];
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");