def contract_manager_meta(contracts_path): manager = ContractManager(contracts_path) abi = manager.get_contract_abi('TokenNetwork') assert isinstance(abi, list) with pytest.raises(KeyError): manager.get_contract_abi('SomeName') abi = manager.get_event_abi('TokenNetwork', 'ChannelClosed') assert isinstance(abi, dict) with pytest.raises(KeyError): manager.get_event_abi('TokenNetwork', 'NonExistant')
def contract_manager_meta(contracts_path): manager = ContractManager(contracts_path) abi = manager.get_contract_abi(CONTRACT_TOKEN_NETWORK) assert isinstance(abi, list) with pytest.raises(KeyError): manager.get_contract_abi('SomeName') abi = manager.get_event_abi(CONTRACT_TOKEN_NETWORK, EVENT_CHANNEL_CLOSED) assert isinstance(abi, dict) with pytest.raises(ValueError): manager.get_event_abi(CONTRACT_TOKEN_NETWORK, 'NonExistant')
def contract_manager_meta(contracts_path): """ See failures in looking up non-existent ABI entries of TokenNetwork and CLOSED """ manager = ContractManager(contracts_path) abi = manager.get_contract_abi(CONTRACT_TOKEN_NETWORK) assert isinstance(abi, list) with pytest.raises(KeyError): manager.get_contract_abi('SomeName') abi = manager.get_event_abi(CONTRACT_TOKEN_NETWORK, ChannelEvent.CLOSED) assert isinstance(abi, dict) with pytest.raises(ValueError): manager.get_event_abi(CONTRACT_TOKEN_NETWORK, 'NonExistant')
def secret_registry_events( secret_registry_address: SecretRegistryAddress, contract_manager: ContractManager) -> SmartContractEvents: return SmartContractEvents( contract_address=Address(secret_registry_address), abi=contract_manager.get_contract_abi(CONTRACT_SECRET_REGISTRY), )
def token_network_events( token_network_address: TokenNetworkAddress, contract_manager: ContractManager) -> SmartContractEvents: return SmartContractEvents( contract_address=Address(token_network_address), abi=contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), )
def token_network_registry_events( token_network_registry_address: TokenNetworkRegistryAddress, contract_manager: ContractManager) -> SmartContractEvents: return SmartContractEvents( contract_address=Address(token_network_registry_address), abi=contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK_REGISTRY), )
def __init__( self, jsonrpc_client: JSONRPCClient, token_address: TokenAddress, contract_manager: ContractManager, ) -> None: contract = jsonrpc_client.new_contract( contract_manager.get_contract_abi(CONTRACT_CUSTOM_TOKEN), Address(token_address)) proxy = ContractProxy(jsonrpc_client, contract) if not is_binary_address(token_address): raise ValueError("token_address must be a valid address") check_address_has_code(jsonrpc_client, Address(token_address), "Token", expected_code=None) self.address = token_address self.client = jsonrpc_client self.node_address = jsonrpc_client.address self.proxy = proxy self.token_lock: RLock = RLock()
def __init__( self, jsonrpc_client, discovery_address, ): contract_manager = ContractManager(CONTRACTS_PRECOMPILED_PATH) contract = jsonrpc_client.new_contract( contract_manager.get_contract_abi(CONTRACT_ENDPOINT_REGISTRY), to_normalized_address(discovery_address), ) proxy = ContractProxy(jsonrpc_client, contract) if not is_binary_address(discovery_address): raise ValueError('discovery_address must be a valid address') check_address_has_code(jsonrpc_client, discovery_address, 'Discovery') try: is_valid_version = compare_versions( proxy.contract.functions.contract_version().call(), EXPECTED_CONTRACTS_VERSION, ) if not is_valid_version: raise ContractVersionMismatch('Incompatible ABI for Discovery') except BadFunctionCallOutput: raise AddressWrongContract('') self.address = discovery_address self.node_address = privatekey_to_address(jsonrpc_client.privkey) self.client = jsonrpc_client self.not_found_address = NULL_ADDRESS self.proxy = proxy
def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, ) -> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=( initial_amount, decimals, token_name, token_symbol, ), ) contract_abi = contract_manager.get_contract_abi( CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address, )
def deploy_token( deploy_client: JSONRPCClient, contract_manager: ContractManager, initial_amount: typing.TokenAmount, decimals: int, token_name: str, token_symbol: str, )-> ContractProxy: token_address = deploy_contract_web3( contract_name=CONTRACT_HUMAN_STANDARD_TOKEN, deploy_client=deploy_client, contract_manager=contract_manager, constructor_arguments=( initial_amount, decimals, token_name, token_symbol, ), ) contract_abi = contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN) return deploy_client.new_contract_proxy( contract_interface=contract_abi, contract_address=token_address, )
def get_channel_participants_from_open_event( token_network: "TokenNetwork", channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockNumber, ) -> Optional[Tuple[Address, Address]]: # For this check it is perfectly fine to use a `latest` block number. # Because the filter is looking just for the OPENED event. to_block = "latest" filter_args = get_filter_args_for_specific_event_from_channel( token_network_address=token_network.address, channel_identifier=channel_identifier, event_name=ChannelEvent.OPENED, contract_manager=contract_manager, from_block=from_block, to_block=to_block, ) events = token_network.proxy.contract.web3.eth.getLogs(filter_args) # There must be only one channel open event per channel identifier if len(events) != 1: return None event = decode_event( contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), events[0]) participant1 = Address(decode_hex(event["args"]["participant1"])) participant2 = Address(decode_hex(event["args"]["participant2"])) return participant1, participant2
def get_all_netting_channel_events( chain: BlockChainService, token_network_address: TokenNetworkAddress, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockSpecification = GENESIS_BLOCK_NUMBER, to_block: BlockSpecification = 'latest', ) -> List[Dict]: """ Helper to get all events of a NettingChannelContract. """ filter_args = get_filter_args_for_all_events_from_channel( token_network_address=token_network_address, channel_identifier=netting_channel_identifier, contract_manager=contract_manager, from_block=from_block, to_block=to_block, ) return get_contract_events( chain, contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), typing.Address(token_network_address), filter_args['topics'], from_block, to_block, )
def __init__( self, jsonrpc_client, discovery_address, contract_manager: ContractManager, ): contract = jsonrpc_client.new_contract( contract_manager.get_contract_abi(CONTRACT_ENDPOINT_REGISTRY), to_normalized_address(discovery_address), ) proxy = ContractProxy(jsonrpc_client, contract) if not is_binary_address(discovery_address): raise ValueError('discovery_address must be a valid address') check_address_has_code(jsonrpc_client, discovery_address, 'Discovery') compare_contract_versions( proxy=proxy, expected_version=contract_manager.contracts_version, contract_name=CONTRACT_ENDPOINT_REGISTRY, address=discovery_address, ) self.address = discovery_address self.node_address = jsonrpc_client.address self.client = jsonrpc_client self.not_found_address = NULL_ADDRESS self.proxy = proxy
def get_netting_channel_closed_events( chain: BlockChainService, token_network_address: Address, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockSpecification = 0, to_block: BlockSpecification = 'latest', ) -> List[Dict]: closed_event_abi = contract_manager.get_event_abi( CONTRACT_TOKEN_NETWORK, ChannelEvent.CLOSED, ) topic_set = construct_event_topic_set( event_abi=closed_event_abi, arguments={'channel_identifier': netting_channel_identifier}, ) if len(topic_set) == 1 and is_list_like(topic_set[0]): topics = topic_set[0] else: topics = topic_set return get_contract_events( chain=chain, abi=contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), contract_address=token_network_address, topics=topics, from_block=from_block, to_block=to_block, )
def get_netting_channel_deposit_events( proxy_manager: ProxyManager, token_network_address: TokenNetworkAddress, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockSpecification = GENESIS_BLOCK_NUMBER, to_block: BlockSpecification = "latest", ) -> List[Dict]: deposit_event_abi = contract_manager.get_event_abi(CONTRACT_TOKEN_NETWORK, ChannelEvent.DEPOSIT) topic_set = construct_event_topic_set( event_abi=deposit_event_abi, arguments={"channel_identifier": netting_channel_identifier}) if len(topic_set) == 1 and is_list_like(topic_set[0]): topics = topic_set[0] else: topics = topic_set return get_contract_events( proxy_manager, contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), Address(token_network_address), topics, from_block, to_block, )
def get_netting_channel_deposit_events( chain: BlockChainService, token_network_address: Address, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockSpecification = GENESIS_BLOCK_NUMBER, to_block: BlockSpecification = 'latest', ) -> List[Dict]: deposit_event_abi = contract_manager.get_event_abi( CONTRACT_TOKEN_NETWORK, ChannelEvent.DEPOSIT, ) topic_set = construct_event_topic_set( event_abi=deposit_event_abi, arguments={'channel_identifier': netting_channel_identifier}, ) if len(topic_set) == 1 and is_list_like(topic_set[0]): topics = topic_set[0] else: topics = topic_set return get_contract_events( chain, contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), token_network_address, topics, from_block, to_block, )
def test_deprecation_immediate_payout(create_account: Callable, custom_token: Contract, service_registry: Contract, web3: Web3) -> None: """When the deprecation switch is on, deposits can be withdrawn immediately.""" # A user makes a deposit A = create_account() minted = service_registry.functions.currentPrice().call() call_and_transact(custom_token.functions.mint(minted), {"from": A}) call_and_transact( custom_token.functions.approve(service_registry.address, minted), {"from": A}) deposit_tx = call_and_transact(service_registry.functions.deposit(minted), {"from": A}) # The user obtains the deposit address deposit_tx_receipt = web3.eth.get_transaction_receipt(deposit_tx) contract_manager = ContractManager( contracts_precompiled_path(version=None)) event_abi = contract_manager.get_event_abi(CONTRACT_SERVICE_REGISTRY, EVENT_REGISTERED_SERVICE) event_data = get_event_data(web3.codec, event_abi, deposit_tx_receipt["logs"][-1]) deposit_address = event_data["args"]["deposit_contract"] # And obtains the Deposit contract instance deposit_abi = contract_manager.get_contract_abi(CONTRACT_DEPOSIT) deposit = web3.eth.contract(abi=deposit_abi, address=deposit_address) # The controller turns on the deprecation switch call_and_transact(service_registry.functions.setDeprecationSwitch(), {"from": DEPLOYER_ADDRESS}) # The user successfully withdraws the deposit call_and_transact(deposit.functions.withdraw(A), {"from": A}) # The user has all the balance it has minted assert minted == custom_token.functions.balanceOf(A).call() # The Deposit contract has destroyed itself assert web3.eth.get_code(deposit.address) == HexBytes("0x")
def get_netting_channel_deposit_events( chain: BlockChainService, token_network_address: Address, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockSpecification = GENESIS_BLOCK_NUMBER, to_block: BlockSpecification = 'latest', ) -> List[Dict]: deposit_event_abi = contract_manager.get_event_abi( CONTRACT_TOKEN_NETWORK, ChannelEvent.DEPOSIT, ) topic_set = construct_event_topic_set( event_abi=deposit_event_abi, arguments={'channel_identifier': netting_channel_identifier}, ) if len(topic_set) == 1 and is_list_like(topic_set[0]): topics = topic_set[0] else: topics = topic_set return get_contract_events( chain, contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), token_network_address, topics, from_block, to_block, )
def query_blockchain_events( web3: Web3, contract_manager: ContractManager, contract_address: Address, contract_name: str, topics: List, from_block: BlockNumber, to_block: BlockNumber, ) -> List[Dict]: """Returns events emmitted by a contract for a given event name, within a certain range. Args: web3: A Web3 instance contract_manager: A contract manager contract_address: The address of the contract to be filtered, can be `None` contract_name: The name of the contract topics: The topics to filter for from_block: The block to start search events to_block: The block to stop searching for events Returns: All matching events """ filter_params = { "fromBlock": from_block, "toBlock": to_block, "address": to_checksum_address(contract_address), "topics": topics, } events = web3.eth.getLogs(filter_params) contract_abi = contract_manager.get_contract_abi(contract_name) return [decode_event(abi=contract_abi, log_=raw_event) for raw_event in events]
def transact_call(key, data): rpc_client = data["client"] contract_manager = ContractManager(contracts_precompiled_path()) action, contract = TRANSACT_ACTIONS[key] log.debug("Fetching ABI..", contract=contract) contract_abi = contract_manager.get_contract_abi(contract) log.debug( "Fetching contract proxy", contract=contract, abi=contract_abi, contract_address=data["contract_address"], ) contract_proxy = rpc_client.new_contract_proxy(contract_abi, data["contract_address"]) log.debug("Transacting..", **data) args = data["amount"], data["target_address"] if action != "mintFor": # The deposit function expects the address first, amount second. args = (data["target_address"], data["amount"]) return contract_proxy.transact(action, data["gas_limit"], *args)
def __init__( self, jsonrpc_client: JSONRPCClient, monitoring_service_address: MonitoringServiceAddress, contract_manager: ContractManager, block_identifier: BlockIdentifier, ): if not is_binary_address(monitoring_service_address): raise ValueError("Expected binary address for monitoring service") check_address_has_code_handle_pruned_block( client=jsonrpc_client, address=Address(monitoring_service_address), contract_name=CONTRACT_MONITORING_SERVICE, expected_code=decode_hex( contract_manager.get_runtime_hexcode(CONTRACT_MONITORING_SERVICE) ), given_block_identifier=block_identifier, ) proxy = jsonrpc_client.new_contract_proxy( abi=contract_manager.get_contract_abi(CONTRACT_MONITORING_SERVICE), contract_address=Address(monitoring_service_address), ) self.address = monitoring_service_address self.client = jsonrpc_client self.contract_manager = contract_manager self.node_address = self.client.address self.proxy = proxy
def __init__( self, jsonrpc_client, discovery_address, contract_manager: ContractManager, ): contract = jsonrpc_client.new_contract( contract_manager.get_contract_abi(CONTRACT_ENDPOINT_REGISTRY), to_normalized_address(discovery_address), ) proxy = ContractProxy(jsonrpc_client, contract) if not is_binary_address(discovery_address): raise ValueError('discovery_address must be a valid address') check_address_has_code(jsonrpc_client, discovery_address, 'Discovery') compare_contract_versions( proxy=proxy, expected_version=contract_manager.contracts_version, contract_name=CONTRACT_ENDPOINT_REGISTRY, address=discovery_address, ) self.address = discovery_address self.node_address = privatekey_to_address(jsonrpc_client.privkey) self.client = jsonrpc_client self.not_found_address = NULL_ADDRESS self.proxy = proxy
def get_all_netting_channel_events( proxy_manager: ProxyManager, token_network_address: TokenNetworkAddress, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockIdentifier = GENESIS_BLOCK_NUMBER, to_block: BlockIdentifier = BLOCK_ID_LATEST, ) -> List[Dict]: # pragma: no unittest """ Helper to get all events of a NettingChannelContract. """ filter_args = get_filter_args_for_all_events_from_channel( token_network_address=token_network_address, channel_identifier=netting_channel_identifier, contract_manager=contract_manager, from_block=from_block, to_block=to_block, ) return get_contract_events( proxy_manager, contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), Address(token_network_address), filter_args["topics"], # type: ignore from_block, to_block, )
def get_netting_channel_closed_events( proxy_manager: ProxyManager, token_network_address: TokenNetworkAddress, netting_channel_identifier: ChannelID, contract_manager: ContractManager, from_block: BlockIdentifier = GENESIS_BLOCK_NUMBER, to_block: BlockIdentifier = BLOCK_ID_LATEST, ) -> List[Dict]: closed_event_abi = contract_manager.get_event_abi(CONTRACT_TOKEN_NETWORK, ChannelEvent.CLOSED) topic_set = construct_event_topic_set( event_abi=closed_event_abi, abi_codec=proxy_manager.client.web3.codec, arguments={"channel_identifier": netting_channel_identifier}, ) return get_contract_events( proxy_manager=proxy_manager, abi=contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), contract_address=Address(token_network_address), topics=topic_set, # type: ignore from_block=from_block, to_block=to_block, )
def register_service( web3: Web3, contract_manager: ContractManager, msc_contract_address: str, private_key: str, deposit: int = 10, # any amount works now ): """Register service with a Monitor service contract""" service_address = private_key_to_address(private_key) assert is_checksum_address(msc_contract_address) assert is_checksum_address(service_address) monitor_contract_abi = contract_manager.get_contract_abi( CONTRACT_MONITORING_SERVICE) monitor_contract = PrivateContract( web3.eth.contract( abi=monitor_contract_abi, address=msc_contract_address, )) bundle_contract_abi = contract_manager.get_contract_abi( CONTRACT_RAIDEN_SERVICE_BUNDLE) raiden_service_bundle_address = to_checksum_address( monitor_contract.functions.rsb().call()) bundle_contract = PrivateContract( web3.eth.contract( abi=bundle_contract_abi, address=raiden_service_bundle_address, )) # approve funds for MSC token_address = to_checksum_address( monitor_contract.functions.token().call()) token_abi = contract_manager.get_contract_abi('Token') token_contract = web3.eth.contract(abi=token_abi, address=token_address) token_contract = PrivateContract(token_contract) tx = token_contract.functions.approve(raiden_service_bundle_address, deposit).transact( private_key=private_key, ) wait_for_transaction_receipt(web3, tx) # register MS tx = bundle_contract.functions.deposit(deposit).transact( private_key=private_key, ) # check if MS is really registered wait_for_transaction_receipt(web3, tx) return bundle_contract.functions.deposits(service_address).call() > 0
def verify_deployed_contract( web3: Web3, contract_manager: ContractManager, deployment_data: 'DeployedContracts', contract_name: str, ) -> Contract: """ Verify deployment info against the chain Verifies: - the runtime bytecode - precompiled data against the chain - information stored in deployment_*.json against the chain, except for the constructor arguments, which have to be checked separately. Returns: (onchain_instance, constructor_arguments) """ contracts = deployment_data['contracts'] contract_address = contracts[contract_name]['address'] contract_instance = web3.eth.contract( abi=contract_manager.get_contract_abi(contract_name), address=contract_address, ) # Check that the deployed bytecode matches the precompiled data blockchain_bytecode = web3.eth.getCode(contract_address).hex() compiled_bytecode = runtime_hexcode( contracts_manager=contract_manager, name=contract_name, ) assert blockchain_bytecode == compiled_bytecode print( f'{contract_name} at {contract_address} ' f'matches the compiled data from contracts.json', ) # Check blockchain transaction hash & block information receipt = web3.eth.getTransactionReceipt( contracts[contract_name]['transaction_hash'], ) assert receipt['blockNumber'] == contracts[contract_name][ 'block_number'], ( f'We have block_number {contracts[contract_name]["block_number"]} ' f'instead of {receipt["blockNumber"]}') assert receipt['gasUsed'] == contracts[contract_name]['gas_cost'], ( f'We have gasUsed {contracts[contract_name]["gas_cost"]} ' f'instead of {receipt["gasUsed"]}') assert receipt['contractAddress'] == contracts[contract_name]['address'], ( f'We have contractAddress {contracts[contract_name]["address"]} ' f'instead of {receipt["contractAddress"]}') # Check the contract version version = contract_instance.functions.contract_version().call() assert version == deployment_data['contracts_version'], \ f'got {version} expected {deployment_data["contracts_version"]}.' \ f'contract_manager has contracts_version {contract_manager.contracts_version}' return contract_instance, contracts[contract_name]['constructor_arguments']
def _get_contract(w3: Web3, contract_name: str): chain_id = int(w3.net.version) manager = ContractManager(contracts_precompiled_path()) contract_data = get_contracts_deployment_info(chain_id) assert contract_data address = contract_data["contracts"][contract_name]["address"] abi = manager.get_contract_abi(contract_name) return w3.eth.contract(abi=abi, address=address)
def abi_of_contract_address( self, contract_manager: ContractManager) -> Dict[Address, ABI]: """ This class knows which ABI is behind each filtered contract address """ tnr_abi = contract_manager.get_contract_abi( CONTRACT_TOKEN_NETWORK_REGISTRY) tn_abi = contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK) secret_registry_abi = contract_manager.get_contract_abi( CONTRACT_SECRET_REGISTRY) abis = { **{ Address(tnr): tnr_abi for tnr in self.token_network_registry_addresses }, **{Address(tn): tn_abi for tn in self.token_network_addresses}, } if self.secret_registry_address: abis[Address(self.secret_registry_address)] = secret_registry_abi return abis
def get_token_network_registry_contract(w3: Web3): chain_id = int(w3.net.version) manager = ContractManager(contracts_precompiled_path()) contract_data = get_contracts_deployment_info(ChainID(chain_id)) assert contract_data address = contract_data["contracts"][CONTRACT_TOKEN_NETWORK_REGISTRY]["address"] abi = manager.get_contract_abi(CONTRACT_TOKEN_NETWORK_REGISTRY) return w3.eth.contract(abi=abi, address=address)
def mint_tokens(w3: Web3, account: Account, token: Erc20Token): contract_manager = ContractManager(contracts_precompiled_path()) token_proxy = w3.eth.contract( address=to_checksum_address(token.address), abi=contract_manager.get_contract_abi(CONTRACT_CUSTOM_TOKEN), ) return send_raw_transaction(w3, account, token_proxy.functions.mint, token.supply, gas=GAS_REQUIRED_FOR_MINT)
def is_service_registered( web3: Web3, contract_manager: ContractManager, msc_contract_address: str, service_address: str, ) -> bool: """Returns true if service is registered in the Monitoring service contract""" assert is_checksum_address(msc_contract_address) assert is_checksum_address(service_address) monitor_contract_abi = contract_manager.get_contract_abi( CONTRACT_MONITORING_SERVICE) monitor_contract = web3.eth.contract(abi=monitor_contract_abi, address=msc_contract_address) bundle_contract_abi = contract_manager.get_contract_abi( CONTRACT_RAIDEN_SERVICE_BUNDLE) raiden_service_bundle_address = to_checksum_address( monitor_contract.functions.rsb().call()) bundle_contract = web3.eth.contract( abi=bundle_contract_abi, address=raiden_service_bundle_address, ) return bundle_contract.functions.deposits(service_address).call() > 0
def add_secret_registry_listener( self, secret_registry_proxy: SecretRegistry, contract_manager: ContractManager, from_block: typing.BlockSpecification = 'latest', ): secret_registry_filter = secret_registry_proxy.secret_registered_filter( from_block=from_block, ) secret_registry_address = secret_registry_proxy.address self.add_event_listener( 'SecretRegistry {}'.format(pex(secret_registry_address)), secret_registry_filter, contract_manager.get_contract_abi(CONTRACT_SECRET_REGISTRY), )
def add_token_network_listener( self, token_network_proxy, contract_manager: ContractManager, from_block: typing.BlockSpecification = 'latest', ): token_network_filter = token_network_proxy.all_events_filter(from_block=from_block) token_network_address = token_network_proxy.address self.add_event_listener( 'TokenNetwork {}'.format(pex(token_network_address)), token_network_filter, contract_manager.get_contract_abi(CONTRACT_TOKEN_NETWORK), )
def __init__( self, jsonrpc_client, token_address, contract_manager: ContractManager, ): contract = jsonrpc_client.new_contract( contract_manager.get_contract_abi(CONTRACT_HUMAN_STANDARD_TOKEN), to_normalized_address(token_address), ) proxy = ContractProxy(jsonrpc_client, contract) if not is_binary_address(token_address): raise ValueError('token_address must be a valid address') check_address_has_code(jsonrpc_client, token_address, 'Token') self.address = token_address self.client = jsonrpc_client self.node_address = privatekey_to_address(jsonrpc_client.privkey) self.proxy = proxy
def contract_manager_meta(contracts_path): manager = ContractManager(contracts_path) abi = manager.get_contract_abi('TokenNetwork') assert isinstance(abi, list) abi = manager.get_event_abi('TokenNetwork', 'ChannelClosed') assert isinstance(abi, dict)