use the same syntax as bitcoind for key import
authorThomasV <thomasv@gitorious>
Sat, 5 Jan 2013 20:28:12 +0000 (21:28 +0100)
committerThomasV <thomasv@gitorious>
Sat, 5 Jan 2013 20:28:12 +0000 (21:28 +0100)
electrum
lib/wallet.py

index 3f134d9..1489345 100755 (executable)
--- a/electrum
+++ b/electrum
@@ -70,7 +70,7 @@ options:\n  --fee, -f: set transaction fee\n  --fromaddr, -s: send from address
     'signtx':"Sign an unsigned transaction created by a deseeded wallet\nSyntax: signtx <filename>",
     'seed':
             "Print the generation seed of your wallet.",
-    'import': 
+    'importprivkey': 
             'Imports a key pair\nSyntax: import <address>:<privatekey>',
     'signmessage':
             'Signs a message with a key\nSyntax: signmessage <address> <message>\nIf you want to lead or end a message with spaces, or want double spaces inside the message make sure you quote the string. I.e. " Hello  This is a weird String "',
@@ -99,13 +99,13 @@ offline_commands = [ 'password', 'mktx', 'signtx',
                      'help', 'validateaddress',
                      'signmessage', 'verifymessage',
                      'eval', 'set', 'get', 'create', 'addresses',
-                     'import', 'seed',
+                     'importprivkey', 'seed',
                      'deseed','reseed',
                      'freeze','unfreeze',
                      'prioritize','unprioritize']
 
 
-protected_commands = ['payto', 'password', 'mktx', 'signtx', 'seed', 'import','signmessage' ]
+protected_commands = ['payto', 'password', 'mktx', 'signtx', 'seed', 'importprivkey','signmessage' ]
 
 # get password routine
 def prompt_password(prompt, confirm=True):
@@ -395,16 +395,16 @@ if __name__ == '__main__':
         else:
             password = None
 
-    if cmd == 'import':
+    if cmd == 'importprivkey':
         # See if they specificed a key on the cmd line, if not prompt
         if len(args) > 1:
-            keypair = args[1]
+            sec = args[1]
         else:
-            keypair = prompt_password('Enter Address:PrivateKey (will not echo):', False)
+            sec = prompt_password('Enter PrivateKey (will not echo):', False)
         try:
-            wallet.import_key(keypair,password)
+            addr = wallet.import_key(sec,password)
             wallet.save()
-            print_msg("Keypair imported")
+            print_msg("Keypair imported: ", addr)
         except BaseException as e:
             print_msg("Error: Keypair import failed: " + str(e))
 
index 9cde7c8..eea1778 100644 (file)
@@ -112,14 +112,8 @@ class Wallet:
         self.interface.poke('synchronizer')
         while not self.is_up_to_date(): time.sleep(0.1)
 
-    def import_key(self, keypair, password):
+    def import_key(self, sec, password):
 
-        address, sec = keypair.split(':')
-        if not self.is_valid(address):
-            raise BaseException('Invalid Bitcoin address')
-        if address in self.all_addresses():
-            raise BaseException('Address already in wallet')
-        
         # rebuild public key from private key, compressed or uncompressed
         pkey = regenerate_key(sec)
         if not pkey:
@@ -131,14 +125,14 @@ class Wallet:
         # rebuild private and public key from regenerated secret
         private_key = GetPrivKey(pkey, compressed)
         public_key = GetPubKey(pkey, compressed)
-        addr = public_key_to_bc_address(public_key)
+        address = public_key_to_bc_address(public_key)
         
-        # sanity check
-        if not address == addr :
-            raise BaseException('Address does not match private key')
+        if address in self.all_addresses():
+            raise BaseException('Address already in wallet')
         
         # store the originally requested keypair into the imported keys table
         self.imported_keys[address] = self.pw_encode(sec, password )
+        return address
         
 
     def new_seed(self, password):