def execute(ctx: ExecutionContext): """Step entry point. :param ctx: Execution context information. """ # Set target network / node. network, node = get_network_node(ctx) # Set validator. _, validator = get_network_node(ctx, ctx.args.validator_index) # Submit deploy. dispatch_info = chain.DeployDispatchInfo(validator.account, network, node) deploy_hash, dispatch_duration, dispatch_attempts = \ chain.set_auction_bid_withdraw( dispatch_info, ctx.args.amount ) # Update cache: deploy. cache.state.set_deploy( factory.create_deploy_for_run(ctx=ctx, account=validator.account, node=node, deploy_hash=deploy_hash, dispatch_attempts=dispatch_attempts, dispatch_duration=dispatch_duration, typeof=DeployType.AUCTION_BID_WITHDRAW))
def verify_account_balance_on_transfer( ctx: ExecutionContext, node_id: NodeIdentifier, state_root_hash: str, account_index: int, expected: int, ) -> Account: """Verifies that an account balance is as per expectation. """ # Set account. account = cache.state.get_account_by_index(ctx, account_index) # Set network / node in readiness for chain interaction. network, node = get_network_node(node_id) # Set account main purse uref. purse_uref = chain.get_account_main_purse_uref(network, node, account.account_key, state_root_hash) assert purse_uref is not None, \ f"account {account_index} main purse uref could not be retrieved - probably on-chain account does not exist" # Set account balance. balance = chain.get_account_balance(network, node, purse_uref, state_root_hash) assert balance == expected, \ f"account balance mismatch: account_index={account_index}, account_key={account.account_key}, expected={expected}, actual={balance}" return account
def execute(ctx: ExecutionContext): """Step entry point. :param ctx: Execution context information. """ # Set target network / node. network, node = get_network_node(ctx) # Set validator account. validator = factory.create_account_for_run(ctx, _USER_ACCOUNT_INDEX) # Submit deploy. dispatch_info = chain.DeployDispatchInfo(validator, network, node) deploy_hash, dispatch_duration, dispatch_attempts = \ chain.set_auction_bid_submit( dispatch_info, ctx.args.amount, ctx.args.delegation_rate ) # Update cache: deploy. cache.state.set_deploy( factory.create_deploy_for_run(ctx=ctx, account=validator, node=node, deploy_hash=deploy_hash, dispatch_attempts=dispatch_attempts, dispatch_duration=dispatch_duration, typeof=DeployType.AUCTION_BID_SUBMIT))
def do_transfer( ctx: ExecutionContext, cp1_index: int, cp2_index: int, amount: int, transfer_type: str, ): """Executes a token transfer between 2 counter-parties. :param ctx: Execution context information. :param cp1_index: Account index of counter-party 1. :param cp2_index: Account index of counter-party 1. :param amount: Amount (in motes) to transfer. :param transfer_type: Type of transfer to dispatch. """ # Set target network / node. network, node = get_network_node(ctx) # Set counterparties. cp1 = get_account(ctx, network, cp1_index) cp2 = get_account(ctx, network, cp2_index) # Set amount to transfer (in the case of refunds). if amount is None: amount = get_account_balance(network, node, cp1) - chain.DEFAULT_TX_FEE # Dispatch tx -> chain. dispatch_info = chain.DeployDispatchInfo(cp1, network, node) dispatch_fn = TFR_TYPE_TO_TFR_FN[DeployType[transfer_type]] deploy_hash, dispatch_duration, dispatch_attempts = dispatch_fn(dispatch_info, cp2, amount) # Update cache: deploy. cache.state.set_deploy(factory.create_deploy_for_run( ctx=ctx, account=cp1, associated_account=cp2, node=node, deploy_hash=deploy_hash, dispatch_attempts=dispatch_attempts, dispatch_duration=dispatch_duration, typeof=DeployType[transfer_type] )) # Update cache: account balances. if cp1.is_run_account: cache.state.decrement_account_balance(cp1, amount) if cp2.is_run_account: cache.state.increment_account_balance(cp2, amount)
def verify_account_balance(ctx: ExecutionContext, account_index: int, expected: int) -> Account: """Verifies that an account balance is as per expectation. """ account = cache.state.get_account_by_index(ctx, account_index) network, node = get_network_node(ctx) state_root_hash = chain.get_state_root_hash(network, node) purse_uref = chain.get_account_main_purse_uref(network, node, account.account_key, state_root_hash) assert purse_uref is not None, \ f"account {account_index} main purse uref could not be retrieved - probably on-chain account does not exist" balance = chain.get_account_balance(network, node, purse_uref, state_root_hash) assert balance == expected, \ f"account balance mismatch: account_index={account_index}, account_key={account.account_key}, expected={expected}, actual={balance}"
def do_transfer_fire_forget( ctx: ExecutionContext, cp2: Account, amount: int, transfer_type: DeployType, ): """Executes fire & forget token transfers between counter-parties. :param ctx: Execution context information. :param cp2: Counter-party 2 account. :param amount: Amount (in motes) to transfer. :param transfer_type: Type of transfer to dispatch. """ network, node = get_network_node(ctx) cp1 = get_account(ctx, network, get_account_idx_for_network_faucet()) dispatch_info = chain.DeployDispatchInfo(cp1, network, node) dispatch_fn = TFR_TYPE_TO_TFR_FN[transfer_type] dispatch_fn(dispatch_info, cp2, amount) cache.orchestration.increment_deploy_counts(ctx, 1)
def _do_delegate_action(ctx: ExecutionContext, account_index: int, amount: int, deploy_type: DeployType): # Set target network / node. network, node = get_network_node(ctx) # Set accounts. validator = node.account user = _get_account(ctx, network, account_index) # Dispatch auction deploy. dispatch_fn = DEPLOY_TYPE_TO_FN[deploy_type] dispatch_info = DeployDispatchInfo(user, network, node) deploy_hash, dispatch_duration, dispatch_attempts = dispatch_fn( dispatch_info, validator, amount) # Update cache: deploy. cache.state.set_deploy( factory.create_deploy_for_run(ctx=ctx, account=user, node=node, deploy_hash=deploy_hash, dispatch_attempts=dispatch_attempts, dispatch_duration=dispatch_duration, typeof=deploy_type))