def abi_encode_args(self, method_name, parameters, kwargs): # When using proxy make sure that token_hash ('erc20') is the first argument args = ( [parameters[p](p, kwargs[p]) for p in parameters if p == "erc20"] + [ABI.string_value("method", method_name)] + [parameters[p](p, kwargs[p]) for p in parameters if p != "erc20"]) return ABI.args(args)
def do_deploy_client_contract(network: Network, contract_type: ClientContractType, contract_name: str) -> str: """Deploys a client side smart contract to chain for future reference. :param network: Network to which a client contract is being deployed. :param contract_type: Type of contract to be deployed. :param contract_name: Name of contract as specified in wasm blob. :returns: Contract hash (in hex format). """ # Set client. _, client = utils.get_client(network) # Dispatch deploy. session = utils.get_client_contract_path(contract_type) session_args = ABI.args([ABI.string_value("target", "hash")]) dhash = client.deploy( session=session, session_args=session_args, from_addr=network.faucet.public_key, private_key=network.faucet.private_key_as_pem_filepath, # TODO: allow these to be passed in via standard arguments payment_amount=defaults.CLX_TX_FEE, gas_price=defaults.CLX_TX_GAS_PRICE) logger.log( f"PYCLX :: deploy-contract :: {contract_type.value} :: deploy-hash={dhash} -> awaiting processing" ) # Get block hash. dinfo = client.showDeploy(dhash, wait_for_processed=True) bhash = dinfo.processing_results[0].block_info.summary.block_hash.hex() logger.log( f"PYCLX :: deploy-contract :: {contract_type.value} :: deploy-hash={dhash} -> processing complete" ) # Get contract hash. chash = utils.get_client_contract_hash(client, network.faucet, bhash, contract_name) logger.log( f"PYCLX :: deploy-contract :: {contract_type.value} :: contract-hash={chash}" ) return chash
def abi_encode_args(self, method_name, parameters, kwargs): args = [ABI.string_value("method", method_name) ] + [parameters[p](p, kwargs[p]) for p in parameters] return ABI.args(args)
def disable_test_multiple_deploys_per_block(cli): """ Two deploys from the same account then propose. Both deploys should be be included in the new block. Create named purses to pay from for each deploy (standard payment cannot be used because it causes a WRITE against the main purse balance, but every deploy has a READ against that balance to check it meets the minimum balance condition, so standard payment calls always conflict with any other deploy from the same account) """ account = cli.node.test_account cli.set_default_deploy_args('--from', account.public_key_hex, '--private-key', cli.private_key_path(account), '--public-key', cli.public_key_path(account)) # Create purse_1 deploy_hash = cli( 'deploy', '--session', cli.resource(Contract.CREATE_NAMED_PURSE), '--session-args', ABI.args_to_json( ABI.args([ ABI.big_int("amount", 100000000), ABI.string_value("purse-name", "purse_1") ])), '--payment', cli.resource(Contract.STANDARD_PAYMENT), '--payment-args', ABI.args_to_json(ABI.args([ABI.big_int("amount", 100000000)]))) check_no_errors(cli, deploy_hash) # Create purse_2 deploy_hash = cli( 'deploy', '--session', cli.resource(Contract.CREATE_NAMED_PURSE), '--session-args', ABI.args_to_json( ABI.args([ ABI.big_int("amount", 100000000), ABI.string_value("purse-name", "purse_2") ])), '--payment', cli.resource(Contract.STANDARD_PAYMENT), '--payment-args', ABI.args_to_json(ABI.args([ABI.big_int("amount", 100000000)]))) check_no_errors(cli, deploy_hash) # First deploy uses first purse for payment deploy_hash1 = cli( 'deploy', '--from', account.public_key_hex, '--session', cli.resource(Contract.COUNTER_DEFINE), '--payment', cli.resource(Contract.PAYMENT_FROM_NAMED_PURSE), '--payment-args', ABI.args_to_json( ABI.args([ ABI.big_int("amount", 100000000), ABI.string_value("purse-name", "purse_1") ]))) # Second deploy uses second purse for payment deploy_hash2 = cli( 'deploy', '--from', account.public_key_hex, '--session', cli.resource(Contract.MAILING_LIST_DEFINE), '--payment', cli.resource(Contract.PAYMENT_FROM_NAMED_PURSE), '--payment-args', ABI.args_to_json( ABI.args([ ABI.big_int("amount", 100000000), ABI.string_value("purse-name", "purse_2") ]))) block_hash = check_no_errors(cli, deploy_hash2) # Propose should include both deploys. deploys = list(cli("show-deploys", block_hash)) # TODO: with auto-propose this may fail: assert len(deploys) == 2 assert set(d.deploy.deploy_hash for d in deploys) == set( (deploy_hash1, deploy_hash2))