rename 'addresses' command as 'listadresses'. use json syntax.
authorthomasv <thomasv@gitorious>
Fri, 1 Mar 2013 10:21:10 +0000 (11:21 +0100)
committerthomasv <thomasv@gitorious>
Fri, 1 Mar 2013 10:21:10 +0000 (11:21 +0100)
electrum
lib/bitcoin.py
lib/commands.py

index b69af6c..8386eae 100755 (executable)
--- a/electrum
+++ b/electrum
@@ -63,6 +63,8 @@ def arg_parser():
     parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline")
     parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
     parser.add_option("-b", "--balance", action="store_true", dest="show_balance", default=False, help="show the balance at listed addresses")
+    parser.add_option("-l", "--labels", action="store_true", dest="show_labels", default=False, help="show the labels of listed addresses")
+
     parser.add_option("-f", "--fee", dest="tx_fee", default="0.005", help="set tx fee")
     parser.add_option("-F", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.")
     parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet")
@@ -376,8 +378,8 @@ if __name__ == '__main__':
     elif cmd == 'createrawtransaction':
         args = [ cmd, json.loads(args[1]), json.loads(args[2])]
 
-    elif cmd=='addresses':
-        args = [cmd, options.show_all]
+    elif cmd=='listaddresses':
+        args = [cmd, options.show_all, options.show_balance, options.show_labels]
                 
     elif cmd == 'setlabel':
         try:
index 6df05c4..5faff5f 100644 (file)
@@ -475,6 +475,7 @@ class Transaction:
         self.outputs = self.d['outputs']
         self.outputs = map(lambda x: (x['address'],x['value']), self.outputs)
         self.input_info = None
+        self.is_complete = True
         
     @classmethod
     def from_io(klass, inputs, outputs):
index ac1ee5b..255c41f 100644 (file)
@@ -38,7 +38,7 @@ options:\n  --fee, -f: set transaction fee\n  --fromaddr, -s: send from address
             'Broadcasts a transaction to the network. \nSyntax: sendrawtransaction <tx in hexadecimal>',
     'password': 
             "Changes your password",
-    'addresses':  
+    'listaddresses':
             """Shows your list of addresses.
 options:
   -a: show all addresses, including change addresses""",
@@ -87,7 +87,7 @@ offline_commands = [ 'password', 'mktx',
                      'setlabel', 'contacts',
                      'help', 'validateaddress',
                      'signmessage', 'verifymessage',
-                     'eval', 'set', 'get', 'create', 'addresses',
+                     'eval', 'set', 'get', 'create', 'listaddresses',
                      'importprivkey', 'get_seed',
                      'deseed',
                      'freeze','unfreeze',
@@ -286,17 +286,21 @@ class Commands:
         return c
 
 
-    def addresses(self, show_all = False):
+    def listaddresses(self, show_all = False, show_balance = False, show_label = False):
         out = []
         for addr in self.wallet.all_addresses():
             if show_all or not self.wallet.is_change(addr):
-
-                flags = self.wallet.get_address_flags(addr)
-                label = self.wallet.labels.get(addr,'')
-                if label: label = "\"%s\""%label
-                b = format_satoshis(self.wallet.get_addr_balance(addr)[0])
-                m_addr = "%34s"%addr
-                out.append( flags + ' ' + m_addr + ' ' + b + ' ' + label )
+                if show_balance or show_label:
+                    item = { 'address': addr }
+                    if show_balance:
+                        item['balance'] = str(Decimal(self.wallet.get_addr_balance(addr)[0])/100000000)
+                    if show_label:
+                        label = self.wallet.labels.get(addr,'')
+                        if label:
+                            item['label'] = label
+                else:
+                    item = addr
+                out.append( item )
         return out