diff --git a/lib/bitcoind.js b/lib/bitcoind.js index ce529568..52caf035 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -382,6 +382,10 @@ Bitcoin.prototype.getTx = function(txHash, blockHash, callback) { }); }; +Bitcoin.prototype.getInfo = function() { + return bitcoindjs.getInfo(); +}; + Bitcoin.prototype.log = Bitcoin.prototype.info = function() { if (typeof arguments[0] !== 'string') { diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 23a80704..ed3cbde7 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -166,6 +166,7 @@ NAN_METHOD(BroadcastTx); NAN_METHOD(VerifyBlock); NAN_METHOD(VerifyTransaction); NAN_METHOD(FillTransaction); +NAN_METHOD(GetInfo); NAN_METHOD(GetBlockHex); NAN_METHOD(GetTxHex); NAN_METHOD(BlockFromHex); @@ -1476,6 +1477,55 @@ NAN_METHOD(FillTransaction) { NanReturnValue(new_jstx); } +/** + * GetInfo() + * bitcoindjs.GetInfo() + * Get miscellaneous information + */ + +NAN_METHOD(GetInfo) { + NanScope(); + + if (args.Length() > 0) { + return NanThrowError( + "Usage: bitcoindjs.getInfo()"); + } + + Local obj = NanNew(); + + proxyType proxy; + GetProxy(NET_IPV4, proxy); + + obj->Set("version", NanNew(CLIENT_VERSION)); + obj->Set("protocolversion", NanNew(PROTOCOL_VERSION)); +#ifdef ENABLE_WALLET + if (pwalletMain) { + obj->Set("walletversion", NanNewGetVersion())); + obj->Set("balance", NanNew(pwalletMain->GetBalance())); // double + } +#endif + obj->Set("blocks", NanNew((int)chainActive.Height())->ToInt32()); + obj->Set("timeoffset", NanNew(GetTimeOffset())); + obj->Set("connections", NanNew((int)vNodes.size())->ToInt32()); + obj->Set("proxy", NanNew(proxy.IsValid() ? proxy.ToStringIPPort() : std::string(""))); + obj->Set("difficulty", NanNew((double)GetDifficulty())); + obj->Set("testnet", NanNew(Params().NetworkID() == CBaseChainParams::TESTNET)); +#ifdef ENABLE_WALLET + if (pwalletMain) { + obj->Set("keypoololdest", NanNew(pwalletMain->GetOldestKeyPoolTime())); + obj->Set("keypoolsize", NanNew((int)pwalletMain->GetKeyPoolSize())->ToInt32()); + } + if (pwalletMain && pwalletMain->IsCrypted()) { + obj->Set("unlocked_until", NanNew(nWalletUnlockTime)); + } + obj->Set("paytxfee", NanNew(payTxFee.GetFeePerK())); // double +#endif + obj->Set("relayfee", NanNew(::minRelayTxFee.GetFeePerK())); // double + obj->Set("errors", NanNew(GetWarnings("statusbar"))); + + NanReturnValue(obj); +} + /** * GetBlockHex() * bitcoindjs.getBlockHex(callback) @@ -3173,6 +3223,7 @@ init(Handle target) { NODE_SET_METHOD(target, "verifyBlock", VerifyBlock); NODE_SET_METHOD(target, "verifyTransaction", VerifyTransaction); NODE_SET_METHOD(target, "fillTransaction", FillTransaction); + NODE_SET_METHOD(target, "getInfo", GetInfo); NODE_SET_METHOD(target, "getBlockHex", GetBlockHex); NODE_SET_METHOD(target, "getTxHex", GetTxHex); NODE_SET_METHOD(target, "blockFromHex", BlockFromHex);