From 857c40bf9a44e482d50edacc1669b56997122273 Mon Sep 17 00:00:00 2001 From: Ovidiu Constantin Date: Mon, 16 Jan 2012 02:02:48 +0200 Subject: [PATCH] * Expand the 'balance' command line argument to support individual address balances, including not owned (watched) addresses (addresses for which the private key is not known) --- client/electrum.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/client/electrum.py b/client/electrum.py index ac3c83d3..8f2ea225 100755 --- a/client/electrum.py +++ b/client/electrum.py @@ -571,7 +571,10 @@ class Wallet: return False, "The last %d addresses in your list have never been used. You should use them first, or increase the allowed gap size in your preferences. "%self.gap_limit def get_addr_balance(self, addr): - h = self.history.get(addr) + if addr in self.addresses: + h = self.history.get(addr) + else: + h = self.interface.retrieve_history(addr) if not h: return 0,0 c = u = 0 for item in h: @@ -888,7 +891,8 @@ if __name__ == '__main__': print "known commands:", ', '.join(known_commands) print "help shows the help on a specific command" elif cmd2 == 'balance': - print "display the balance of your wallet" + print "Display the balance of your wallet or a specific address. The address does not have to be a owned address (you know the private key)." + print "syntax: balance [
]" elif cmd2 == 'contacts': print "show your list of contacts" elif cmd2 == 'payto': @@ -926,11 +930,23 @@ if __name__ == '__main__': print wallet.is_valid(addr) elif cmd == 'balance': - c, u = wallet.get_balance() - if u: - print c*1e-8, u*1e-8 + try: + addrs = args[1:] + except: + pass + if addrs == []: + c, u = wallet.get_balance() + if u: + print c*1e-8, u*1e-8 + else: + print c*1e-8 else: - print c*1e-8 + for addr in addrs: + c, u = wallet.get_addr_balance(addr) + if u: + print "%s %s, %s" % (addr, c*1e-8, u*1e-8) + else: + print "%s %s" % (addr, c*1e-8) elif cmd in [ 'contacts']: for addr in wallet.addressbook: