From 279b85e3fef1ef398399a9152d2279b5d50708a8 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 5 Jan 2013 21:28:12 +0100 Subject: [PATCH] use the same syntax as bitcoind for key import --- electrum | 16 ++++++++-------- lib/wallet.py | 16 +++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/electrum b/electrum index 3f134d9d..14893454 100755 --- 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 ", 'seed': "Print the generation seed of your wallet.", - 'import': + 'importprivkey': 'Imports a key pair\nSyntax: import
:', 'signmessage': 'Signs a message with a key\nSyntax: signmessage
\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)) diff --git a/lib/wallet.py b/lib/wallet.py index 9cde7c89..eea17788 100644 --- a/lib/wallet.py +++ b/lib/wallet.py @@ -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):