|
|
@ -346,7 +346,9 @@ class Abstract_Wallet(AddressSynchronizer): |
|
|
|
|
|
|
|
def export_private_key(self, address, password): |
|
|
|
if self.is_watching_only(): |
|
|
|
return [] |
|
|
|
raise Exception(_("This is a watching-only wallet")) |
|
|
|
if not self.is_mine(address): |
|
|
|
raise Exception(_('Address not in wallet.') + f' {address}') |
|
|
|
index = self.get_address_index(address) |
|
|
|
pk, compressed = self.keystore.get_private_key(index, password) |
|
|
|
txin_type = self.get_txin_type(address) |
|
|
@ -1485,7 +1487,9 @@ class Imported_Wallet(Simple_Wallet): |
|
|
|
return self.db.has_imported_address(address) |
|
|
|
|
|
|
|
def get_address_index(self, address): |
|
|
|
# returns None is address is not mine |
|
|
|
# returns None if address is not mine |
|
|
|
if not is_address(address): |
|
|
|
raise Exception(f"Invalid bitcoin address: {address}") |
|
|
|
return self.get_public_key(address) |
|
|
|
|
|
|
|
def get_public_key(self, address): |
|
|
@ -1677,6 +1681,8 @@ class Deterministic_Wallet(Abstract_Wallet): |
|
|
|
return True |
|
|
|
|
|
|
|
def get_address_index(self, address): |
|
|
|
if not is_address(address): |
|
|
|
raise Exception(f"Invalid bitcoin address: {address}") |
|
|
|
return self.db.get_address_index(address) |
|
|
|
|
|
|
|
def get_master_public_keys(self): |
|
|
@ -1875,7 +1881,7 @@ class Wallet(object): |
|
|
|
raise WalletFileException("Unknown wallet type: " + str(wallet_type)) |
|
|
|
|
|
|
|
|
|
|
|
def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True, segwit=True): |
|
|
|
def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True, segwit=True, gap_limit=None): |
|
|
|
"""Create a new wallet""" |
|
|
|
storage = WalletStorage(path) |
|
|
|
if storage.file_exists(): |
|
|
@ -1886,6 +1892,8 @@ def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True |
|
|
|
k = keystore.from_seed(seed, passphrase) |
|
|
|
storage.put('keystore', k.dump()) |
|
|
|
storage.put('wallet_type', 'standard') |
|
|
|
if gap_limit is not None: |
|
|
|
storage.put('gap_limit', gap_limit) |
|
|
|
wallet = Wallet(storage) |
|
|
|
wallet.update_password(old_pw=None, new_pw=password, encrypt_storage=encrypt_file) |
|
|
|
wallet.synchronize() |
|
|
@ -1896,7 +1904,8 @@ def create_new_wallet(*, path, passphrase=None, password=None, encrypt_file=True |
|
|
|
|
|
|
|
|
|
|
|
def restore_wallet_from_text(text, *, path, network=None, |
|
|
|
passphrase=None, password=None, encrypt_file=True): |
|
|
|
passphrase=None, password=None, encrypt_file=True, |
|
|
|
gap_limit=None): |
|
|
|
"""Restore a wallet from text. Text can be a seed phrase, a master |
|
|
|
public key, a master private key, a list of bitcoin addresses |
|
|
|
or bitcoin private keys.""" |
|
|
@ -1930,6 +1939,8 @@ def restore_wallet_from_text(text, *, path, network=None, |
|
|
|
raise Exception("Seed or key not recognized") |
|
|
|
storage.put('keystore', k.dump()) |
|
|
|
storage.put('wallet_type', 'standard') |
|
|
|
if gap_limit is not None: |
|
|
|
storage.put('gap_limit', gap_limit) |
|
|
|
wallet = Wallet(storage) |
|
|
|
|
|
|
|
assert not storage.file_exists(), "file was created too soon! plaintext keys might have been written to disk" |
|
|
|