mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 18:25:21 +00:00
new class: Imported_Wallet
This commit is contained in:
parent
3ae48a1819
commit
582fb76e9e
3 changed files with 61 additions and 3 deletions
|
@ -4,6 +4,7 @@ import PyQt4.QtCore as QtCore
|
|||
|
||||
from electrum.i18n import _
|
||||
from electrum import Wallet, Wallet_2of2, Wallet_2of3
|
||||
import electrum.bitcoin as bitcoin
|
||||
|
||||
import seed_dialog
|
||||
from network_dialog import NetworkDialog
|
||||
|
@ -92,7 +93,7 @@ class InstallWizard(QDialog):
|
|||
|
||||
def is_seed(self, seed_e):
|
||||
text = self.get_seed_text(seed_e)
|
||||
return Wallet.is_seed(text) or Wallet.is_mpk(text)
|
||||
return Wallet.is_seed(text) or Wallet.is_mpk(text) or Wallet.is_address(text) or Wallet.is_private_key(text)
|
||||
|
||||
|
||||
def enter_seed_dialog(self, is_restore, sid):
|
||||
|
@ -372,6 +373,10 @@ class InstallWizard(QDialog):
|
|||
wallet.create_accounts(password)
|
||||
elif Wallet.is_mpk(text):
|
||||
wallet = Wallet.from_mpk(text, self.storage)
|
||||
elif Wallet.is_address(text):
|
||||
wallet = Wallet.from_address(text, self.storage)
|
||||
elif Wallet.is_private_key(text):
|
||||
wallet = Wallet.from_private_key(text, self.storage)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
|
|
@ -285,6 +285,10 @@ def address_from_private_key(sec):
|
|||
|
||||
|
||||
def is_valid(addr):
|
||||
return is_address(addr)
|
||||
|
||||
|
||||
def is_address(addr):
|
||||
ADDRESS_RE = re.compile('[1-9A-HJ-NP-Za-km-z]{26,}\\Z')
|
||||
if not ADDRESS_RE.match(addr): return False
|
||||
try:
|
||||
|
@ -294,6 +298,10 @@ def is_valid(addr):
|
|||
return addr == hash_160_to_bc_address(h, addrtype)
|
||||
|
||||
|
||||
def is_private_key(key):
|
||||
return ASecretToSecret(key) is not False
|
||||
|
||||
|
||||
########### end pywallet functions #######################
|
||||
|
||||
try:
|
||||
|
|
|
@ -36,6 +36,7 @@ from bitcoin import *
|
|||
from account import *
|
||||
from transaction import Transaction
|
||||
from plugins import run_hook
|
||||
import bitcoin
|
||||
|
||||
COINBASE_MATURITY = 100
|
||||
DUST_THRESHOLD = 5430
|
||||
|
@ -331,6 +332,8 @@ class NewWallet:
|
|||
self.add_account("m/", account)
|
||||
|
||||
|
||||
|
||||
|
||||
def create_accounts(self, password):
|
||||
seed = pw_decode(self.seed, password)
|
||||
self.create_account('Main account', password)
|
||||
|
@ -1480,6 +1483,17 @@ class NewWallet:
|
|||
|
||||
|
||||
|
||||
class Imported_Wallet(NewWallet):
|
||||
|
||||
def __init__(self, storage):
|
||||
NewWallet.__init__(self, storage)
|
||||
|
||||
def is_watching_only(self):
|
||||
n = self.imported_keys.values()
|
||||
return n == [''] * len(n)
|
||||
|
||||
|
||||
|
||||
class Wallet_2of2(NewWallet):
|
||||
|
||||
def __init__(self, storage):
|
||||
|
@ -1543,7 +1557,6 @@ class Wallet_2of3(Wallet_2of2):
|
|||
|
||||
class WalletSynchronizer(threading.Thread):
|
||||
|
||||
|
||||
def __init__(self, wallet, network):
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = True
|
||||
|
@ -1843,6 +1856,10 @@ class Wallet(object):
|
|||
if storage.get('wallet_type') == '2of3':
|
||||
return Wallet_2of3(storage)
|
||||
|
||||
if storage.file_exists and not storage.get('seed'):
|
||||
# wallet made of imported keys
|
||||
return Imported_Wallet(storage)
|
||||
|
||||
|
||||
if not storage.file_exists:
|
||||
seed_version = NEW_SEED_VERSION if config.get('bip32') is True else OLD_SEED_VERSION
|
||||
|
@ -1891,7 +1908,20 @@ class Wallet(object):
|
|||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
@classmethod
|
||||
def is_address(self, text):
|
||||
for x in text.split():
|
||||
if not bitcoin.is_address(x):
|
||||
return False
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def is_private_key(self, text):
|
||||
for x in text.split():
|
||||
if not bitcoin.is_private_key(x):
|
||||
return False
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def from_seed(self, seed, storage):
|
||||
|
@ -1902,6 +1932,21 @@ class Wallet(object):
|
|||
w = klass(storage)
|
||||
return w
|
||||
|
||||
@classmethod
|
||||
def from_address(self, text, storage):
|
||||
w = Imported_Wallet(storage)
|
||||
for x in text.split():
|
||||
w.imported_keys[x] = ''
|
||||
w.storage.put('imported_keys', w.imported_keys, True)
|
||||
return w
|
||||
|
||||
@classmethod
|
||||
def from_private_key(self, text, storage):
|
||||
w = Imported_Wallet(storage)
|
||||
for x in text.split():
|
||||
w.import_key(x, None)
|
||||
return w
|
||||
|
||||
@classmethod
|
||||
def from_mpk(self, mpk, storage):
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue