getpubkeys command
authorThomasV <thomasv@gitorious>
Thu, 3 Oct 2013 11:31:59 +0000 (13:31 +0200)
committerThomasV <thomasv@gitorious>
Thu, 3 Oct 2013 11:31:59 +0000 (13:31 +0200)
electrum
lib/account.py
lib/commands.py
lib/wallet.py

index 93513d2..086c30f 100755 (executable)
--- a/electrum
+++ b/electrum
@@ -320,12 +320,12 @@ if __name__ == '__main__':
     # check the number of arguments
     if len(args) - 1 < cmd.min_args:
         print_msg("Not enough arguments")
-        print_msg("Syntax:", syntax)
+        print_msg("Syntax:", cmd.syntax)
         sys.exit(1)
 
     if cmd.max_args >= 0 and len(args) - 1 > cmd.max_args:
         print_msg("too many arguments", args)
-        print_msg("Syntax:", syntax)
+        print_msg("Syntax:", cmd.syntax)
         sys.exit(1)
 
     if cmd.max_args < 0:
index b07559f..bf12ae1 100644 (file)
@@ -42,6 +42,8 @@ class Account(object):
     def get_address(self, for_change, n):
         pass
         
+    def get_pubkeys(self, sequence):
+        return [ self.get_pubkey( *sequence )]
 
 
 
@@ -182,6 +184,8 @@ class BIP32_Account_2of2(BIP32_Account):
         address = hash_160_to_bc_address(hash_160(self.redeem_script((for_change, n)).decode('hex')), 5)
         return address
 
+    def get_pubkeys(self, sequence):
+        return [ self.get_pubkey( *sequence ), self.get_pubkey2( *sequence )]
 
 class BIP32_Account_2of3(BIP32_Account_2of2):
 
@@ -212,4 +216,8 @@ class BIP32_Account_2of3(BIP32_Account_2of2):
         pubkey3 = self.get_pubkey3(chain, i)
         return Transaction.multisig_script([pubkey1, pubkey2, pubkey3], 3)
 
+    def get_pubkeys(self, sequence):
+        return [ self.get_pubkey( *sequence ), self.get_pubkey2( *sequence ), self.get_pubkey3( *sequence )]
+
+
 
index 55f72ec..5a94fcb 100644 (file)
@@ -69,8 +69,9 @@ register_command('freeze',               1, 1, False, True,  True,  'Freeze the
 register_command('getbalance',           0, 1, True,  True,  False, 'Return the balance of your wallet, or of one account in your wallet', 'getbalance [<account>]')
 register_command('getservers',           0, 0, True,  False, False, 'Return the list of available servers')
 register_command('getaddressbalance',    1, 1, True,  True,  False, 'Return the balance of an address', 'getbalance <address>')
-register_command('getaddresshistory',    1, 1, True,  False, False, 'Return the transaction history of an address', 'getaddresshistory <address>')
+register_command('getaddresshistory',    1, 1, True,  True,  False, 'Return the transaction history of a wallet address', 'getaddresshistory <address>')
 register_command('getconfig',            1, 1, False, False, False, 'Return a configuration variable', 'getconfig <name>', config_options)
+register_command('getpubkeys',           1, 1, False, True,  False, 'Return the public keys for a wallet address', 'getpubkeys <bitcoin address>')
 register_command('getrawtransaction',    1, 2, True,  False, False, 'Retrieve a transaction', 'getrawtransaction <txhash> <height>')
 register_command('getseed',              0, 0, False, True,  True,  'Print the generation seed of your wallet.')
 register_command('help',                 0, 1, False, False, False, 'Prints this help')
@@ -118,6 +119,7 @@ class Commands:
         return result
 
     def getaddresshistory(self, addr):
+        assert self.wallet.is_mine(addr)
         h = self.wallet.get_history(addr)
         if h is None: h = self.network.synchronous_get([ ('blockchain.address.get_history',[addr]) ])[0]
         return h
@@ -177,17 +179,20 @@ class Commands:
             addresses = self.wallet.addresses(True)
         return [self.wallet.get_private_key(address, self.password) for address in addresses]
 
-    def validateaddress(self,addr):
+    def validateaddress(self, addr):
         isvalid = is_valid(addr)
         out = { 'isvalid':isvalid }
         if isvalid:
-            is_mine = self.wallet.is_mine(addr)
             out['address'] = addr
-            out['ismine'] = is_mine
-            if is_mine:
-                account, sequence = self.wallet.get_address_index(addr)
-                if account != -1:
-                    out['pubkey'] = self.wallet.get_public_key(addr)
+
+    def getpubkeys(self, addr):
+        assert is_valid(addr) and self.wallet.is_mine(addr)
+        out = { 'address':addr }
+        account, sequence = self.wallet.get_address_index(addr)
+        if account != -1:
+            a = self.wallet.accounts[account]
+            out['pubkeys'] = a.get_pubkeys( sequence )
+
         return out
 
     def getbalance(self, account= None):
@@ -337,14 +342,14 @@ class Commands:
                 out.append( item )
         return out
                          
-    def help(self, cmd2=None):
-        if cmd2 not in known_commands:
+    def help(self, cmd=None):
+        if cmd not in known_commands:
             print_msg("\nList of commands:", ', '.join(sorted(known_commands)))
         else:
-            _, _, description, syntax, options_syntax = known_commands[cmd2]
-            print_msg(description)
-            if syntax: print_msg("Syntax: " + syntax)
-            if options_syntax: print_msg("options:\n" + options_syntax)
+            cmd = known_commands[cmd]
+            print_msg(cmd.description)
+            if cmd.syntax: print_msg("Syntax: " + cmd.syntax)
+            if cmd.options: print_msg("options:\n" + cmd.options)
         return None
 
     def getrawtransaction(self, tx_hash, height = 0):
index 7f45a67..7bf3860 100644 (file)
@@ -555,10 +555,6 @@ class Wallet:
         return '&'.join(dd)
 
 
-    def get_public_key(self, address):
-        account, sequence = self.get_address_index(address)
-        return self.accounts[account].get_pubkey( *sequence )
-
 
     def decode_seed(self, password):
         seed = pw_decode(self.seed, password)