def manager_by_token(self, token_address): """ Find the channel manager for `token_address` and return a proxy to interact with it. If the token is not already registered it raises `JSONRPCClientReplyError`, since we try to instantiate a Channel manager with an empty address. """ if token_address not in self.token_to_channelmanager: token = self.token(token_address) # check that the token exists manager_address = self.default_registry.manager_address_by_token( token.address) if manager_address == '': raise NoTokenManager( 'Manager for token 0x{} does not exist'.format( (str(token_address).encode('hex')))) manager = ChannelManager( self.client, address_decoder(manager_address), poll_timeout=self.poll_timeout, ) self.token_to_channelmanager[token_address] = manager self.address_to_channelmanager[manager_address] = manager return self.token_to_channelmanager[token_address]
def manager_by_token(self, token_address): """ Find the channel manager for `token_address` and return a proxy to interact with it. If the token is not already registered it raises `EthNodeCommunicationError`, since we try to instantiate a Channel manager with an empty address. """ if not isaddress(token_address): raise ValueError('token_address must be a valid address') if token_address not in self.token_to_channelmanager: check_address_has_code( self.client, token_address) # check that the token exists manager_address = self.manager_address_by_token(token_address) if manager_address is None: raise NoTokenManager( 'Manager for token 0x{} does not exist'.format( token_address.encode('hex'))) manager = ChannelManager( self.client, manager_address, self.startgas, self.gasprice, self.poll_timeout, ) self.token_to_channelmanager[token_address] = manager self.address_to_channelmanager[manager_address] = manager return self.token_to_channelmanager[token_address]
def token_network_by_token(self, token_address: typing.TokenAddress): """ Find the token network for `token_address` and return a proxy to interact with it. If the token is not already registered it raises `EthNodeCommunicationError`, since we try to instantiate a Token Network with an empty address. """ if not is_binary_address(token_address): raise InvalidAddress('Expected binary address format for token') if token_address not in self.token_to_tokennetwork: check_address_has_code( self.client, token_address) # check that the token exists token_network_address = self.get_token_network(token_address) if token_network_address is None: raise NoTokenManager( 'TokenNetwork for token 0x{} does not exist'.format( hexlify(token_address)), ) token_network = TokenNetwork( self.client, token_network_address, ) self.token_to_tokennetwork[token_address] = token_network self.address_to_tokennetwork[token_network_address] = token_network return self.token_to_tokennetwork[token_address]