def __init__( self, jsonrpc_client, secret_registry_address, ): if not is_binary_address(secret_registry_address): raise InvalidAddress( 'Expected binary address format for secret registry') check_address_has_code(jsonrpc_client, secret_registry_address, CONTRACT_SECRET_REGISTRY) proxy = jsonrpc_client.new_contract_proxy( CONTRACT_MANAGER.get_contract_abi(CONTRACT_SECRET_REGISTRY), to_normalized_address(secret_registry_address), ) try: if not compare_versions( proxy.contract.functions.contract_version().call(), EXPECTED_CONTRACTS_VERSION, ): raise ContractVersionMismatch( 'Incompatible ABI for SecretRegistry') except BadFunctionCallOutput: raise AddressWrongContract('') self.address = secret_registry_address self.proxy = proxy self.client = jsonrpc_client self.node_address = privatekey_to_address(self.client.privkey) self.open_secret_transactions = dict()
def compare_contract_versions( proxy: ContractProxy, expected_version: str, contract_name: str, address: Address, ) -> None: """Compare version strings of a contract. If not matching raise ContractVersionMismatch. Also may raise AddressWrongContract if the contract contains no code.""" assert isinstance(expected_version, str) try: deployed_version = proxy.contract.functions.contract_version().call() except BadFunctionCallOutput: raise AddressWrongContract('') deployed_version = deployed_version.replace('_', '0') expected_version = expected_version.replace('_', '0') deployed = [int(x) for x in deployed_version.split('.')] expected = [int(x) for x in expected_version.split('.')] if deployed != expected: raise ContractVersionMismatch( f'Provided {contract_name} contract ({to_normalized_address(address)}) ' f'version mismatch. Expected: {expected_version} Got: {deployed_version}', )
def __init__( self, jsonrpc_client, registry_address, ): if not is_binary_address(registry_address): raise InvalidAddress( 'Expected binary address format for token network registry') check_address_has_code(jsonrpc_client, registry_address, CONTRACT_TOKEN_NETWORK_REGISTRY) proxy = jsonrpc_client.new_contract_proxy( CONTRACT_MANAGER.get_contract_abi(CONTRACT_TOKEN_NETWORK_REGISTRY), to_normalized_address(registry_address), ) try: is_valid_version = compare_versions( proxy.contract.functions.contract_version().call(), EXPECTED_CONTRACTS_VERSION, ) except BadFunctionCallOutput: raise AddressWrongContract('') if not is_valid_version: raise ContractVersionMismatch( 'Incompatible ABI for TokenNetworkRegistry') self.address = registry_address self.proxy = proxy self.client = jsonrpc_client self.node_address = privatekey_to_address(self.client.privkey)
def __init__( self, jsonrpc_client, discovery_address, ): 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.client = jsonrpc_client self.not_found_address = NULL_ADDRESS self.proxy = proxy