diff --git a/configure.ac b/configure.ac index 95ccddd47..c2227d726 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/doc/REST-interface.md b/doc/REST-interface.md index 4323ba2b8..e274ec09d 100644 --- a/doc/REST-interface.md +++ b/doc/REST-interface.md @@ -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.` `GET /rest/block/.` +`GET /rest/block/.` +`GET /rest/block/notxdetails/tip.` `GET /rest/block/notxdetails/.` +`GET /rest/block/notxdetails/.` 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. diff --git a/src/claimtrie.h b/src/claimtrie.h index 00c716532..ab1e1801c 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -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")) diff --git a/src/clientversion.h b/src/clientversion.h index fc069c480..8005ecd4c 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -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 diff --git a/src/rest.cpp b/src/rest.cpp index 2dff8d7da..607db3bc0 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -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)");