From 595293c4b55ea13bb37f399c80404eaa1cf50951 Mon Sep 17 00:00:00 2001 From: Damon C Date: Tue, 18 Jun 2019 11:49:43 -0700 Subject: [PATCH] cleanup access to blockchain.client properties --- nucypher/blockchain/eth/actors.py | 4 +- nucypher/blockchain/eth/interfaces.py | 41 ++----------------- nucypher/config/node.py | 4 +- .../eth/clients/test_mocked_clients.py | 30 +++++++------- 4 files changed, 23 insertions(+), 56 deletions(-) diff --git a/nucypher/blockchain/eth/actors.py b/nucypher/blockchain/eth/actors.py index bcd8c6411..b2d880d7f 100644 --- a/nucypher/blockchain/eth/actors.py +++ b/nucypher/blockchain/eth/actors.py @@ -105,7 +105,7 @@ class NucypherTokenActor: @property def eth_balance(self) -> Decimal: """Return this actors's current ETH balance""" - balance = self.blockchain.get_balance(self.checksum_address) + balance = self.blockchain.client.get_balance(self.checksum_address) return self.blockchain.fromWei(balance, 'ether') @property @@ -201,7 +201,7 @@ class Deployer(NucypherTokenActor): if Deployer._upgradeable: if not plaintext_secret: raise ValueError("Upgrade plaintext_secret must be passed to deploy an upgradeable contract.") - secret_hash = self.blockchain.keccak(bytes(plaintext_secret, encoding='utf-8')) + secret_hash = self.blockchain.client.keccak(bytes(plaintext_secret, encoding='utf-8')) txhashes = deployer.deploy(secret_hash=secret_hash, gas_limit=gas_limit) else: txhashes = deployer.deploy(gas_limit=gas_limit) diff --git a/nucypher/blockchain/eth/interfaces.py b/nucypher/blockchain/eth/interfaces.py index 54afe8ff5..9415d4c85 100644 --- a/nucypher/blockchain/eth/interfaces.py +++ b/nucypher/blockchain/eth/interfaces.py @@ -171,39 +171,6 @@ class BlockchainInterface: r = '{name}({uri})'.format(name=self.__class__.__name__, uri=self.provider_uri) return r - def __getattr__(self, name): - """ - - MAGIC... - - allows the interface class to defer to methods of its client - or its client.w3 - - for example: - methods/properties of w3 can be called through eg. interface.toWei() - if a particular eth provider needs a different method, - override that method for that provider's client - """ - - # does Blockchain have this attr/method? - if name not in self.__dict__: - - # do we have a client? - if self.client is not NO_BLOCKCHAIN_CONNECTION: - - # does the client have this property/method? - # most likely it is because of an implementation difference - # between parity/geth/etc. - if hasattr(self.client, name): - return getattr(self.client, name) - - # ok, does w3 have it? - if hasattr(self.client.w3, name): - return getattr(self.client.w3, name) - - # return the default getattr behavior (could be an AttributeError) - return object.__getattribute__(self, name) - def _configure_registry(self, fetch_registry: bool = True): RegistryClass = EthereumContractRegistry._get_registry_class(local=self.client.is_local) if fetch_registry: @@ -230,7 +197,7 @@ class BlockchainInterface: # For use with Proof-Of-Authority test-blockchains if self.poa is True: self.log.debug('Injecting POA middleware at layer 0') - self.middleware_onion.inject(geth_poa_middleware, layer=0) + self.client.w3.middleware_onion.inject(geth_poa_middleware, layer=0) def __connect(self, provider: Web3Providers = None, @@ -253,8 +220,8 @@ class BlockchainInterface: # Connect Web3 Instance try: - w3 = self.Web3(provider=self.__provider) - self.client = Web3Client.from_w3(w3=w3) + self.w3 = self.Web3(provider=self.__provider) + self.client = Web3Client.from_w3(w3=self.w3) except requests.ConnectionError: # RPC raise self.ConnectionFailed(f'Connection Failed - {str(self.provider_uri)} - is RPC enabled?') except FileNotFoundError: # IPC File Protocol @@ -268,7 +235,7 @@ class BlockchainInterface: # Wait for chaindata sync if sync_now: - self.sync() + self.client.sync() return self.is_connected diff --git a/nucypher/config/node.py b/nucypher/config/node.py index 083f38a45..f86a1dce9 100644 --- a/nucypher/config/node.py +++ b/nucypher/config/node.py @@ -284,7 +284,7 @@ class CharacterConfiguration(BaseConfiguration): if not os.path.exists(path): message = 'Missing configuration file or directory: {}.' if 'registry' in path: - message += ' Did you mean to pass --federated-only?' + message += ' Did you mean to pass --federated-only?' raise CharacterConfiguration.InvalidConfiguration(message.format(path)) return True @@ -444,7 +444,7 @@ class CharacterConfiguration(BaseConfiguration): self.connect_to_blockchain() if not self.blockchain.client.accounts: raise self.ConfigurationError(f'Web3 provider "{self.provider_uri}" does not have any accounts') - self.checksum_address = self.blockchain.etherbase + self.checksum_address = self.blockchain.client.etherbase self.keyring = NucypherKeyring.generate(password=password, keyring_root=self.keyring_root, diff --git a/tests/blockchain/eth/clients/test_mocked_clients.py b/tests/blockchain/eth/clients/test_mocked_clients.py index f57329001..f37667874 100644 --- a/tests/blockchain/eth/clients/test_mocked_clients.py +++ b/tests/blockchain/eth/clients/test_mocked_clients.py @@ -88,29 +88,29 @@ class GanacheClientTestInterface(BlockchainInterfaceTestBase): def test_geth_web3_client(): interface = GethClientTestBlockchain(provider_uri='file:///ipc.geth', sync_now=False) assert isinstance(interface.client, GethClient) - assert interface.node_technology == 'Geth' - assert interface.node_version == 'v1.4.11-stable-fed692f6' - assert interface.platform == 'darwin' - assert interface.backend == 'go1.7' + assert interface.client.node_technology == 'Geth' + assert interface.client.node_version == 'v1.4.11-stable-fed692f6' + assert interface.client.platform == 'darwin' + assert interface.client.backend == 'go1.7' - assert interface.is_local is False - assert interface.chain_id == 5 + assert interface.client.is_local is False + assert interface.client.chain_id == 5 def test_parity_web3_client(): interface = ParityClientTestInterface(provider_uri='file:///ipc.parity', sync_now=False) assert isinstance(interface.client, ParityClient) - assert interface.node_technology == 'Parity-Ethereum' - assert interface.node_version == 'v2.5.1-beta-e0141f8-20190510' - assert interface.platform == 'x86_64-linux-gnu' - assert interface.backend == 'rustc1.34.1' + assert interface.client.node_technology == 'Parity-Ethereum' + assert interface.client.node_version == 'v2.5.1-beta-e0141f8-20190510' + assert interface.client.platform == 'x86_64-linux-gnu' + assert interface.client.backend == 'rustc1.34.1' def test_ganache_web3_client(): interface = GanacheClientTestInterface(provider_uri='http://ganache:8445', sync_now=False) assert isinstance(interface.client, GanacheClient) - assert interface.node_technology == 'EthereumJS TestRPC' - assert interface.node_version == 'v2.1.5' - assert interface.platform is None - assert interface.backend == 'ethereum-js' - assert interface.is_local + assert interface.client.node_technology == 'EthereumJS TestRPC' + assert interface.client.node_version == 'v2.1.5' + assert interface.client.platform is None + assert interface.client.backend == 'ethereum-js' + assert interface.client.is_local