diff --git a/integration/regtest.js b/integration/regtest.js index 76582ea8..55ba9e27 100644 --- a/integration/regtest.js +++ b/integration/regtest.js @@ -410,4 +410,24 @@ 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'); + info.hash_serialized.length.should.equal(64); + info.height.should.equal(151); + info.total_amount.should.equal(750000000000); + 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 f0ddecd0..816b6d5e 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -224,6 +224,14 @@ Bitcoin.prototype.addMempoolUncheckedTransaction = function(txBuffer) { return bindings.addMempoolUncheckedTransaction(txBuffer); }; +Bitcoin.prototype.getBestBlockHash = function() { + return bindings.getBestBlockHash(); +}; + +Bitcoin.prototype.getTxOutSetInfo = function() { + return bindings.getTxOutSetInfo(); +}; + Bitcoin.prototype.getInfo = function() { return bindings.getInfo(); }; diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index 6759b9f3..78ddd5fc 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -203,6 +203,39 @@ NAN_METHOD(SyncPercentage) { NanReturnValue(NanNew(progress * 100)); }; +NAN_METHOD(GetTxOutSetInfo) { + Isolate* isolate = args.GetIsolate(); + HandleScope scope(isolate); + { + + LOCK(cs_main); + + CCoinsStats stats; + FlushStateToDisk(); + if (pcoinsTip->GetStats(stats)) { + Local obj = NanNew(); + obj->Set(NanNew("height"), NanNew((int64_t)stats.nHeight)); + obj->Set(NanNew("bestblock"), NanNew(stats.hashBlock.GetHex())); + obj->Set(NanNew("transactions"), NanNew((int64_t)stats.nTransactions)); + obj->Set(NanNew("txouts"), NanNew((int64_t)stats.nTransactionOutputs)); + obj->Set(NanNew("bytes_serialized"), NanNew((int64_t)stats.nSerializedSize)); + obj->Set(NanNew("hash_serialized"), NanNew(stats.hashSerialized.GetHex())); + obj->Set(NanNew("total_amount"), NanNew(stats.nTotalAmount)); + NanReturnValue(obj); + } + } + + NanReturnValue(NanNull()); + +}; + +NAN_METHOD(GetBestBlockHash) { + { + LOCK(cs_main); + NanReturnValue(NanNew(chainActive.Tip()->GetBlockHash().GetHex())); + } +} + /** * IsSynced() * bitcoind.isSynced() @@ -1629,6 +1662,8 @@ init(Handle target) { NODE_SET_METHOD(target, "startTxMon", StartTxMon); 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 45010446..8a214265 100644 --- a/src/libbitcoind.h +++ b/src/libbitcoind.h @@ -36,3 +36,5 @@ NAN_METHOD(EstimateFee); 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 15d87260..6b52b919 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -408,6 +408,8 @@ describe('Bitcoin Service', function() { ['getTransactionWithBlockInfo', 3], ['getMempoolTransactions', 0], ['addMempoolUncheckedTransaction', 1], + ['getTxOutSetInfo', 0], + ['getBestBlockHash', 0], ['getInfo', 0] ];