commit 114f6150be4182bb82614f1c9ce07727300541c2
parent 037d611480b0eb42fdc0b9023ea603ac5f1047f9
Author: ThomasV <thomasv@gitorious>
Date: Tue, 21 Feb 2012 17:08:59 +0100
Merge branch 'master' of gitorious.org:electrum/electrum
Diffstat:
3 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/client/electrum b/client/electrum
@@ -27,7 +27,7 @@ from decimal import Decimal
from wallet import format_satoshis
if __name__ == '__main__':
- known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'mktx','seed','import','signmessage','verifymessage','eval', 'gtk','qt']
+ known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'restore', 'payto', 'sendtx', 'password', 'addresses', 'history', 'label', 'mktx','seed','import','signmessage','verifymessage','eval']
usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands))
@@ -88,12 +88,13 @@ if __name__ == '__main__':
if cmd not in known_commands:
cmd = 'help'
- if not wallet.read() and cmd not in ['help','create']:
+ if not wallet.read() and cmd not in ['help','create','restore']:
print "Wallet file not found."
print "Type 'electrum.py create' to create a new wallet, or provide a path to a wallet with the -d option"
sys.exit(0)
- if cmd == 'create':
+ if cmd in ['create', 'restore']:
+ import mnemonic
if wallet.read():
print "remove the existing wallet first!"
sys.exit(0)
@@ -110,27 +111,38 @@ if __name__ == '__main__':
port = raw_input("port (default:%d):"%interface.port)
fee = raw_input("fee (default:%s):"%( str(Decimal(wallet.fee)/100000000)) )
gap = raw_input("gap limit (default 5):")
- if fee: wallet.fee = float(fee)
if host: interface.host = host
if port: interface.port = int(port)
+ if fee: wallet.fee = float(fee)
if gap: wallet.gap_limit = int(gap)
- seed = raw_input("if you are restoring an existing wallet, enter the seed. otherwise just press enter: ")
- if seed:
- wallet.seed = seed
+
+ if cmd == 'restore':
+ seed = raw_input("seed:")
+ try:
+ seed.decode('hex')
+ except:
+ print "not hex, trying decode"
+ seed = mnemonic.mn_decode( seed.split(' ') )
+ if not seed:
+ print "no seed"
+ sys.exit(1)
+
+ wallet.seed = str(seed)
print "recovering wallet..."
+ wallet.init_mpk( wallet.seed ) # not encrypted at this point
wallet.synchronize()
if wallet.is_found():
wallet.fill_addressbook()
wallet.save()
print "recovery successful"
else:
- print "no wallet found"
+ print "found no history for this wallet"
else:
wallet.new_seed(None)
- print "Your seed is", wallet.seed
- print "Please store it safely"
- # generate first key
- wallet.synchronize()
+ print "Your wallet generation seed is: " + wallet.seed
+ print "Please keep it in a safe place; if you lose it, you will not be able to restore your wallet."
+ print "Equivalently, your wallet seed can be stored and recovered with the following mnemonic code:"
+ print "\""+' '.join(mnemonic.mn_encode(wallet.seed))+"\""
# check syntax
if cmd in ['payto', 'mktx']:
@@ -146,7 +158,7 @@ if __name__ == '__main__':
cmd = 'help'
# open session
- if cmd not in ['password', 'mktx', 'history', 'label', 'contacts', 'help', 'validateaddress', 'signmessage', 'verifymessage', 'eval']:
+ if cmd not in ['password', 'mktx', 'history', 'label', 'contacts', 'help', 'validateaddress', 'signmessage', 'verifymessage', 'eval', 'create']:
interface.new_session(wallet.all_addresses(), wallet.electrum_version)
interface.update_wallet(wallet)
wallet.save()
@@ -198,8 +210,6 @@ if __name__ == '__main__':
print "broadcast a transaction to the network. <tx> must be in hexadecimal"
elif cmd2 == 'password':
print "change your password"
- elif cmd2 == 'newaddress':
- print "create a new receiving address. password is needed."
elif cmd2 == 'addresses':
print "show your list of addresses. options: -a, -k, -b"
elif cmd2 == 'history':
@@ -351,10 +361,6 @@ if __name__ == '__main__':
r, h = wallet.sendtx( tx )
print h
- elif cmd == 'newaddress':
- s, a = wallet.get_new_address()
- print a
-
elif cmd == 'password':
try:
seed = wallet.pw_decode( wallet.seed, password)
diff --git a/client/version.py b/client/version.py
@@ -1,2 +1,2 @@
-ELECTRUM_VERSION = "0.40a"
+ELECTRUM_VERSION = "0.40b"
SEED_VERSION = 4 # bump this everytime the seed generation is modified
diff --git a/client/wallet.py b/client/wallet.py
@@ -287,6 +287,7 @@ class Wallet:
def import_key(self, keypair, password):
address, key = keypair.split(':')
if not self.is_valid(address): return False
+ if address in self.all_addresses(): return False
b = ASecretToSecret( key )
if not b: return False
secexp = int( b.encode('hex'), 16)
@@ -303,6 +304,12 @@ class Wallet:
# encrypt
self.seed = self.pw_encode( seed, password )
+ # create addresses
+ self.create_new_address_without_history(True)
+ for i in range(self.gap_limit):
+ self.create_new_address_without_history(False)
+
+
def init_mpk(self,seed):
# public key
curve = SECP256k1
@@ -418,7 +425,7 @@ class Wallet:
raise BaseException("Bad signature")
- def create_new_address(self, for_change):
+ def create_new_address_without_history(self, for_change):
""" Publickey(type,n) = Master_public_key + H(n|S|type)*point """
curve = SECP256k1
n = len(self.change_addresses) if for_change else len(self.addresses)
@@ -432,8 +439,14 @@ class Wallet:
else:
self.addresses.append(address)
- # updates
+ self.history[address] = []
+ self.status[address] = None
print address
+ return address
+
+
+ def create_new_address(self, bool):
+ address = self.create_new_address_without_history(bool)
self.history[address] = h = self.interface.retrieve_history(address)
self.status[address] = h[-1]['blk_hash'] if h else None
return address