separate address creation and subscribe
This commit is contained in:
@@ -136,8 +136,10 @@ if __name__ == '__main__':
|
|||||||
wallet.seed = str(seed)
|
wallet.seed = str(seed)
|
||||||
wallet.start_interface()
|
wallet.start_interface()
|
||||||
print "recovering wallet..."
|
print "recovering wallet..."
|
||||||
wallet.init_mpk( wallet.seed ) # not encrypted at this point
|
wallet.init_mpk( wallet.seed )
|
||||||
wallet.synchronize()
|
wallet.start_interface()
|
||||||
|
thread.start_new_thread(wallet.run, ())
|
||||||
|
wallet.update()
|
||||||
if wallet.is_found():
|
if wallet.is_found():
|
||||||
wallet.fill_addressbook()
|
wallet.fill_addressbook()
|
||||||
wallet.save()
|
wallet.save()
|
||||||
@@ -146,6 +148,8 @@ if __name__ == '__main__':
|
|||||||
print "found no history for this wallet"
|
print "found no history for this wallet"
|
||||||
else:
|
else:
|
||||||
wallet.new_seed(None)
|
wallet.new_seed(None)
|
||||||
|
wallet.init_mpk( wallet.seed )
|
||||||
|
wallet.synchronize() # there is no wallet thread
|
||||||
wallet.save()
|
wallet.save()
|
||||||
print "Your wallet generation seed is: " + wallet.seed
|
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 "Please keep it in a safe place; if you lose it, you will not be able to restore your wallet."
|
||||||
|
|||||||
@@ -270,6 +270,7 @@ class Wallet:
|
|||||||
self.banner = ''
|
self.banner = ''
|
||||||
self.up_to_date_event = threading.Event()
|
self.up_to_date_event = threading.Event()
|
||||||
self.up_to_date_event.clear()
|
self.up_to_date_event.clear()
|
||||||
|
self.interface_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
def set_server(self, host, port):
|
def set_server(self, host, port):
|
||||||
@@ -316,11 +317,6 @@ class Wallet:
|
|||||||
# encrypt
|
# encrypt
|
||||||
self.seed = self.pw_encode( seed, password )
|
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):
|
def init_mpk(self,seed):
|
||||||
# public key
|
# public key
|
||||||
@@ -440,7 +436,7 @@ class Wallet:
|
|||||||
raise BaseException("Bad signature")
|
raise BaseException("Bad signature")
|
||||||
|
|
||||||
|
|
||||||
def create_new_address_without_history(self, for_change):
|
def create_new_address(self, for_change):
|
||||||
""" Publickey(type,n) = Master_public_key + H(n|S|type)*point """
|
""" Publickey(type,n) = Master_public_key + H(n|S|type)*point """
|
||||||
curve = SECP256k1
|
curve = SECP256k1
|
||||||
n = len(self.change_addresses) if for_change else len(self.addresses)
|
n = len(self.change_addresses) if for_change else len(self.addresses)
|
||||||
@@ -460,48 +456,38 @@ class Wallet:
|
|||||||
return address
|
return address
|
||||||
|
|
||||||
|
|
||||||
def create_new_address(self, bool):
|
|
||||||
address = self.create_new_address_without_history(bool)
|
|
||||||
self.interface.subscribe([address])
|
|
||||||
return address
|
|
||||||
|
|
||||||
|
|
||||||
def synchronize(self):
|
def synchronize(self):
|
||||||
if not self.master_public_key:
|
if not self.master_public_key:
|
||||||
return False
|
return []
|
||||||
|
|
||||||
is_new = False
|
new_addresses = []
|
||||||
while True:
|
while True:
|
||||||
if self.change_addresses == []:
|
if self.change_addresses == []:
|
||||||
self.create_new_address(True)
|
new_addresses.append( self.create_new_address(True) )
|
||||||
is_new = True
|
|
||||||
continue
|
continue
|
||||||
a = self.change_addresses[-1]
|
a = self.change_addresses[-1]
|
||||||
if self.history.get(a):
|
if self.history.get(a):
|
||||||
self.create_new_address(True)
|
new_addresses.append( self.create_new_address(True) )
|
||||||
is_new = True
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
n = self.gap_limit
|
n = self.gap_limit
|
||||||
while True:
|
while True:
|
||||||
if len(self.addresses) < n:
|
if len(self.addresses) < n:
|
||||||
self.create_new_address(False)
|
new_addresses.append( self.create_new_address(False) )
|
||||||
is_new = True
|
|
||||||
continue
|
continue
|
||||||
if map( lambda a: self.history.get(a), self.addresses[-n:] ) == n*[[]]:
|
if map( lambda a: self.history.get(a), self.addresses[-n:] ) == n*[[]]:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
self.create_new_address(False)
|
new_addresses.append( self.create_new_address(False) )
|
||||||
is_new = True
|
|
||||||
|
|
||||||
if self.remote_url:
|
if self.remote_url:
|
||||||
num = self.get_remote_number()
|
num = self.get_remote_number()
|
||||||
while len(self.addresses)<num:
|
while len(self.addresses)<num:
|
||||||
self.create_new_address(False)
|
new_addresses.append( self.create_new_address(False) )
|
||||||
is_new = True
|
|
||||||
|
|
||||||
return is_new
|
return new_addresses
|
||||||
|
|
||||||
|
|
||||||
def get_remote_number(self):
|
def get_remote_number(self):
|
||||||
@@ -601,17 +587,6 @@ class Wallet:
|
|||||||
#self.interface = interface.start_interface(self)
|
#self.interface = interface.start_interface(self)
|
||||||
|
|
||||||
|
|
||||||
def get_new_address(self):
|
|
||||||
n = 0
|
|
||||||
for addr in self.addresses[-self.gap_limit:]:
|
|
||||||
if not self.history.get(addr):
|
|
||||||
n = n + 1
|
|
||||||
if n < self.gap_limit:
|
|
||||||
new_address = self.create_new_address(False)
|
|
||||||
self.history[new_address] = [] #get from server
|
|
||||||
return True, new_address
|
|
||||||
else:
|
|
||||||
return False, "The last %d addresses in your list have never been used. You should use them first, or increase the allowed gap size in your preferences. "%self.gap_limit
|
|
||||||
|
|
||||||
def get_addr_balance(self, addr):
|
def get_addr_balance(self, addr):
|
||||||
if self.is_mine(addr):
|
if self.is_mine(addr):
|
||||||
@@ -986,8 +961,9 @@ class Wallet:
|
|||||||
def run(self):
|
def run(self):
|
||||||
while self.interface.is_connected:
|
while self.interface.is_connected:
|
||||||
# the interface should use an input queue for requests so that we don't care about synchronous
|
# the interface should use an input queue for requests so that we don't care about synchronous
|
||||||
is_new = self.synchronize() # in synchronous mode, this puts new responses in the queue
|
new_addresses = self.synchronize() # in synchronous mode, this puts new responses in the queue
|
||||||
if self.interface.is_up_to_date() and not is_new:
|
self.interface.subscribe(new_addresses)
|
||||||
|
if self.interface.is_up_to_date() and not new_addresses:
|
||||||
self.up_to_date = True
|
self.up_to_date = True
|
||||||
self.up_to_date_event.set()
|
self.up_to_date_event.set()
|
||||||
else:
|
else:
|
||||||
@@ -1018,3 +994,5 @@ class Wallet:
|
|||||||
version = self.electrum_version
|
version = self.electrum_version
|
||||||
self.interface.start_session(addresses, version)
|
self.interface.start_session(addresses, version)
|
||||||
print "Starting new session: %s:%d"%(self.host,self.port)
|
print "Starting new session: %s:%d"%(self.host,self.port)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user