예제 #1
0
    def execute(self, args, output):
        convex = self.load_convex(args.url)

        key_pair = self.import_key_pair(args)
        if key_pair is None:
            key_pair = KeyPair()

        logger.debug('creating account')
        account = convex.create_account(key_pair)

        if args.topup:
            logger.debug('auto topup of account balance')
            convex.topup_account(account)

        if args.name:
            logger.debug(f'registering account name {args.name}')
            convex.topup_account(account)
            account = convex.register_account_name(args.name, account)
        if args.password:
            password = args.password
        else:
            password = secrets.token_hex(32)
        values = {
            'password': password,
            'address': account.address,
            'public_key': key_pair.public_key,
            'keyfile': key_pair.export_to_text(password),
            'keywords': key_pair.export_to_mnemonic,
            'balance': convex.get_balance(account)
        }
        if account.name:
            values['name'] = account.name
        output.set_values(values)
        output.add_line_values(values)
예제 #2
0
    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) -> 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}')
예제 #4
0
    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)
예제 #5
0
def test_account_setup_account(convex_url, test_key_pair_info):
    convex = API(convex_url)
    import_key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    account = convex.setup_account(TEST_ACCOUNT_NAME, import_key_pair)
    assert(account.address)
    assert(account.name)
    assert(account.name == TEST_ACCOUNT_NAME)
    assert(convex.resolve_account_name(TEST_ACCOUNT_NAME) == account.address)
    def execute(self, args, output):
        convex = self.load_convex(args.url)

        key_pair = self.import_key_pair(args)
        if key_pair is None:
            key_pair = KeyPair()

        logger.debug('creating account')
        account = convex.create_account(key_pair)

        if args.topup:
            logger.debug('auto topup of account balance')
            for counter in range(4):
                convex.request_funds(DEFAULT_FUND_AMOUNT, account)

        if args.name:
            logger.debug(f'registering account name {args.name}')
            convex.topup_account(account)
            account = convex.register_account_name(args.name, account)
        if args.password:
            password = args.password
        else:
            password = secrets.token_hex(32)

        balance = convex.get_balance(account)
        stake_amount = math.floor(balance * 0.98)

        create_peer_command = f'(create-peer {account.key_pair.public_key} {stake_amount} )'
        convex.send(create_peer_command, account)

        values = {
            'password': password,
            'address': account.address,
            'public_key': key_pair.public_key,
            'keyfile': key_pair.export_to_text(password),
            'keywords': key_pair.export_to_mnemonic,
            'balance': convex.get_balance(account),
            'stake': stake_amount,
        }
        if account.name:
            values['name'] = account.name
        output.set_values(values)
        output.add_line_values(values)
 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)
예제 #8
0
def test_account_api_multi_create_account(convex_url):
    convex = API(convex_url)
    key_pair = KeyPair()
    account_1 = convex.create_account(key_pair)
    assert(account_1)
    account_2 = convex.create_account(key_pair)
    assert(account_2)

    assert(account_1.public_key == account_1.public_key)
    assert(account_1.public_key == account_2.public_key)
    assert(account_1.is_address)
    assert(account_1.address != account_2.address)
예제 #9
0
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
예제 #10
0
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
예제 #11
0
def test_account_name(convex_url, test_key_pair_info):
    convex = API(convex_url)
    import_key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    if convex.resolve_account_name(TEST_ACCOUNT_NAME):
        account = convex.load_account(TEST_ACCOUNT_NAME, import_key_pair)
    else:
        account = convex.create_account(import_key_pair)
        convex.topup_account(account)
        account = convex.register_account_name(TEST_ACCOUNT_NAME, account)
    assert(account.address)
    assert(account.name)
    assert(account.name == TEST_ACCOUNT_NAME)
    assert(convex.resolve_account_name(TEST_ACCOUNT_NAME) == account.address)
예제 #12
0
def test_account_api_create_account(convex_url):

    convex = API(convex_url)
    key_pair = KeyPair()
    result = convex.create_account(key_pair)
    assert(result)
예제 #13
0
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'])