From b40e5a15eaf4de2c8a22b2dcba4081e5a6194d60 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 28 Oct 2014 14:16:33 -0700 Subject: [PATCH] implement GetMiningInfo() method. --- lib/bitcoind.js | 4 ++++ src/bitcoindjs.cc | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 7a41a03f..ff9f7d29 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -365,6 +365,10 @@ Bitcoin.prototype.getGenerate = function(options) { return bitcoindjs.getGenerate(options || {}); }; +Bitcoin.prototype.getMiningInfo = function() { + return bitcoindjs.getMiningInfo(); +}; + Bitcoin.prototype.log = Bitcoin.prototype.info = function() { if (typeof arguments[0] !== 'string') { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index aee937b6..a1244457 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -170,6 +170,7 @@ NAN_METHOD(GetAddresses); NAN_METHOD(GetProgress); NAN_METHOD(SetGenerate); NAN_METHOD(GetGenerate); +NAN_METHOD(GetMiningInfo); NAN_METHOD(GetBlockHex); NAN_METHOD(GetTxHex); @@ -1643,6 +1644,35 @@ NAN_METHOD(GetGenerate) { NanReturnValue(NanNew(generate)); } +/** + * GetMiningInfo() + * bitcoindjs.getMiningInfo() + * Get coin generation / mining information + */ + +NAN_METHOD(GetMiningInfo) { + NanScope(); + + Local obj = NanNew(); + + obj->Set(NanNew("blocks"), (int)chainActive.Height())); + obj->Set(NanNew("currentblocksize"), (uint64_t)nLastBlockSize)); + obj->Set(NanNew("currentblocktx"), (uint64_t)nLastBlockTx)); + obj->Set(NanNew("difficulty"), (double)GetDifficulty())); + obj->Set(NanNew("errors"), GetWarnings("statusbar"))); + obj->Set(NanNew("genproclimit"), (int)GetArg("-genproclimit", -1))); + obj->Set(NanNew("networkhashps"), getnetworkhashps(params, false))); + obj->Set(NanNew("pooledtx"), (uint64_t)mempool.size())); + obj->Set(NanNew("testnet"), Params().NetworkID() == CBaseChainParams::TESTNET)); + obj->Set(NanNew("chain"), Params().NetworkIDString())); +#ifdef ENABLE_WALLET + obj->Set(NanNew("generate"), getgenerate(params, false))); + obj->Set(NanNew("hashespersec"), gethashespersec(params, false))); +#endif + + NanReturnValue(obj); +} + /** * GetBlockHex() * bitcoindjs.getBlockHex(callback) @@ -4362,6 +4392,7 @@ init(Handle target) { NODE_SET_METHOD(target, "getProgress", GetProgress); NODE_SET_METHOD(target, "setGenerate", SetGenerate); NODE_SET_METHOD(target, "getGenerate", GetGenerate); + NODE_SET_METHOD(target, "getMiningInfo", GetMiningInfo); NODE_SET_METHOD(target, "getBlockHex", GetBlockHex); NODE_SET_METHOD(target, "getTxHex", GetTxHex); NODE_SET_METHOD(target, "blockFromHex", BlockFromHex);