add GetBestBlock().

This commit is contained in:
Christopher Jeffrey 2014-11-06 13:37:15 -08:00
parent 3a8ded71b3
commit f8efdb105e
2 changed files with 31 additions and 0 deletions

View File

@ -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;

View File

@ -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<String>(block_hash.GetHex()));
}
/**
* GetBlockHex()
* bitcoindjs.getBlockHex(callback)
@ -5799,6 +5824,7 @@ init(Handle<Object> 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);