diff --git a/integration/regtest.js b/integration/regtest.js index dc4fab19..fd7f7e01 100644 --- a/integration/regtest.js +++ b/integration/regtest.js @@ -400,9 +400,11 @@ describe('Daemon Binding Functionality', function() { }); describe('get transaction output set information', function() { + var bestblock; it('will get the correct info', function() { var info = bitcoind.getTxOutSetInfo(); info.bestblock.should.be.a('string'); + bestblock = info.bestblock; info.bestblock.length.should.equal(64); info.bytes_serialized.should.equal(10431); info.hash_serialized.should.be.a('string'); @@ -412,5 +414,9 @@ describe('Daemon Binding Functionality', function() { info.transactions.should.equal(151); info.txouts.should.equal(151); }); + it('will get the best block hash', function() { + var best = bitcoind.getBestBlockHash(); + best.should.equal(bestblock); + }); }); }); diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index becc813f..59cca5b8 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -223,6 +223,10 @@ Bitcoin.prototype.addMempoolUncheckedTransaction = function(txBuffer) { return bindings.addMempoolUncheckedTransaction(txBuffer); }; +Bitcoin.prototype.getBestBlockHash = function() { + return bindings.getBestBlockHash(); +}; + Bitcoin.prototype.getTxOutSetInfo = function() { return bindings.getTxOutSetInfo(); }; diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index e0dd0103..4905d40f 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -229,6 +229,13 @@ NAN_METHOD(GetTxOutSetInfo) { }; +NAN_METHOD(GetBestBlockHash) { + { + LOCK(cs_main); + NanReturnValue(NanNew(chainActive.Tip()->GetBlockHash().GetHex())); + } +} + /** * IsSynced() * bitcoind.isSynced() @@ -1702,6 +1709,7 @@ init(Handle target) { NODE_SET_METHOD(target, "syncPercentage", SyncPercentage); NODE_SET_METHOD(target, "isSynced", IsSynced); NODE_SET_METHOD(target, "getTxOutSetInfo", GetTxOutSetInfo); + NODE_SET_METHOD(target, "getBestBlockHash", GetBestBlockHash); } diff --git a/src/libbitcoind.h b/src/libbitcoind.h index f4adcfa1..9a960e75 100644 --- a/src/libbitcoind.h +++ b/src/libbitcoind.h @@ -37,3 +37,4 @@ NAN_METHOD(StartTxMon); NAN_METHOD(SyncPercentage); NAN_METHOD(IsSynced); NAN_METHOD(GetTxOutSetInfo); +NAN_METHOD(GetBestBlockHash); diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 6f152e31..f341caaa 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -409,6 +409,7 @@ describe('Bitcoin Service', function() { ['getMempoolOutputs', 1], ['addMempoolUncheckedTransaction', 1], ['getTxOutSetInfo', 0], + ['getBestBlockHash', 0], ['getInfo', 0] ];