mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 01:11:35 +00:00
bugfix: add pubkey to PendingAccount, to be able to spend from it
This commit is contained in:
parent
5ee4a87f29
commit
18d16ba82c
2 changed files with 28 additions and 20 deletions
|
@ -96,7 +96,9 @@ class Account(object):
|
||||||
|
|
||||||
class PendingAccount(Account):
|
class PendingAccount(Account):
|
||||||
def __init__(self, v):
|
def __init__(self, v):
|
||||||
self.pending_address = v['pending']
|
self.pending_address = v['address']
|
||||||
|
self.change_pubkeys = []
|
||||||
|
self.receiving_pubkeys = [ v['pubkey'] ]
|
||||||
|
|
||||||
def synchronize(self, wallet):
|
def synchronize(self, wallet):
|
||||||
return
|
return
|
||||||
|
@ -108,7 +110,7 @@ class PendingAccount(Account):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
return {'pending':self.pending_address }
|
return {'pending':True, 'address':self.pending_address, 'pubkey':self.receiving_pubkeys[0] }
|
||||||
|
|
||||||
def get_name(self, k):
|
def get_name(self, k):
|
||||||
return _('Pending account')
|
return _('Pending account')
|
||||||
|
@ -119,6 +121,9 @@ class PendingAccount(Account):
|
||||||
def get_type(self):
|
def get_type(self):
|
||||||
return _('pending')
|
return _('pending')
|
||||||
|
|
||||||
|
def get_xpubkeys(self, for_change, n):
|
||||||
|
return self.get_pubkeys(for_change, n)
|
||||||
|
|
||||||
class ImportedAccount(Account):
|
class ImportedAccount(Account):
|
||||||
def __init__(self, d):
|
def __init__(self, d):
|
||||||
self.keypairs = d['imported']
|
self.keypairs = d['imported']
|
||||||
|
@ -285,8 +290,8 @@ class BIP32_Account(Account):
|
||||||
|
|
||||||
def first_address(self):
|
def first_address(self):
|
||||||
pubkeys = self.derive_pubkeys(0, 0)
|
pubkeys = self.derive_pubkeys(0, 0)
|
||||||
address = self.pubkeys_to_address(pubkeys)
|
addr = self.pubkeys_to_address(pubkeys)
|
||||||
return address
|
return addr, pubkeys
|
||||||
|
|
||||||
def get_master_pubkeys(self):
|
def get_master_pubkeys(self):
|
||||||
return [self.xpub]
|
return [self.xpub]
|
||||||
|
|
|
@ -253,7 +253,10 @@ class Abstract_Wallet(object):
|
||||||
elif v.get('xpub'):
|
elif v.get('xpub'):
|
||||||
self.accounts[k] = BIP32_Account(v)
|
self.accounts[k] = BIP32_Account(v)
|
||||||
elif v.get('pending'):
|
elif v.get('pending'):
|
||||||
self.accounts[k] = PendingAccount(v)
|
try:
|
||||||
|
self.accounts[k] = PendingAccount(v)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
print_error("cannot load account", v)
|
print_error("cannot load account", v)
|
||||||
|
|
||||||
|
@ -717,7 +720,7 @@ class Abstract_Wallet(object):
|
||||||
# send change to one of the accounts involved in the tx
|
# send change to one of the accounts involved in the tx
|
||||||
address = inputs[0].get('address')
|
address = inputs[0].get('address')
|
||||||
account, _ = self.get_address_index(address)
|
account, _ = self.get_address_index(address)
|
||||||
if not self.use_change or account == IMPORTED_ACCOUNT:
|
if not self.use_change or not self.accounts[account].has_change():
|
||||||
change_addr = address
|
change_addr = address
|
||||||
else:
|
else:
|
||||||
change_addr = self.accounts[account].get_addresses(1)[-self.gap_limit_for_change]
|
change_addr = self.accounts[account].get_addresses(1)[-self.gap_limit_for_change]
|
||||||
|
@ -1363,7 +1366,7 @@ class BIP32_Simple_Wallet(BIP32_Wallet):
|
||||||
class BIP32_HD_Wallet(BIP32_Wallet):
|
class BIP32_HD_Wallet(BIP32_Wallet):
|
||||||
# wallet that can create accounts
|
# wallet that can create accounts
|
||||||
def __init__(self, storage):
|
def __init__(self, storage):
|
||||||
self.next_account = storage.get('next_account', None)
|
self.next_account = storage.get('next_account2', None)
|
||||||
BIP32_Wallet.__init__(self, storage)
|
BIP32_Wallet.__init__(self, storage)
|
||||||
|
|
||||||
def can_create_accounts(self):
|
def can_create_accounts(self):
|
||||||
|
@ -1372,14 +1375,14 @@ class BIP32_HD_Wallet(BIP32_Wallet):
|
||||||
def addresses(self, b=True):
|
def addresses(self, b=True):
|
||||||
l = BIP32_Wallet.addresses(self, b)
|
l = BIP32_Wallet.addresses(self, b)
|
||||||
if self.next_account:
|
if self.next_account:
|
||||||
next_address = self.next_account[2]
|
_, _, _, next_address = self.next_account
|
||||||
if next_address not in l:
|
if next_address not in l:
|
||||||
l.append(next_address)
|
l.append(next_address)
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def get_address_index(self, address):
|
def get_address_index(self, address):
|
||||||
if self.next_account:
|
if self.next_account:
|
||||||
next_id, next_xpub, next_address = self.next_account
|
next_id, next_xpub, next_pubkey, next_address = self.next_account
|
||||||
if address == next_address:
|
if address == next_address:
|
||||||
return next_id, (0,0)
|
return next_id, (0,0)
|
||||||
return BIP32_Wallet.get_address_index(self, address)
|
return BIP32_Wallet.get_address_index(self, address)
|
||||||
|
@ -1406,9 +1409,9 @@ class BIP32_HD_Wallet(BIP32_Wallet):
|
||||||
if xprv:
|
if xprv:
|
||||||
self.add_master_private_key(derivation, xprv, password)
|
self.add_master_private_key(derivation, xprv, password)
|
||||||
account = BIP32_Account({'xpub':xpub})
|
account = BIP32_Account({'xpub':xpub})
|
||||||
addr = account.first_address()
|
addr, pubkey = account.first_address()
|
||||||
self.add_address(addr)
|
self.add_address(addr)
|
||||||
return account_id, xpub, addr
|
return account_id, xpub, pubkey, addr
|
||||||
|
|
||||||
def create_main_account(self, password):
|
def create_main_account(self, password):
|
||||||
# First check the password is valid (this raises if it isn't).
|
# First check the password is valid (this raises if it isn't).
|
||||||
|
@ -1417,13 +1420,13 @@ class BIP32_HD_Wallet(BIP32_Wallet):
|
||||||
self.create_account('Main account', password)
|
self.create_account('Main account', password)
|
||||||
|
|
||||||
def create_account(self, name, password):
|
def create_account(self, name, password):
|
||||||
account_id, xpub, addr = self.get_next_account(password)
|
account_id, xpub, _, _ = self.get_next_account(password)
|
||||||
account = BIP32_Account({'xpub':xpub})
|
account = BIP32_Account({'xpub':xpub})
|
||||||
self.add_account(account_id, account)
|
self.add_account(account_id, account)
|
||||||
self.set_label(account_id, name)
|
self.set_label(account_id, name)
|
||||||
# add address of the next account
|
# add address of the next account
|
||||||
self.next_account = self.get_next_account(password)
|
self.next_account = self.get_next_account(password)
|
||||||
self.storage.put('next_account', self.next_account)
|
self.storage.put('next_account2', self.next_account)
|
||||||
|
|
||||||
def account_is_pending(self, k):
|
def account_is_pending(self, k):
|
||||||
return type(self.accounts.get(k)) == PendingAccount
|
return type(self.accounts.get(k)) == PendingAccount
|
||||||
|
@ -1436,11 +1439,11 @@ class BIP32_HD_Wallet(BIP32_Wallet):
|
||||||
def create_pending_account(self, name, password):
|
def create_pending_account(self, name, password):
|
||||||
if self.next_account is None:
|
if self.next_account is None:
|
||||||
self.next_account = self.get_next_account(password)
|
self.next_account = self.get_next_account(password)
|
||||||
self.storage.put('next_account', self.next_account)
|
self.storage.put('next_account2', self.next_account)
|
||||||
next_id, next_xpub, next_address = self.next_account
|
next_id, next_xpub, next_pubkey, next_address = self.next_account
|
||||||
if name:
|
if name:
|
||||||
self.set_label(next_id, name)
|
self.set_label(next_id, name)
|
||||||
self.accounts[next_id] = PendingAccount({'pending':next_address})
|
self.accounts[next_id] = PendingAccount({'pending':True, 'address':next_address, 'pubkey':next_pubkey})
|
||||||
self.save_accounts()
|
self.save_accounts()
|
||||||
|
|
||||||
def synchronize(self):
|
def synchronize(self):
|
||||||
|
@ -1449,21 +1452,21 @@ class BIP32_HD_Wallet(BIP32_Wallet):
|
||||||
|
|
||||||
if self.next_account is None and not self.use_encryption:
|
if self.next_account is None and not self.use_encryption:
|
||||||
self.next_account = self.get_next_account(None)
|
self.next_account = self.get_next_account(None)
|
||||||
self.storage.put('next_account', self.next_account)
|
self.storage.put('next_account2', self.next_account)
|
||||||
|
|
||||||
# check pending account
|
# check pending account
|
||||||
if self.next_account is not None:
|
if self.next_account is not None:
|
||||||
next_id, next_xpub, next_address = self.next_account
|
next_id, next_xpub, next_pubkey, next_address = self.next_account
|
||||||
if self.address_is_old(next_address):
|
if self.address_is_old(next_address):
|
||||||
print_error("creating account", next_id)
|
print_error("creating account", next_id)
|
||||||
self.add_account(next_id, BIP32_Account({'xpub':next_xpub}))
|
self.add_account(next_id, BIP32_Account({'xpub':next_xpub}))
|
||||||
# here the user should get a notification
|
# here the user should get a notification
|
||||||
self.next_account = None
|
self.next_account = None
|
||||||
self.storage.put('next_account', self.next_account)
|
self.storage.put('next_account2', self.next_account)
|
||||||
elif self.history.get(next_address, []):
|
elif self.history.get(next_address, []):
|
||||||
if next_id not in self.accounts:
|
if next_id not in self.accounts:
|
||||||
print_error("create pending account", next_id)
|
print_error("create pending account", next_id)
|
||||||
self.accounts[next_id] = PendingAccount({'pending':next_address})
|
self.accounts[next_id] = PendingAccount({'pending':True, 'address':next_address, 'pubkey':next_pubkey})
|
||||||
self.save_accounts()
|
self.save_accounts()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue