use the same syntax as bitcoind for key import

This commit is contained in:
ThomasV 2013-01-05 21:28:12 +01:00
parent 42dbf61ba8
commit 279b85e3fe
2 changed files with 13 additions and 19 deletions

View File

@ -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>", 'signtx':"Sign an unsigned transaction created by a deseeded wallet\nSyntax: signtx <filename>",
'seed': 'seed':
"Print the generation seed of your wallet.", "Print the generation seed of your wallet.",
'import': 'importprivkey':
'Imports a key pair\nSyntax: import <address>:<privatekey>', 'Imports a key pair\nSyntax: import <address>:<privatekey>',
'signmessage': '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 "', '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', 'help', 'validateaddress',
'signmessage', 'verifymessage', 'signmessage', 'verifymessage',
'eval', 'set', 'get', 'create', 'addresses', 'eval', 'set', 'get', 'create', 'addresses',
'import', 'seed', 'importprivkey', 'seed',
'deseed','reseed', 'deseed','reseed',
'freeze','unfreeze', 'freeze','unfreeze',
'prioritize','unprioritize'] 'prioritize','unprioritize']
protected_commands = ['payto', 'password', 'mktx', 'signtx', 'seed', 'import','signmessage' ] protected_commands = ['payto', 'password', 'mktx', 'signtx', 'seed', 'importprivkey','signmessage' ]
# get password routine # get password routine
def prompt_password(prompt, confirm=True): def prompt_password(prompt, confirm=True):
@ -395,16 +395,16 @@ if __name__ == '__main__':
else: else:
password = None password = None
if cmd == 'import': if cmd == 'importprivkey':
# See if they specificed a key on the cmd line, if not prompt # See if they specificed a key on the cmd line, if not prompt
if len(args) > 1: if len(args) > 1:
keypair = args[1] sec = args[1]
else: else:
keypair = prompt_password('Enter Address:PrivateKey (will not echo):', False) sec = prompt_password('Enter PrivateKey (will not echo):', False)
try: try:
wallet.import_key(keypair,password) addr = wallet.import_key(sec,password)
wallet.save() wallet.save()
print_msg("Keypair imported") print_msg("Keypair imported: ", addr)
except BaseException as e: except BaseException as e:
print_msg("Error: Keypair import failed: " + str(e)) print_msg("Error: Keypair import failed: " + str(e))

View File

@ -112,13 +112,7 @@ class Wallet:
self.interface.poke('synchronizer') self.interface.poke('synchronizer')
while not self.is_up_to_date(): time.sleep(0.1) 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 # rebuild public key from private key, compressed or uncompressed
pkey = regenerate_key(sec) pkey = regenerate_key(sec)
@ -131,14 +125,14 @@ class Wallet:
# rebuild private and public key from regenerated secret # rebuild private and public key from regenerated secret
private_key = GetPrivKey(pkey, compressed) private_key = GetPrivKey(pkey, compressed)
public_key = GetPubKey(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 address in self.all_addresses():
if not address == addr : raise BaseException('Address already in wallet')
raise BaseException('Address does not match private key')
# store the originally requested keypair into the imported keys table # store the originally requested keypair into the imported keys table
self.imported_keys[address] = self.pw_encode(sec, password ) self.imported_keys[address] = self.pw_encode(sec, password )
return address
def new_seed(self, password): def new_seed(self, password):