def create(ctx, account_type, testnet): """ Creates a new wallet """ # txn_data_provider and related params come from the # global context. passphrase = "" if ctx.obj['passphrase']: # Let's prompt for a passphrase conf = "a" i = 0 while passphrase != conf and i < 3: passphrase = getpass.getpass("Enter desired passphrase: ") conf = getpass.getpass("Confirm passphrase: ") i += 1 if passphrase != conf: ctx.fail("Passphrases don't match. Quitting.") options = {"account_type": account_type, "passphrase": passphrase, "data_provider": ctx.obj['data_provider'], "testnet": testnet, "wallet_path": ctx.obj['wallet_path']} logger.info("Creating wallet with options: %r" % options) created = Two1Wallet.configure(options) if created: # Make sure it opens logger.info("Wallet created.") try: wallet = Two1Wallet(params_or_file=ctx.obj['wallet_path'], data_provider=ctx.obj['data_provider'], passphrase=passphrase) click.echo("Wallet successfully created!") adder = " (and your passphrase) " if passphrase else " " click.echo("Your wallet can be recovered using the following set of words (in that order).") click.echo("Please store them%ssafely." % adder) click.echo("\n%s\n" % wallet._orig_params['master_seed']) except Exception as e: logger.debug("Error opening created wallet: %s" % e) click.echo("Wallet was not created properly.") ctx.exit(code=3) else: ctx.fail("Wallet was not created.")
def __init__(self, config_file=TWO1_CONFIG_FILE, config=None, create_wallet=True): if not os.path.exists(TWO1_USER_FOLDER): os.makedirs(TWO1_USER_FOLDER) self.file = path(config_file).expand().abspath() self.dir = self.file.parent self.defaults = {} # TODO: Rename this var. Those are not the defaults but the actual values. self.json_output = False # output in json # actual config. self.load() # override config variables if config: if self.verbose: self.vlog("Applied manual config.") for k, v in config: self.defaults[k] = v if self.verbose: self.vlog("\t{}={}".format(k, v)) # add wallet object if self.defaults.get('testwallet', None) == 'y': self.wallet = test_wallet.TestWallet() elif create_wallet: dp = TwentyOneProvider(TWO1_PROVIDER_HOST) wallet_path = self.defaults.get('wallet_path') if not Two1Wallet.check_wallet_file(wallet_path): # configure wallet with default options click.pause(UxString.create_wallet) wallet_options = { 'data_provider': dp, 'wallet_path': wallet_path } if not Two1Wallet.configure(wallet_options): raise click.ClickException(UxString.Error.create_wallet_failed) # Display the wallet mnemonic and tell user to back it up. # Read the wallet JSON file and extract it. with open(wallet_path, 'r') as f: wallet_config = json.load(f) mnemonic = wallet_config['master_seed'] click.pause(UxString.create_wallet_done % (mnemonic)) # Start the daemon, if: # 1. It's not already started # 2. It's using the default wallet path # 3. We're not in a virtualenv try: d = daemonizer.get_daemonizer() if Two1Wallet.is_configured() and \ wallet_path == Two1Wallet.DEFAULT_WALLET_PATH and \ not os.environ.get("VIRTUAL_ENV") and \ not d.started(): d.start() if d.started(): click.echo(UxString.wallet_daemon_started) except (OSError, DaemonizerError): pass self.wallet = Wallet(wallet_path=wallet_path, data_provider=dp) self.machine_auth = MachineAuthWallet(self.wallet) self.channel_client = PaymentChannelClient(self.wallet) else: # This branch is hit when '21 help' or '21 update' is invoked pass
def __init__(self, config_file=TWO1_CONFIG_FILE, config=None, create_wallet=True): if not os.path.exists(TWO1_USER_FOLDER): os.makedirs(TWO1_USER_FOLDER) self.file = path(config_file).expand().abspath() self.dir = self.file.parent self.defaults = { } # TODO: Rename this var. Those are not the defaults but the actual values. self.json_output = False # output in json # actual config. self.load() # override config variables if config: if self.verbose: self.vlog("Applied manual config.") for k, v in config: self.defaults[k] = v if self.verbose: self.vlog("\t{}={}".format(k, v)) # add wallet object if self.defaults.get('testwallet', None) == 'y': self.wallet = test_wallet.TestWallet() elif create_wallet: dp = TwentyOneProvider(TWO1_PROVIDER_HOST) wallet_path = self.defaults.get('wallet_path') if not Two1Wallet.check_wallet_file(wallet_path): # configure wallet with default options click.pause(UxString.create_wallet) wallet_options = { 'data_provider': dp, 'wallet_path': wallet_path } if not Two1Wallet.configure(wallet_options): raise click.ClickException( UxString.Error.create_wallet_failed) # Display the wallet mnemonic and tell user to back it up. # Read the wallet JSON file and extract it. with open(wallet_path, 'r') as f: wallet_config = json.load(f) mnemonic = wallet_config['master_seed'] click.pause(UxString.create_wallet_done % (mnemonic)) # Start the daemon, if: # 1. It's not already started # 2. It's using the default wallet path # 3. We're not in a virtualenv try: d = daemonizer.get_daemonizer() if Two1Wallet.is_configured() and \ wallet_path == Two1Wallet.DEFAULT_WALLET_PATH and \ not os.environ.get("VIRTUAL_ENV") and \ not d.started(): d.start() if d.started(): click.echo(UxString.wallet_daemon_started) except (OSError, DaemonizerError): pass self.wallet = Wallet(wallet_path=wallet_path, data_provider=dp) self.machine_auth = MachineAuthWallet(self.wallet) self.channel_client = PaymentChannelClient(self.wallet) else: # This branch is hit when '21 help' or '21 update' is invoked pass