def _add_token_network_deploy_info( token_network: Dict[str, Any], deployer: ContractDeployer, contracts_version: str ) -> None: """ Add deploy info dict to the deploy_*.json file """ deployment_file_path = contracts_deployed_path( chain_id=ChainID(deployer.web3.eth.chainId), version=contracts_version ) with deployment_file_path.open() as f: deployed_contracts_info: DeployedContracts = json.load(f) deployed_contracts_info.setdefault("token_networks", []).append(token_network) deployer.store_and_verify_deployment_info_raiden( deployed_contracts_info=deployed_contracts_info )
def setup_ctx( ctx: click.Context, private_key: str, password_file: Optional[Path], rpc_provider: URI, wait: int, gas_price: int, gas_limit: int, contracts_version: Optional[str] = None, ) -> None: """Set up deployment context according to common options (shared among all subcommands). """ logging.basicConfig(level=logging.DEBUG) logging.getLogger("web3").setLevel(logging.INFO) logging.getLogger("urllib3").setLevel(logging.INFO) web3 = Web3(HTTPProvider(rpc_provider, request_kwargs={"timeout": 60})) web3.middleware_onion.inject(geth_poa_middleware, layer=0) print("Web3 provider is", web3.provider) private_key_string = get_private_key( Path(private_key).expanduser(), password_file) if not private_key_string: raise RuntimeError("Could not access the private key.") owner = private_key_to_address(private_key_string) # pylint: disable=E1101 if web3.eth.get_balance(owner) == 0: raise RuntimeError("Account with insufficient funds.") deployer = ContractDeployer( web3=web3, private_key=private_key_string, gas_limit=gas_limit, gas_price=gas_price, wait=wait, contracts_version=contracts_version, ) ctx.obj = { "deployer": deployer, "deployed_contracts": {}, "token_type": "CustomToken", "wait": wait, }
def deprecation_test_setup( deployer: ContractDeployer, token_amount: int, channel_participant_deposit_limit: int, token_network_deposit_limit: int, ) -> Tuple: deployed_contracts = deployer.deploy_raiden_contracts( max_num_of_token_networks=1, reuse_secret_registry_from_deploy_file=None, settle_timeout_min=DEPLOY_SETTLE_TIMEOUT_MIN, settle_timeout_max=DEPLOY_SETTLE_TIMEOUT_MAX, )["contracts"] token_network_registry_abi = deployer.contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY ) token_network_registry = deployer.web3.eth.contract( abi=token_network_registry_abi, address=deployed_contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]["address"], ) token_decimals = 18 multiplier = 10 ** token_decimals token_supply = 10 ** 6 * multiplier token_amount = int(token_amount * multiplier) deployed_token = deployer.deploy_token_contract( token_supply, token_decimals, "TestToken", "TTT", CONTRACT_CUSTOM_TOKEN ) token_address = deployed_token[CONTRACT_CUSTOM_TOKEN] token_abi = deployer.contract_manager.get_contract_abi(CONTRACT_CUSTOM_TOKEN) token_contract = deployer.web3.eth.contract(abi=token_abi, address=token_address) # Mint some tokens for the owner txhash = call_and_transact(token_contract.functions.mint(token_amount), deployer.transaction) log.debug(f"Minting tokens txHash={encode_hex(txhash)}") check_successful_tx(deployer.web3, txhash, deployer.wait) assert token_contract.functions.balanceOf(deployer.owner).call() >= token_amount abi = deployer.contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK_REGISTRY) token_network_address = deployer.register_token_network( token_registry_abi=abi, token_registry_address=deployed_contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]["address"], token_address=token_address, channel_participant_deposit_limit=channel_participant_deposit_limit, token_network_deposit_limit=token_network_deposit_limit, )["token_network_address"] token_network_abi = deployer.contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK) token_network = deployer.web3.eth.contract( abi=token_network_abi, address=token_network_address ) log.info( f"Registered the token and created a TokenNetwork contract at {token_network_address}." ) txhash = call_and_transact( token_contract.functions.approve(token_network.address, token_amount), deployer.transaction, ) log.debug(f"Approving tokens for the TokenNetwork contract txHash={encode_hex(txhash)}") check_successful_tx(deployer.web3, txhash, deployer.wait) assert ( token_contract.functions.allowance(deployer.owner, token_network.address).call() >= token_amount ) log.info( f"Approved {token_amount} tokens for the TokenNetwork contract " f"from owner {deployer.owner}." ) return (token_network_registry, token_network, token_contract)