cleanup access to blockchain.client properties

pull/1029/head
Damon C 2019-06-18 11:49:43 -07:00 committed by David Núñez
parent 898925c8ad
commit 595293c4b5
4 changed files with 23 additions and 56 deletions

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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