Browse Source

split create_new_address, so that get_new_address can be used without the context of a wallet

283
thomasv 12 years ago
parent
commit
287c7fc643
  1. 17
      lib/wallet.py

17
lib/wallet.py

@ -531,20 +531,23 @@ class Wallet:
def create_new_address(self, for_change): def create_new_address(self, for_change):
n = len(self.change_addresses) if for_change else len(self.addresses)
address = self.get_new_address(n, for_change)
if for_change:
self.change_addresses.append(address)
else:
self.addresses.append(address)
self.history[address] = []
return address
def get_new_address(self, n, 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)
z = self.get_sequence(n, for_change) z = self.get_sequence(n, for_change)
master_public_key = ecdsa.VerifyingKey.from_string( self.master_public_key, curve = SECP256k1 ) master_public_key = ecdsa.VerifyingKey.from_string( self.master_public_key, curve = SECP256k1 )
pubkey_point = master_public_key.pubkey.point + z*curve.generator pubkey_point = master_public_key.pubkey.point + z*curve.generator
public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 ) public_key2 = ecdsa.VerifyingKey.from_public_point( pubkey_point, curve = SECP256k1 )
address = public_key_to_bc_address( '04'.decode('hex') + public_key2.to_string() ) address = public_key_to_bc_address( '04'.decode('hex') + public_key2.to_string() )
if for_change:
self.change_addresses.append(address)
else:
self.addresses.append(address)
self.history[address] = []
print address print address
return address return address

Loading…
Cancel
Save