From 6299b996143e205a4341a7fc118bfb116bdee487 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 5 Aug 2016 14:27:10 -0700 Subject: [PATCH] rpc: implement getmininginfo. --- lib/bcoin/http/rpc.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/bcoin/http/rpc.js b/lib/bcoin/http/rpc.js index 41ae18c3..55af3ace 100644 --- a/lib/bcoin/http/rpc.js +++ b/lib/bcoin/http/rpc.js @@ -1132,9 +1132,37 @@ RPC.prototype.getblocktemplate = function getblocktemplate(args, callback) { }; RPC.prototype.getmininginfo = function getmininginfo(args, callback) { + var self = this; + if (args.help || args.length !== 0) return callback(new Error('getmininginfo')); - callback(new Error('Not implemented.')); + + this.chain.getBlock(this.chain.tip.hash, function(err, block) { + if (err) + return callback(err); + + if (!block) + return callback(new Error('Block not found.')); + + self._hashps(120, -1, function(err, hashps) { + if (err) + return callback(err); + + callback(null, { + blocks: self.chain.height, + currentblocksize: block.getSize(), + currentblocktx: block.txs.length, + difficulty: self._getDifficulty(), + errors: '', + genproclimit: self.proclimit, + networkhashps: hashps, + pooledtx: self.mempool.total, + testnet: self.network.type !== 'main', + chain: self.network.type, + generate: self.mining + }); + }); + }); }; RPC.prototype.getnetworkhashps = function getnetworkhashps(args, callback) {