def execute(self, args: Any, output: Any) -> None: if not self.is_address(args.address): output.add_error(f'{args.address} is not a convex account address') return key_pair = KeyPair.import_from_file(args.keyfile, args.password) if not key_pair: output.add_error( 'unable to load keyfile using the provided password') return account = ConvexAccount(key_pair, args.address) amount = float(args.amount) to_address = args.to_address if not self.is_address(to_address): output.add_error(f'{to_address} is not a convex address') return network = self.get_network(args.url) logger.debug( f'sending tokens from account {account.address} to account {to_address}' ) network.convex.transfer(to_address, amount, account) balance = network.get_balance(account) output.add_line( f'Send {amount} tokens from account: {args.address} to account {to_address}' ) output.set_value('balance', balance) output.set_value('from_address', args.address) output.set_value('to_address', args.to_address) output.set_value('amount', amount)
def execute(self, args: Any, output: Any) -> Any: network = self.get_network( args.url, contract_names={'DIDContract': args.contract_name}) key_pair = KeyPair.import_from_file(args.keyfile, args.password) if not key_pair: output.add_error( 'unable to load keyfile using the provided password') return register_account = ConvexAccount(key_pair, args.address) service_list = None if args.service_list: name_list = re.split(r'[^a-z]+', args.service_list, re.IGNORECASE) service_list = [] for name in name_list: service_name = name.strip() if service_name not in SUPPORTED_SERVICES: output.add_error(f'{service_name} is not a valid service') return service_list.append(service_name) ddo = DDO.create(args.agent_url, service_list=service_list) if network.register_did(register_account, ddo.did, ddo.as_text): output.add_line( f'{args.agent_url} has been registered with the did {ddo.did}') output.add_line(ddo.as_text) output.set_value('did', ddo.did) output.set_value('ddo_text', ddo.as_text) else: output.add_error(f'unable to register {args.agent_url}')
def accounts(config, convex): result = [] # load in the test accounts account_1 = config['accounts']['account1'] keypair_import = KeyPair.import_from_file(account_1['keyfile'], account_1['password']) accounts = [ convex.setup_account(account_1['name'], keypair_import), convex.create_account(keypair_import), ] topup_accounts(convex, accounts) return accounts
def convex_accounts(config, convex_network): result = [] # load in the test accounts account_1 = config['convex']['accounts']['account1'] import_key_pair = KeyPair.import_from_file(account_1['keyfile'], account_1['password']) accounts = [ convex_network.setup_account(account_1['name'], import_key_pair), convex_network.create_account(import_key_pair), ] auto_topup_account(convex_network, accounts) return accounts
def import_key_pair(self, args): key_pair = None if args.keyfile and args.password: logger.debug(f'importing keyfile {args.keyfile}') key_pair = KeyPair.import_from_file(args.keyfile, args.password) elif args.keywords: logger.debug('importing key from mnemonic') key_pair = KeyPair.import_from_mnemonic(args.keywords) elif args.keytext and args.password: logger.debug('importing keytext') key_pair = KeyPair.import_from_text(args.keytext, args.password) return key_pair
def execute(self, args: Any, output: Any) -> None: network = self.get_network(args.url) key_pair = None if args.password and args.keyfile: key_pair = KeyPair.import_from_file(args.keyfile, args.password) else: key_pair = KeyPair() account = network.create_account(key_pair) logger.debug(f'create new account {account.address}') if args.keyfile and not os.path.exists(args.keyfile): logger.debug(f'writing key file to {args.keyfile}') account.key_pair.export_to_file(args.keyfile, args.password) else: logger.debug('writing key file to ouptut') output.add_line(account.key_pair.export_to_text(args.password)) output.add_line(account.address) output.set_value('public_key', account.public_key) output.set_value('export_key', account.key_pair.export_to_text(args.password)) output.set_value('address', account.address)
def keypair_import(config, convex): result = [] # load in the test accounts account_1 = config['accounts']['account1'] return KeyPair.import_from_file(account_1['keyfile'], account_1['password'])