imported addresses
This commit is contained in:
parent
0b31c2dd1e
commit
29ee4d5a28
@ -248,6 +248,8 @@ class Wallet:
|
|||||||
|
|
||||||
self.init_path(wallet_path)
|
self.init_path(wallet_path)
|
||||||
|
|
||||||
|
self.imported_addresses = {}
|
||||||
|
|
||||||
|
|
||||||
def init_path(self, wallet_path):
|
def init_path(self, wallet_path):
|
||||||
|
|
||||||
@ -281,7 +283,7 @@ class Wallet:
|
|||||||
self.master_public_key = master_private_key.get_verifying_key().to_string()
|
self.master_public_key = master_private_key.get_verifying_key().to_string()
|
||||||
|
|
||||||
def all_addresses(self):
|
def all_addresses(self):
|
||||||
return self.addresses + self.change_addresses
|
return self.addresses + self.change_addresses + self.imported_addresses.keys()
|
||||||
|
|
||||||
def is_mine(self, address):
|
def is_mine(self, address):
|
||||||
return address in self.all_addresses()
|
return address in self.all_addresses()
|
||||||
@ -306,26 +308,30 @@ class Wallet:
|
|||||||
|
|
||||||
def get_private_key2(self, address, password):
|
def get_private_key2(self, address, password):
|
||||||
""" Privatekey(type,n) = Master_private_key + H(n|S|type) """
|
""" Privatekey(type,n) = Master_private_key + H(n|S|type) """
|
||||||
if address in self.addresses:
|
if address in self.imported_addresses.keys():
|
||||||
n = self.addresses.index(address)
|
b = ASecretToSecret( self.imported_addresses[address] )
|
||||||
for_change = False
|
secexp = int( b.encode('hex'), 16)
|
||||||
elif address in self.change_addresses:
|
private_key = ecdsa.SigningKey.from_secret_exponent( secexp, curve=SECP256k1 )
|
||||||
n = self.change_addresses.index(address)
|
|
||||||
for_change = True
|
|
||||||
else:
|
else:
|
||||||
raise BaseException("unknown address")
|
if address in self.addresses:
|
||||||
|
n = self.addresses.index(address)
|
||||||
|
for_change = False
|
||||||
|
elif address in self.change_addresses:
|
||||||
|
n = self.change_addresses.index(address)
|
||||||
|
for_change = True
|
||||||
|
else:
|
||||||
|
raise BaseException("unknown address")
|
||||||
|
seed = self.pw_decode( self.seed, password)
|
||||||
|
secexp = self.stretch_key(seed)
|
||||||
|
order = generator_secp256k1.order()
|
||||||
|
privkey_number = ( secexp + self.get_sequence(n,for_change) ) % order
|
||||||
|
private_key = ecdsa.SigningKey.from_secret_exponent( privkey_number, curve = SECP256k1 )
|
||||||
|
|
||||||
seed = self.pw_decode( self.seed, password)
|
|
||||||
secexp = self.stretch_key(seed)
|
|
||||||
order = generator_secp256k1.order()
|
|
||||||
privkey_number = ( secexp + self.get_sequence(n,for_change) ) % order
|
|
||||||
private_key = ecdsa.SigningKey.from_secret_exponent( privkey_number, curve = SECP256k1 )
|
|
||||||
# sanity check
|
# sanity check
|
||||||
#public_key = private_key.get_verifying_key()
|
public_key = private_key.get_verifying_key()
|
||||||
#assert address == public_key_to_bc_address( '04'.decode('hex') + public_key.to_string() )
|
assert address == public_key_to_bc_address( '04'.decode('hex') + public_key.to_string() )
|
||||||
return private_key
|
return private_key
|
||||||
|
|
||||||
|
|
||||||
def create_new_address2(self, for_change):
|
def create_new_address2(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
|
||||||
@ -694,7 +700,7 @@ if __name__ == '__main__':
|
|||||||
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
|
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
|
||||||
parser.add_option("-b", "--balance", action="store_true", dest="show_balance", default=False, help="show the balance at listed addresses")
|
parser.add_option("-b", "--balance", action="store_true", dest="show_balance", default=False, help="show the balance at listed addresses")
|
||||||
parser.add_option("-k", "--keys",action="store_true", dest="show_keys",default=False, help="show the private keys of listed addresses")
|
parser.add_option("-k", "--keys",action="store_true", dest="show_keys",default=False, help="show the private keys of listed addresses")
|
||||||
parser.add_option("-f", "--fee", dest="tx_fee", default=0.005, help="set tx fee")
|
parser.add_option("-f", "--fee", dest="tx_fee", default="0.005", help="set tx fee")
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
try:
|
try:
|
||||||
cmd = args[0]
|
cmd = args[0]
|
||||||
@ -769,7 +775,8 @@ if __name__ == '__main__':
|
|||||||
to_address = args[1]
|
to_address = args[1]
|
||||||
amount = int( 100000000 * Decimal(args[2]) )
|
amount = int( 100000000 * Decimal(args[2]) )
|
||||||
label = ' '.join(args[3:])
|
label = ' '.join(args[3:])
|
||||||
if options.tx_fee: options.tx_fee = int( 100000000 * Decimal(options.tx_fee) )
|
if options.tx_fee:
|
||||||
|
options.tx_fee = int( 100000000 * Decimal(options.tx_fee) )
|
||||||
except:
|
except:
|
||||||
firstarg = cmd
|
firstarg = cmd
|
||||||
cmd = 'help'
|
cmd = 'help'
|
||||||
@ -842,7 +849,7 @@ if __name__ == '__main__':
|
|||||||
print addr, " ", wallet.labels.get(addr)
|
print addr, " ", wallet.labels.get(addr)
|
||||||
|
|
||||||
elif cmd in [ 'addresses']:
|
elif cmd in [ 'addresses']:
|
||||||
for addr in wallet.addresses:
|
for addr in wallet.all_addresses():
|
||||||
if options.show_all or not wallet.is_change(addr):
|
if options.show_all or not wallet.is_change(addr):
|
||||||
label = wallet.labels.get(addr) if not wallet.is_change(addr) else "[change]"
|
label = wallet.labels.get(addr) if not wallet.is_change(addr) else "[change]"
|
||||||
if label is None: label = ''
|
if label is None: label = ''
|
||||||
@ -892,12 +899,17 @@ if __name__ == '__main__':
|
|||||||
to_address = k
|
to_address = k
|
||||||
print "alias", to_address
|
print "alias", to_address
|
||||||
break
|
break
|
||||||
r, h = wallet.mktx( to_address, amount, label, password, fee = options.tx_fee )
|
try:
|
||||||
if r and cmd=='payto':
|
tx = wallet.mktx( to_address, amount, label, password, fee = options.tx_fee )
|
||||||
|
except BaseException, e:
|
||||||
|
print e
|
||||||
|
tx = None
|
||||||
|
|
||||||
|
if tx and cmd=='payto':
|
||||||
r, h = wallet.sendtx( tx )
|
r, h = wallet.sendtx( tx )
|
||||||
print h
|
print h
|
||||||
else:
|
else:
|
||||||
print h
|
print tx
|
||||||
|
|
||||||
elif cmd == 'sendtx':
|
elif cmd == 'sendtx':
|
||||||
tx = args[1]
|
tx = args[1]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user