diff --git a/plugins/currency/bitcoin/bitcoind_ b/plugins/currency/bitcoin/bitcoind_ index 6a7bccb8..12fe03bd 100755 --- a/plugins/currency/bitcoin/bitcoind_ +++ b/plugins/currency/bitcoin/bitcoind_ @@ -69,7 +69,6 @@ def main(): command = sys.argv[1] if len(sys.argv) > 1 else None request_labels = {'balance': ('Wallet Balance', 'BTC'), 'connections': ('Peer Connections', 'Connections'), - 'fees': ("Tip Offered", "BTC"), 'transactions': ("Transactions", "Transactions", ('confirmed', 'waiting')), 'block_age': ("Last Block Age", "Seconds"), @@ -120,8 +119,9 @@ def main(): bitcoin_options.rpcport), username=bitcoin_options.rpcuser, password=bitcoin_options.rpcpassword) - (info, connect_error) = bitcoin.getinfo() - error = "Could not connect to Bitcoin server: {}".format(connect_error) + (info, connect_error) = bitcoin.getnetworkinfo() + if connect_error: + error = "Could not connect to Bitcoin server: {}".format(connect_error) if command == 'autoconf': if error: @@ -134,20 +134,35 @@ def main(): print(error, file=sys.stderr) return False + if request_var == 'balance': + # we use getbalance*s* (plural) as old getbalance is being deprecated, + # and we have to calculate total balance (owned and watch-only) manually now. + (info, error) = bitcoin.getbalances() + + total = sum(info[wallet_mode]['trusted'] + for wallet_mode in ('mine', 'watchonly') + if wallet_mode in info) + + info['balance'] = total + if request_var in ('transactions', 'block_age'): - (info, error) = bitcoin.getblockhash(info['blocks']) - (info, error) = bitcoin.getblock(info) + (info, error) = bitcoin.getblockchaininfo() + (info, error) = bitcoin.getblock(info['bestblockhash']) info['block_age'] = int(time.time()) - info['time'] info['confirmed'] = len(info['tx']) - if request_var in ('fees', 'transactions'): - (memory_pool, error) = bitcoin.getrawmempool() - if memory_pool: - info['waiting'] = len(memory_pool) + if request_var == 'difficulty': + (info, error) = bitcoin.getblockchaininfo() + + if request_var == 'transactions': + (memory_pool, error) = bitcoin.getmempoolinfo() + info['waiting'] = memory_pool['size'] for label in line_labels: print("%s.value %s" % (label, info[label])) + return True + def parse_conf(filename): """ Bitcoin config file parser. """ @@ -249,7 +264,7 @@ class Proxy: return (None, e) if DEBUG: - print('RPC Response (%s): %s' % (self.method, json.dumps(body, indent=4))) + print('RPC Response (%s): %s' % (self.method, json.dumps(json.loads(body), indent=4))) try: data = json.loads(body)