def __init__(self): """ Constructor for the Rev class. """ self.config = two1_config.Config(two1.TWO1_CONFIG_FILE, None) self.wallet = wallet_utils.get_or_create_wallet(self.config.wallet_path) self.machine_auth = machine_auth_wallet.MachineAuthWallet(self.wallet) self.client = rest_client.TwentyOneRestClient(two1.TWO1_HOST, self.machine_auth, self.config.username)
def parse_config( config_file=two1.TWO1_CONFIG_FILE, config_dict=None, need_wallet_and_account=True, check_update=False, debug=False, ): """Get configuration information that is used to drive all 21 commands. This function is very useful for testing as it builds up several key variables (like the client, wallet, username, and the like) that are used in many commands. The way it does this is by taking in the config_file (typically .two1/two1.json) and the config_dict (a list of key-value pairs to override the config_file, typically an empty dictionary), and then running the logic below. It returns obj which is a dictionary that has Config, Wallet, MachineAuth, and TwentyOneRestClient instances underneath it, as well as a string with the username. The obj is passed down by click to various other commands. You can use this function in any test to instantiate the user's wallet, username, and other variables. """ try: config = two1_config.Config(config_file, config_dict, check_update=check_update) except exceptions.FileDecodeError as e: raise click.ClickException( uxstring.UxString.Error.file_decode.format((str(e)))) wallet, machine_auth, username, client = None, None, None, None if need_wallet_and_account: try: wallet = wallet_utils.get_or_create_wallet(config.wallet_path) except blockchain_exceptions.DataProviderError as err: raise exceptions.Two1Error( 'You have experienced a data provider error: %s ' % err.args) machine_auth = machine_auth_wallet.MachineAuthWallet(wallet) username = account_utils.get_or_create_username(config, machine_auth) client = rest_client.TwentyOneRestClient(two1.TWO1_HOST, machine_auth, config.username) config.username = username obj = dict( config=config, wallet=wallet, machine_auth=machine_auth, username=username, client=client, debug=debug, ) return obj
def parse_config( config_file=two1.TWO1_CONFIG_FILE, config_dict=None, need_wallet_and_account=True, check_update=False, debug=False, ): """Get configuration information that is used to drive all 21 commands. This function is very useful for testing as it builds up several key variables (like the client, wallet, username, and the like) that are used in many commands. The way it does this is by taking in the config_file (typically .two1/two1.json) and the config_dict (a list of key-value pairs to override the config_file, typically an empty dictionary), and then running the logic below. It returns obj which is a dictionary that has Config, Wallet, MachineAuth, and TwentyOneRestClient instances underneath it, as well as a string with the username. The obj is passed down by click to various other commands. You can use this function in any test to instantiate the user's wallet, username, and other variables. """ try: config = two1_config.Config( config_file, config_dict, check_update=check_update) except exceptions.FileDecodeError as e: raise click.ClickException(uxstring.UxString.Error.file_decode.format((str(e)))) wallet, machine_auth, username, client = None, None, None, None if need_wallet_and_account: try: wallet = wallet_utils.get_or_create_wallet(config.wallet_path) except blockchain_exceptions.DataProviderError as err: raise exceptions.Two1Error( 'You have experienced a data provider error: %s ' % err.args) machine_auth = machine_auth_wallet.MachineAuthWallet(wallet) username = account_utils.get_or_create_username(config, machine_auth) client = rest_client.TwentyOneRestClient(two1.TWO1_HOST, machine_auth, config.username) config.username = username obj = dict( config=config, wallet=wallet, machine_auth=machine_auth, username=username, client=client, debug=debug, ) return obj
def initialize_client(): uuid = bitcoin_computer.get_device_uuid() if uuid: two1.TWO1_DEVICE_ID = uuid try: config = two1_config.Config(two1.TWO1_CONFIG_FILE, dict()) ctx = dict() except exceptions.FileDecodeError as e: raise click.ClickException(uxstring.UxString.Error.file_decode.format((str(e)))) wallet = wallet_utils.get_or_create_wallet(config.wallet_path) machine_auth = machine_auth_wallet.MachineAuthWallet(wallet) config.username = account_utils.get_or_create_username(config, machine_auth) client = rest_client.TwentyOneRestClient(two1.TWO1_HOST, machine_auth, config.username) ctx['client'] = client ctx['config'] = config ctx['wallet'] = wallet return ctx;
def login(ctx, setpassword, username, password): """Login to your 21.co account. \b Usage _____ 21 login # Interactive login 21 login -u user -p pass # Headless login 21 login -sp # Set password for currently logged-in user """ config = ctx.obj['config'] # A user needs to have a machine auth wallet in order to login to anything wallet = wallet_util.get_or_create_wallet(config.wallet_path) machine_auth = machine_auth_wallet.MachineAuthWallet(wallet) if setpassword: return set_password(config, machine_auth) else: return login_account(config, machine_auth, username, password)