diff --git a/lib/bitcoind.js b/lib/bitcoind.js index ab156022..48f43a02 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -388,6 +388,11 @@ Bitcoin.prototype.getAddrTransactions = function(addr, callback) { return bitcoindjs.getAddrTransactions(addr, callback); }; +Bitcoin.prototype.getBestBlock = function(callback) { + var hash = bitcoindjs.getBestBlock(); + return bitcoindjs.getBlock(hash, callback); +}; + Bitcoin.prototype.log = Bitcoin.prototype.info = function() { if (this.options.silent) return; diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index b808ca81..4eaca259 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -252,6 +252,7 @@ NAN_METHOD(SetGenerate); NAN_METHOD(GetGenerate); NAN_METHOD(GetMiningInfo); NAN_METHOD(GetAddrTransactions); +NAN_METHOD(GetBestBlock); NAN_METHOD(GetBlockHex); NAN_METHOD(GetTxHex); @@ -2152,6 +2153,30 @@ async_get_addrtx_after(uv_work_t *req) { delete req; } +/** + * GetBestBlock() + * bitcoindjs.getBestBlock() + * Get the best block + */ + +NAN_METHOD(GetBestBlock) { + NanScope(); + + if (args.Length() < 0) { + return NanThrowError( + "Usage: bitcoindjs.getBestBlock()"); + } + + //static CCoinsViewDB *pcoinsdbview = NULL; + //pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex); + //uint256 block_hash = pcoinsdbview->GetBestBlock(); + + //CCoinsViewCache &viewChain = *pcoinsTip; + uint256 block_hash = pcoinsTip->GetBestBlock(); + + NanReturnValue(NanNew(block_hash.GetHex())); +} + /** * GetBlockHex() * bitcoindjs.getBlockHex(callback) @@ -5799,6 +5824,7 @@ init(Handle target) { NODE_SET_METHOD(target, "getGenerate", GetGenerate); NODE_SET_METHOD(target, "getMiningInfo", GetMiningInfo); NODE_SET_METHOD(target, "getAddrTransactions", GetAddrTransactions); + NODE_SET_METHOD(target, "getBestBlock", GetBestBlock); NODE_SET_METHOD(target, "getBlockHex", GetBlockHex); NODE_SET_METHOD(target, "getTxHex", GetTxHex); NODE_SET_METHOD(target, "blockFromHex", BlockFromHex);