mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
move get_keyID to accounts
This commit is contained in:
parent
5c31263848
commit
df540cb241
3 changed files with 30 additions and 30 deletions
|
@ -122,6 +122,10 @@ class OldAccount(Account):
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return _('Old Electrum format')
|
return _('Old Electrum format')
|
||||||
|
|
||||||
|
def get_keyID(self, sequence):
|
||||||
|
a, b = sequence
|
||||||
|
return 'old(%s,%d,%d)'%(self.mpk,a,b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BIP32_Account(Account):
|
class BIP32_Account(Account):
|
||||||
|
@ -160,7 +164,10 @@ class BIP32_Account(Account):
|
||||||
|
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return _('Standard 1 of 1')
|
return _('Standard 1 of 1')
|
||||||
#acctype = 'multisig 2 of 2' if len(roots) == 2 else 'multisig 2 of 3' if len(roots) == 3 else 'standard 1 of 1'
|
|
||||||
|
def get_keyID(self, sequence):
|
||||||
|
s = '/' + '/'.join( map(lambda x:str(x), sequence) )
|
||||||
|
return '&'.join( map(lambda x: 'bip32(%s,%s)'%(x, s), self.get_master_pubkeys() ) )
|
||||||
|
|
||||||
|
|
||||||
class BIP32_Account_2of2(BIP32_Account):
|
class BIP32_Account_2of2(BIP32_Account):
|
||||||
|
@ -182,7 +189,7 @@ class BIP32_Account_2of2(BIP32_Account):
|
||||||
|
|
||||||
def redeem_script(self, sequence):
|
def redeem_script(self, sequence):
|
||||||
pubkeys = self.get_pubkeys(sequence)
|
pubkeys = self.get_pubkeys(sequence)
|
||||||
return Transaction.multisig_script(pubkeys, len(pubkeys))
|
return Transaction.multisig_script(pubkeys, 2)
|
||||||
|
|
||||||
def get_address(self, for_change, n):
|
def get_address(self, for_change, n):
|
||||||
address = hash_160_to_bc_address(hash_160(self.redeem_script((for_change, n)).decode('hex')), 5)
|
address = hash_160_to_bc_address(hash_160(self.redeem_script((for_change, n)).decode('hex')), 5)
|
||||||
|
@ -226,3 +233,4 @@ class BIP32_Account_2of3(BIP32_Account_2of2):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -517,6 +517,8 @@ class Transaction:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tx_for_sig = self.serialize( self.inputs, self.outputs, for_sig = i )
|
tx_for_sig = self.serialize( self.inputs, self.outputs, for_sig = i )
|
||||||
|
|
||||||
|
print_error("redeem pubkeys input %d"%i, redeem_pubkeys)
|
||||||
for pubkey in redeem_pubkeys:
|
for pubkey in redeem_pubkeys:
|
||||||
# check if we have the corresponding private key
|
# check if we have the corresponding private key
|
||||||
if pubkey in keypairs.keys():
|
if pubkey in keypairs.keys():
|
||||||
|
@ -535,6 +537,7 @@ class Transaction:
|
||||||
txin["signatures"] = signatures
|
txin["signatures"] = signatures
|
||||||
is_complete = is_complete and len(signatures) == num
|
is_complete = is_complete and len(signatures) == num
|
||||||
|
|
||||||
|
print_error("is_complete", is_complete)
|
||||||
self.is_complete = is_complete
|
self.is_complete = is_complete
|
||||||
self.raw = self.serialize( self.inputs, self.outputs )
|
self.raw = self.serialize( self.inputs, self.outputs )
|
||||||
|
|
||||||
|
|
|
@ -570,14 +570,6 @@ class NewWallet:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_keyID(self, account, sequence):
|
|
||||||
rs = self.rebase_sequence(account, sequence)
|
|
||||||
dd = []
|
|
||||||
for root, public_sequence in rs:
|
|
||||||
xpub = self.master_public_keys[root]
|
|
||||||
s = '/' + '/'.join( map(lambda x:str(x), public_sequence) )
|
|
||||||
dd.append( 'bip32(%s,%s)'%(xpub, s) )
|
|
||||||
return '&'.join(dd)
|
|
||||||
|
|
||||||
|
|
||||||
def get_seed(self, password):
|
def get_seed(self, password):
|
||||||
|
@ -596,19 +588,21 @@ class NewWallet:
|
||||||
|
|
||||||
# first check the provided password
|
# first check the provided password
|
||||||
seed = self.get_seed(password)
|
seed = self.get_seed(password)
|
||||||
|
|
||||||
out = []
|
out = []
|
||||||
if address in self.imported_keys.keys():
|
if address in self.imported_keys.keys():
|
||||||
out.append( pw_decode( self.imported_keys[address], password ) )
|
out.append( pw_decode( self.imported_keys[address], password ) )
|
||||||
else:
|
else:
|
||||||
account_id, sequence = self.get_address_index(address)
|
account_id, sequence = self.get_address_index(address)
|
||||||
#rs = self.rebase_sequence( account, sequence)
|
account = self.accounts[account_id]
|
||||||
rs = [(account_id, sequence)]
|
xpubs = account.get_master_pubkeys()
|
||||||
for root, public_sequence in rs:
|
roots = [k for k, v in self.master_public_keys.iteritems() if v in xpubs]
|
||||||
|
for root in roots:
|
||||||
xpriv = self.get_master_private_key(root, password)
|
xpriv = self.get_master_private_key(root, password)
|
||||||
if not xpriv: continue
|
if not xpriv:
|
||||||
|
continue
|
||||||
_, _, _, c, k = deserialize_xkey(xpriv)
|
_, _, _, c, k = deserialize_xkey(xpriv)
|
||||||
pk = bip32_private_key( public_sequence, k, c )
|
pk = bip32_private_key( sequence, k, c )
|
||||||
out.append(pk)
|
out.append(pk)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
@ -636,12 +630,11 @@ class NewWallet:
|
||||||
if keyid:
|
if keyid:
|
||||||
roots = []
|
roots = []
|
||||||
for s in keyid.split('&'):
|
for s in keyid.split('&'):
|
||||||
m = re.match("bip32\(([0-9a-f]+),([0-9a-f]+),(/\d+/\d+/\d+)", s)
|
m = re.match("bip32\((.*),(/\d+/\d+)\)", s)
|
||||||
if not m: continue
|
if not m: continue
|
||||||
c = m.group(1)
|
xpub = m.group(1)
|
||||||
K = m.group(2)
|
sequence = m.group(2)
|
||||||
sequence = m.group(3)
|
root = self.find_root_by_master_key(xpub)
|
||||||
root = self.find_root_by_master_key(c,K)
|
|
||||||
if not root: continue
|
if not root: continue
|
||||||
sequence = map(lambda x:int(x), sequence.strip('/').split('/'))
|
sequence = map(lambda x:int(x), sequence.strip('/').split('/'))
|
||||||
root = root + '%d'%sequence[0]
|
root = root + '%d'%sequence[0]
|
||||||
|
@ -1236,13 +1229,14 @@ class NewWallet:
|
||||||
address = txin['address']
|
address = txin['address']
|
||||||
if address in self.imported_keys.keys():
|
if address in self.imported_keys.keys():
|
||||||
continue
|
continue
|
||||||
account, sequence = self.get_address_index(address)
|
account_id, sequence = self.get_address_index(address)
|
||||||
txin['KeyID'] = self.get_keyID(account, sequence)
|
account = self.accounts[account_id]
|
||||||
redeemScript = self.accounts[account].redeem_script(sequence)
|
txin['KeyID'] = account.get_keyID(sequence)
|
||||||
|
redeemScript = account.redeem_script(sequence)
|
||||||
if redeemScript:
|
if redeemScript:
|
||||||
txin['redeemScript'] = redeemScript
|
txin['redeemScript'] = redeemScript
|
||||||
else:
|
else:
|
||||||
txin['redeemPubkey'] = self.accounts[account].get_pubkey(*sequence)
|
txin['redeemPubkey'] = account.get_pubkey(*sequence)
|
||||||
|
|
||||||
|
|
||||||
def sign_transaction(self, tx, keypairs, password):
|
def sign_transaction(self, tx, keypairs, password):
|
||||||
|
@ -1746,11 +1740,6 @@ class OldWallet(NewWallet):
|
||||||
out.append(pk)
|
out.append(pk)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def get_keyID(self, account, sequence):
|
|
||||||
a, b = sequence
|
|
||||||
mpk = self.storage.get('master_public_key')
|
|
||||||
return 'old(%s,%d,%d)'%(mpk,a,b)
|
|
||||||
|
|
||||||
def check_pending_accounts(self):
|
def check_pending_accounts(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue