def init_storage_from_path(self, path): self.storage = WalletStorage(path) self.basename = self.storage.basename() if not self.storage.file_exists(): self.require_password = False self.message = _('Press Next to create') elif self.storage.is_encrypted(): if not self.storage.is_encrypted_with_user_pw(): raise Exception( "Kivy GUI does not support this type of encrypted wallet files." ) self.pw_check = self.storage.check_password if self.app.password and self.check_password(self.app.password): self.pw = self.app.password # must be set so that it is returned in callback self.require_password = False self.message = _('Press Next to open') else: self.require_password = True self.message = self.enter_pw_message else: # it is a bit wasteful load the wallet here and load it again in main_window, # but that is fine, because we are progressively enforcing storage encryption. db = WalletDB(self.storage.read(), manual_upgrades=False) wallet = Wallet(db, self.storage, config=self.app.electrum_config) self.require_password = wallet.has_password() self.pw_check = wallet.check_password self.message = self.enter_pw_message if self.require_password else _( 'Wallet not encrypted')
def __init__(self, config, network, path): super(BaseWizard, self).__init__() self.config = config self.network = network self.storage = WalletStorage(path) self.wallet = None self.stack = []
def __init__(self, config, daemon, plugins): self.config = config network = daemon.network storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() self.done = 0 self.last_balance = "" set_verbosity(False) self.str_recipient = "" self.str_description = "" self.str_amount = "" self.str_fee = "" self.wallet = Wallet(storage) self.wallet.start_threads(network) self.contacts = StoreDict(self.config, 'contacts') network.register_callback(self.on_network, ['updated', 'banner']) self.commands = [_("[h] - displays this help text"), \ _("[i] - display transaction history"), \ _("[o] - enter payment order"), \ _("[p] - print stored payment order"), \ _("[s] - send stored payment order"), \ _("[r] - show own receipt addresses"), \ _("[c] - display contacts"), \ _("[b] - print server banner"), \ _("[q] - quit") ] self.num_commands = len(self.commands)
class OpenWalletDialog(PasswordDialog): """This dialog will let the user choose another wallet file if they don't remember their the password""" def __init__(self, app, path, callback): self.app = app self.callback = callback PasswordDialog.__init__( self, app, on_success=lambda pw: self.callback(pw, self.storage), on_failure=self.app.stop) self.init_storage_from_path(path) def select_file(self): dirname = os.path.dirname(self.app.electrum_config.get_wallet_path()) d = WalletDialog(dirname, self.init_storage_from_path, self.app.is_wallet_creation_disabled()) d.open() def init_storage_from_path(self, path): self.storage = WalletStorage(path) self.basename = self.storage.basename() if not self.storage.file_exists(): self.require_password = False self.message = _('Press Next to create') elif self.storage.is_encrypted(): if not self.storage.is_encrypted_with_user_pw(): raise Exception( "Kivy GUI does not support this type of encrypted wallet files." ) self.pw_check = self.storage.check_password if self.app.password and self.check_password(self.app.password): self.pw = self.app.password # must be set so that it is returned in callback self.require_password = False self.message = _('Press Next to open') else: self.require_password = True self.message = self.enter_pw_message else: # it is a bit wasteful load the wallet here and load it again in main_window, # but that is fine, because we are progressively enforcing storage encryption. db = WalletDB(self.storage.read(), manual_upgrades=False) wallet = Wallet(db, self.storage, config=self.app.electrum_config) self.require_password = wallet.has_password() self.pw_check = wallet.check_password self.message = self.enter_pw_message if self.require_password else _( 'Wallet not encrypted')
def init_storage_from_path(self, path): self.storage = WalletStorage(path) self.basename = self.storage.basename() if not self.storage.file_exists(): self.require_password = False self.message = _('Press Next to create') elif self.storage.is_encrypted(): if not self.storage.is_encrypted_with_user_pw(): raise Exception( "Kivy GUI does not support this type of encrypted wallet files." ) self.require_password = True self.pw_check = self.storage.check_password self.message = self.enter_pw_message else: # it is a bit wasteful load the wallet here and load it again in main_window, # but that is fine, because we are progressively enforcing storage encryption. wallet = self.app.daemon.load_wallet(path, None) self.require_password = wallet.has_password() self.pw_check = wallet.check_password self.message = self.enter_pw_message if self.require_password else _( 'Wallet not encrypted')
class OpenWalletDialog(PasswordDialog): def __init__(self, app, path, callback): self.app = app self.callback = callback PasswordDialog.__init__( self, app, on_success=lambda pw: self.callback(pw, self.storage), on_failure=self.app.stop) self.init_storage_from_path(path) def select_file(self): dirname = os.path.dirname(self.app.electrum_config.get_wallet_path()) d = WalletDialog(dirname, self.init_storage_from_path) d.open() def init_storage_from_path(self, path): self.storage = WalletStorage(path) self.basename = self.storage.basename() if not self.storage.file_exists(): self.require_password = False self.message = _('Press Next to create') elif self.storage.is_encrypted(): if not self.storage.is_encrypted_with_user_pw(): raise Exception( "Kivy GUI does not support this type of encrypted wallet files." ) self.require_password = True self.pw_check = self.storage.check_password self.message = self.enter_pw_message else: # it is a bit wasteful load the wallet here and load it again in main_window, # but that is fine, because we are progressively enforcing storage encryption. wallet = self.app.daemon.load_wallet(path, None) self.require_password = wallet.has_password() self.pw_check = wallet.check_password self.message = self.enter_pw_message if self.require_password else _( 'Wallet not encrypted')
def __init__(self, config, network): self.network = network self.config = config storage = WalletStorage(self.config.get_wallet_path()) if not storage.file_exists: raise BaseException("Wallet not found") self.wallet = Wallet(storage) self.cmd_runner = Commands(self.config, self.wallet, self.network) host = config.get('rpchost', 'localhost') port = config.get('rpcport', 7777) self.server = SimpleJSONRPCServer((host, port), requestHandler=RequestHandler) self.server.socket.settimeout(1) for cmdname in known_commands: self.server.register_function(getattr(self.cmd_runner, cmdname), cmdname)
def __init__(self, config, network): self.network = network self.config = config storage = WalletStorage(config) if not storage.file_exists: print "Wallet not found. try 'electrum create'" exit() self.done = 0 self.last_balance = "" set_verbosity(False) self.str_recipient = "" self.str_description = "" self.str_amount = "" self.str_fee = "" self.wallet = Wallet(storage) self.wallet.start_threads(network) self.wallet.network.register_callback('updated', self.updated) self.wallet.network.register_callback('connected', self.connected) self.wallet.network.register_callback('disconnected', self.disconnected) self.wallet.network.register_callback('disconnecting', self.disconnecting) self.wallet.network.register_callback('peers', self.peers) self.wallet.network.register_callback('banner', self.print_banner) self.commands = [_("[h] - displays this help text"), \ _("[i] - display transaction history"), \ _("[o] - enter payment order"), \ _("[p] - print stored payment order"), \ _("[s] - send stored payment order"), \ _("[r] - show own receipt addresses"), \ _("[c] - display contacts"), \ _("[b] - print server banner"), \ _("[q] - quit") ] self.num_commands = len(self.commands)
class BaseWizard(object): def __init__(self, config, network, path): super(BaseWizard, self).__init__() self.config = config self.network = network self.storage = WalletStorage(path) self.wallet = None self.stack = [] def run(self, *args): action = args[0] args = args[1:] self.stack.append((action, args)) if not action: return if hasattr(self.wallet, 'plugin') and hasattr(self.wallet.plugin, action): f = getattr(self.wallet.plugin, action) apply(f, (self.wallet, self) + args) elif hasattr(self, action): f = getattr(self, action) apply(f, args) else: raise BaseException("unknown action", action) def get_action(self): if self.storage.file_exists: self.wallet = Wallet(self.storage) action = self.wallet.get_action() else: action = 'new' return action def get_wallet(self): if self.wallet and self.wallet.get_action() is None: return self.wallet def can_go_back(self): return len(self.stack)>1 def go_back(self): if not self.can_go_back(): return self.stack.pop() action, args = self.stack.pop() self.run(action, *args) def new(self): name = os.path.basename(self.storage.path) title = _("Welcome to the Electrum installation wizard.") message = '\n'.join([ _("The wallet '%s' does not exist.") % name, _("What kind of wallet do you want to create?") ]) wallet_kinds = [ ('standard', _("Standard wallet")), ('twofactor', _("Wallet with two-factor authentication")), ('multisig', _("Multi-signature wallet")), ('hardware', _("Hardware wallet")), ] registered_kinds = Wallet.categories() choices = [pair for pair in wallet_kinds if pair[0] in registered_kinds] self.choice_dialog(title = title, message=message, choices=choices, run_next=self.on_wallet_type) def on_wallet_type(self, choice): self.wallet_type = choice if choice == 'standard': action = 'choose_seed' elif choice == 'multisig': action = 'choose_multisig' elif choice == 'hardware': action = 'choose_hw' elif choice == 'twofactor': action = 'choose_seed' self.run(action) def choose_multisig(self): def on_multisig(m, n): self.multisig_type = "%dof%d"%(m, n) self.run('choose_seed') self.multisig_dialog(run_next=on_multisig) def choose_seed(self): title = _('Choose Seed') message = _("Do you want to create a new seed, or to restore a wallet using an existing seed?") if self.wallet_type == 'standard': choices = [ ('create_seed', _('Create a new seed')), ('restore_seed', _('I already have a seed')), ('restore_from_key', _('Import keys')), ] elif self.wallet_type == 'twofactor': choices = [ ('create_2fa', _('Create a new seed')), ('restore_2fa', _('I already have a seed')), ] elif self.wallet_type == 'multisig': choices = [ ('create_seed', _('Create a new seed')), ('restore_seed', _('I already have a seed')), ('restore_from_key', _('I have a master key')), #('choose_hw', _('Cosign with hardware wallet')), ] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.run) def create_2fa(self): self.storage.put('wallet_type', '2fa') self.wallet = Wallet(self.storage) self.run('show_disclaimer') def restore_seed(self): # TODO: return derivation password too self.restore_seed_dialog(run_next=self.add_password, is_valid=Wallet.is_seed) def on_restore(self, text): if is_private_key(text): self.add_password(text) else: self.create_wallet(text, None) def restore_from_key(self): if self.wallet_type == 'standard': v = is_any_key title = _("Import keys") message = ' '.join([ _("To create a watching-only wallet, please enter your master public key (xpub), or a list of FairCoin addresses."), _("To create a spending wallet, please enter a master private key (xprv), or a list of FairCoin private keys.") ]) else: v = is_bip32_key title = _("Master public or private key") message = ' '.join([ _("To create a watching-only wallet, please enter your master public key (xpub)."), _("To create a spending wallet, please enter a master private key (xprv).") ]) self.restore_keys_dialog(title=title, message=message, run_next=self.on_restore, is_valid=v) def restore_2fa(self): self.storage.put('wallet_type', '2fa') self.wallet = Wallet(self.storage) self.wallet.plugin.on_restore_wallet(self.wallet, self) def choose_hw(self): hw_wallet_types, choices = self.plugins.hardware_wallets('create') choices = zip(hw_wallet_types, choices) title = _('Hardware wallet') if choices: msg = _('Select the type of hardware wallet: ') else: msg = ' '.join([ _('No hardware wallet support found on your system.'), _('Please install the relevant libraries (eg python-trezor for Trezor).'), ]) self.choice_dialog(title=title, message=msg, choices=choices, run_next=self.on_hardware) def on_hardware(self, hw_type): self.hw_type = hw_type if self.wallet_type == 'multisig': self.create_hardware_multisig() else: title = _('Hardware wallet') + ' [%s]' % hw_type message = _('Do you have a device, or do you want to restore a wallet using an existing seed?') choices = [ ('create_hardware_wallet', _('I have a device')), ('restore_hardware_wallet', _('Use hardware wallet seed')), ] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.run) def create_hardware_multisig(self): self.storage.put('wallet_type', self.multisig_type) self.wallet = Multisig_Wallet(self.storage) # todo: get the xpub from the plugin self.run('create_wallet', xpub, None) def create_hardware_wallet(self): self.storage.put('wallet_type', self.hw_type) self.wallet = Wallet(self.storage) self.wallet.plugin.on_create_wallet(self.wallet, self) self.terminate() def restore_hardware_wallet(self): self.storage.put('wallet_type', self.wallet_type) self.wallet = Wallet(self.storage) self.wallet.plugin.on_restore_wallet(self.wallet, self) self.terminate() def create_wallet(self, text, password): if self.wallet_type == 'standard': self.wallet = Wallet.from_text(text, password, self.storage) self.run('create_addresses') elif self.wallet_type == 'multisig': self.storage.put('wallet_type', self.multisig_type) self.wallet = Multisig_Wallet(self.storage) self.wallet.add_cosigner('x1/', text, password) self.stack = [] self.run('show_xpub_and_add_cosigners', (password,)) def show_xpub_and_add_cosigners(self, password): xpub = self.wallet.master_public_keys.get('x1/') self.show_xpub_dialog(xpub=xpub, run_next=lambda x: self.run('add_cosigners', password)) def add_cosigners(self, password): i = self.wallet.get_missing_cosigner() self.add_cosigner_dialog(run_next=lambda x: self.on_cosigner(x, password), index=(i-1), is_valid=Wallet.is_xpub) def on_cosigner(self, text, password): i = self.wallet.get_missing_cosigner() try: self.wallet.add_cosigner('x%d/'%i, text, password) except BaseException as e: print "error:" + str(e) i = self.wallet.get_missing_cosigner() if i: self.run('add_cosigners', password) else: self.create_addresses() def create_addresses(self): def task(): self.wallet.create_main_account() self.wallet.synchronize() self.wallet.storage.write() self.terminate() msg = _("Electrum is generating your addresses, please wait.") self.waiting_dialog(task, msg) def create_seed(self): from electrum.wallet import BIP32_Wallet seed = BIP32_Wallet.make_seed() self.show_seed_dialog(run_next=self.confirm_seed, seed_text=seed) def confirm_seed(self, seed): self.confirm_seed_dialog(run_next=self.add_password, is_valid=lambda x: x==seed) def add_password(self, text): f = lambda pw: self.run('create_wallet', text, pw) self.request_password(run_next=f)
class BaseWizard(object): def __init__(self, config, network, path): super(BaseWizard, self).__init__() self.config = config self.network = network self.storage = WalletStorage(path) self.wallet = None self.stack = [] def run(self, *args): action = args[0] args = args[1:] self.stack.append((action, args)) if not action: return if hasattr(self.wallet, 'plugin') and hasattr(self.wallet.plugin, action): f = getattr(self.wallet.plugin, action) apply(f, (self.wallet, self) + args) elif hasattr(self, action): f = getattr(self, action) apply(f, args) else: raise BaseException("unknown action", action) def get_action(self): if self.storage.file_exists: self.wallet = Wallet(self.storage) action = self.wallet.get_action() else: action = 'new' return action def get_wallet(self): if self.wallet and self.wallet.get_action() is None: return self.wallet def can_go_back(self): return len(self.stack)>1 def go_back(self): if not self.can_go_back(): return self.stack.pop() action, args = self.stack.pop() self.run(action, *args) def new(self): name = os.path.basename(self.storage.path) title = _("Welcome to the Electrum installation wizard.") message = '\n'.join([ _("The wallet '%s' does not exist.") % name, _("What kind of wallet do you want to create?") ]) wallet_kinds = [ ('standard', _("Standard wallet")), ('twofactor', _("Wallet with two-factor authentication")), ('multisig', _("Multi-signature wallet")), ('hardware', _("Hardware wallet")), ] registered_kinds = Wallet.categories() choices = [pair for pair in wallet_kinds if pair[0] in registered_kinds] self.choice_dialog(title = title, message=message, choices=choices, run_next=self.on_wallet_type) def on_wallet_type(self, choice): self.wallet_type = choice if choice == 'standard': action = 'choose_seed' elif choice == 'multisig': action = 'choose_multisig' elif choice == 'hardware': action = 'choose_hw' elif choice == 'twofactor': action = 'choose_seed' self.run(action) def choose_multisig(self): def on_multisig(m, n): self.multisig_type = "%dof%d"%(m, n) self.run('choose_seed') self.multisig_dialog(run_next=on_multisig) def choose_seed(self): title = _('Choose Seed') message = _("Do you want to create a new seed, or to restore a wallet using an existing seed?") if self.wallet_type == 'standard': choices = [ ('create_seed', _('Create a new seed')), ('restore_seed', _('I already have a seed')), ('restore_from_key', _('Import keys')), ] elif self.wallet_type == 'twofactor': choices = [ ('create_2fa', _('Create a new seed')), ('restore_2fa', _('I already have a seed')), ] elif self.wallet_type == 'multisig': choices = [ ('create_seed', _('Create a new seed')), ('restore_seed', _('I already have a seed')), ('restore_from_key', _('I have a master key')), #('choose_hw', _('Cosign with hardware wallet')), ] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.run) def create_2fa(self): self.storage.put('wallet_type', '2fa') self.wallet = Wallet(self.storage) self.run('show_disclaimer') def restore_seed(self): # TODO: return derivation password too self.restore_seed_dialog(run_next=self.add_password, is_valid=Wallet.is_seed) def on_restore(self, text): if is_private_key(text): self.add_password(text) else: self.create_wallet(text, None) def restore_from_key(self): if self.wallet_type == 'standard': v = is_any_key title = _("Import keys") message = ' '.join([ _("To create a watching-only wallet, please enter your master public key (xpub), or a list of Bitcoin addresses."), _("To create a spending wallet, please enter a master private key (xprv), or a list of Bitcoin private keys.") ]) else: v = is_bip32_key title = _("Master public or private key") message = ' '.join([ _("To create a watching-only wallet, please enter your master public key (xpub)."), _("To create a spending wallet, please enter a master private key (xprv).") ]) self.restore_keys_dialog(title=title, message=message, run_next=self.on_restore, is_valid=v) def restore_2fa(self): self.storage.put('wallet_type', '2fa') self.wallet = Wallet(self.storage) self.wallet.plugin.on_restore_wallet(self.wallet, self) def choose_hw(self): hw_wallet_types, choices = self.plugins.hardware_wallets('create') choices = zip(hw_wallet_types, choices) title = _('Hardware wallet') if choices: msg = _('Select the type of hardware wallet: ') else: msg = ' '.join([ _('No hardware wallet support found on your system.'), _('Please install the relevant libraries (eg python-trezor for Trezor).'), ]) self.choice_dialog(title=title, message=msg, choices=choices, run_next=self.on_hardware) def on_hardware(self, hw_type): self.hw_type = hw_type if self.wallet_type == 'multisig': self.create_hardware_multisig() else: title = _('Hardware wallet') + ' [%s]' % hw_type message = _('Do you have a device, or do you want to restore a wallet using an existing seed?') choices = [ ('create_hardware_wallet', _('I have a device')), ('restore_hardware_wallet', _('Use hardware wallet seed')), ] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.run) def create_hardware_multisig(self): self.storage.put('wallet_type', self.multisig_type) self.wallet = Multisig_Wallet(self.storage) # todo: get the xpub from the plugin self.run('create_wallet', xpub, None) def create_hardware_wallet(self): self.storage.put('wallet_type', self.hw_type) self.wallet = Wallet(self.storage) self.wallet.plugin.on_create_wallet(self.wallet, self) self.terminate() def restore_hardware_wallet(self): self.storage.put('wallet_type', self.wallet_type) self.wallet = Wallet(self.storage) self.wallet.plugin.on_restore_wallet(self.wallet, self) self.terminate() def create_wallet(self, text, password): if self.wallet_type == 'standard': self.wallet = Wallet.from_text(text, password, self.storage) self.run('create_addresses') elif self.wallet_type == 'multisig': self.storage.put('wallet_type', self.multisig_type) self.wallet = Multisig_Wallet(self.storage) self.wallet.add_cosigner('x1/', text, password) self.stack = [] self.run('show_xpub_and_add_cosigners', (password,)) def show_xpub_and_add_cosigners(self, password): xpub = self.wallet.master_public_keys.get('x1/') self.show_xpub_dialog(xpub=xpub, run_next=lambda x: self.run('add_cosigners', password)) def add_cosigners(self, password): i = self.wallet.get_missing_cosigner() self.add_cosigner_dialog(run_next=lambda x: self.on_cosigner(x, password), index=(i-1), is_valid=Wallet.is_xpub) def on_cosigner(self, text, password): i = self.wallet.get_missing_cosigner() try: self.wallet.add_cosigner('x%d/'%i, text, password) except BaseException as e: print "error:" + str(e) i = self.wallet.get_missing_cosigner() if i: self.run('add_cosigners', password) else: self.create_addresses() def create_addresses(self): def task(): self.wallet.create_main_account() self.wallet.synchronize() self.wallet.storage.write() self.terminate() msg = _("Electrum is generating your addresses, please wait.") self.waiting_dialog(task, msg) def create_seed(self): from electrum.wallet import BIP32_Wallet seed = BIP32_Wallet.make_seed() self.show_seed_dialog(run_next=self.confirm_seed, seed_text=seed) def confirm_seed(self, seed): self.confirm_seed_dialog(run_next=self.add_password, is_valid=lambda x: x==seed) def add_password(self, text): f = lambda pw: self.run('create_wallet', text, pw) self.request_password(run_next=f)
class BaseWizard(object): def __init__(self, config, network, path): super(BaseWizard, self).__init__() self.config = config self.network = network self.storage = WalletStorage(path) self.wallet = None self.stack = [] def run(self, action, *args): self.stack.append((action, args)) if not action: return if hasattr(self.wallet, 'plugin'): if hasattr(self.wallet.plugin, action): f = getattr(self.wallet.plugin, action) apply(f, (self.wallet, self) + args) elif hasattr(self, action): f = getattr(self, action) apply(f, *args) else: raise BaseException("unknown action", action) def get_action(self): if self.storage.file_exists: self.wallet = Wallet(self.storage) action = self.wallet.get_action() else: action = 'new' return action def get_wallet(self): if self.wallet and self.wallet.get_action() is None: return self.wallet def can_go_back(self): return len(self.stack)>1 def go_back(self): if not self.can_go_back(): return self.stack.pop() action, args = self.stack.pop() self.run(action, *args) def run_wallet(self): self.stack = [] action = self.wallet.get_action() if action: self.action_dialog(action=action, run_next=lambda x: self.run_wallet()) def new(self): name = os.path.basename(self.storage.path) title = _("Welcome to the Electrum installation wizard.") message = '\n'.join([ _("The wallet '%s' does not exist.") % name, _("What kind of wallet do you want to create?") ]) wallet_kinds = [ ('standard', _("Standard wallet")), ('twofactor', _("Wallet with two-factor authentication")), ('multisig', _("Multi-signature wallet")), ('hardware', _("Hardware wallet")), ] registered_kinds = Wallet.categories() choices = [pair for pair in wallet_kinds if pair[0] in registered_kinds] self.choice_dialog(title = title, message=message, choices=choices, run_next=self.on_wallet_type) def on_wallet_type(self, choice): self.wallet_type = choice if choice == 'standard': action = 'choose_seed' elif choice == 'multisig': action = 'choose_multisig' elif choice == 'hardware': action = 'choose_hw' elif choice == 'twofactor': action = 'choose_seed' self.run(action) def choose_multisig(self): def on_multisig(m, n): self.multisig_type = "%dof%d"%(m, n) self.run('choose_seed') self.multisig_dialog(run_next=on_multisig) def choose_seed(self): title = _('Private Keys') message = _("Do you want to create a new seed, or to restore a wallet using an existing seed?") if self.wallet_type == 'standard': choices = [ ('create_seed', _('Create a new seed')), ('restore_seed', _('I already have a seed')), ('restore_xpub', _('Watching-only wallet')), ] elif self.wallet_type == 'twofactor': choices = [ ('create_2fa', _('Create a new seed')), ('restore_2fa', _('I already have a seed')), ] elif self.wallet_type == 'multisig': choices = [ ('create_seed', _('Create a new seed')), ('restore_seed', _('I already have a seed')), ('restore_xpub', _('Watching-only wallet')), ('choose_hw', _('Cosign with hardware wallet')), ] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.run) def create_2fa(self): print 'create 2fa' self.storage.put('wallet_type', '2fa') self.wallet = Wallet(self.storage) self.run_wallet() def restore_seed(self): msg = _('Please type your seed phrase using the virtual keyboard.') title = _('Enter Seed') self.enter_seed_dialog(run_next=self.add_password, title=title, message=msg, is_valid=Wallet.is_seed) def restore_xpub(self): title = "MASTER PUBLIC KEY" message = _('To create a watching-only wallet, paste your master public key, or scan it using the camera button.') self.add_xpub_dialog(run_next=lambda xpub: self.create_wallet(xpub, None), title=title, message=message, is_valid=Wallet.is_mpk) def restore_2fa(self): self.storage.put('wallet_type', '2fa') self.wallet = Wallet(self.storage) self.wallet.plugin.on_restore_wallet(self.wallet, self) def choose_hw(self): hw_wallet_types, choices = self.plugins.hardware_wallets('create') choices = zip(hw_wallet_types, choices) title = _('Hardware wallet') if choices: msg = _('Select the type of hardware wallet: ') else: msg = ' '.join([ _('No hardware wallet support found on your system.'), _('Please install the relevant libraries (eg python-trezor for Trezor).'), ]) self.choice_dialog(title=title, message=msg, choices=choices, run_next=self.on_hardware) def on_hardware(self, hw_type): self.hw_type = hw_type if self.wallet_type == 'multisig': self.create_hardware_multisig() else: title = _('Hardware wallet') + ' [%s]' % hw_type message = _('Do you have a device, or do you want to restore a wallet using an existing seed?') choices = [ ('create_hardware_wallet', _('I have a device')), ('restore_hardware_wallet', _('Use hardware wallet seed')), ] self.choice_dialog(title=title, message=message, choices=choices, run_next=self.run) def create_hardware_multisig(self): self.storage.put('wallet_type', self.multisig_type) self.wallet = Multisig_Wallet(self.storage) # todo: get the xpub from the plugin self.run('create_wallet', xpub, None) def create_hardware_wallet(self): self.storage.put('wallet_type', self.hw_type) self.wallet = Wallet(self.storage) self.wallet.plugin.on_create_wallet(self.wallet, self) self.terminate() def restore_hardware_wallet(self): self.storage.put('wallet_type', self.wallet_type) self.wallet = Wallet(self.storage) self.wallet.plugin.on_restore_wallet(self.wallet, self) self.terminate() def create_wallet(self, text, password): if self.wallet_type == 'standard': self.wallet = Wallet.from_text(text, password, self.storage) self.run('create_addresses') elif self.wallet_type == 'multisig': self.storage.put('wallet_type', self.multisig_type) self.wallet = Multisig_Wallet(self.storage) self.wallet.add_seed(text, password) self.wallet.create_master_keys(password) self.run_wallet() def add_cosigners(self): xpub = self.wallet.master_public_keys.get('x1/') self.show_xpub_dialog(run_next=lambda x: self.add_cosigner(), xpub=xpub) def add_cosigner(self): def on_xpub(xpub): self.wallet.add_cosigner(xpub) i = self.wallet.get_missing_cosigner() action = 'add_cosigner' if i else 'create_addresses' self.run(action) i = self.wallet.get_missing_cosigner() title = _("Add Cosigner") + " %d"%(i-1) message = _('Please paste your cosigners master public key, or scan it using the camera button.') self.add_xpub_dialog(run_next=on_xpub, title=title, message=message, is_valid=Wallet.is_any) def create_addresses(self): def task(): self.wallet.create_main_account() self.wallet.synchronize() self.terminate() msg= _("Electrum is generating your addresses, please wait.") self.waiting_dialog(task, msg) def create_seed(self): from electrum.wallet import BIP32_Wallet seed = BIP32_Wallet.make_seed() msg = _("If you forget your PIN or lose your device, your seed phrase will be the " "only way to recover your funds.") self.show_seed_dialog(run_next=self.confirm_seed, message=msg, seed_text=seed) def confirm_seed(self, seed): assert Wallet.is_seed(seed) title = _('Confirm Seed') msg = _('Please retype your seed phrase, to confirm that you properly saved it') self.enter_seed_dialog(run_next=self.add_password, title=title, message=msg, is_valid=lambda x: x==seed) def add_password(self, seed): f = lambda x: self.create_wallet(seed, x) self.request_password(run_next=f)
type=str, nargs='+', help='Electrum wallet path') args = parser.parse_args() exec_path = os.path.dirname(os.path.realpath(__file__)) + '/' # test electrum daemon try: pid = subprocess.check_output('pgrep electrum', shell=True) except subprocess.CalledProcessError: # start daemon f = subprocess.call(['electrum', 'daemon', 'start']) if os.path.isfile(args.wallet_path[0]): storage = WalletStorage(args.wallet_path[0]) w = electrum.wallet.NewWallet(storage) else: print('Wrong Wallet Path!') sys.exit() if not os.path.isfile(exec_path + 'murtcele.db'): conn = sqlite3.connect(exec_path + 'murtcele.db') c = conn.cursor() c.execute( '''CREATE TABLE electrum (id integer primary key autoincrement ,address text not null, balance real not null, t datetime not null default CURRENT_TIMESTAMP)''' ) # fill db with wallet addresses addresses = subprocess.check_output('electrum listaddresses', shell=True)