Remove populus from Pipfile (also add ipbd)

pull/249/head
Kieran Prasch 2018-04-13 15:21:15 -07:00
parent 5f9b8c48ed
commit 9cd500bea5
4 changed files with 30 additions and 23 deletions

View File

@ -21,8 +21,7 @@ hendrix = {git = "https://github.com/hendrix/hendrix", ref = "tags/3.0.0rc1"}
constantSorrow = {git = "https://github.com/nucypher/constantSorrow.git", ref = "kms-depend"} constantSorrow = {git = "https://github.com/nucypher/constantSorrow.git", ref = "kms-depend"}
bytestringSplitter = {git = "https://github.com/nucypher/byteStringSplitter.git", ref = "eaa1df2433362190f30bc6e400570f0331980ebb"} bytestringSplitter = {git = "https://github.com/nucypher/byteStringSplitter.git", ref = "eaa1df2433362190f30bc6e400570f0331980ebb"}
appdirs = "*" appdirs = "*"
populus = {git = "https://github.com/nucypher/Bropulus.git"} eth-tester = "==0.1.0b23"
eth-tester = "*"
py-evm = "*" py-evm = "*"
[dev-packages] [dev-packages]
@ -34,6 +33,7 @@ ipython = "*"
appdirs = "*" appdirs = "*"
codecov = "*" codecov = "*"
py-solc = "*" py-solc = "*"
ipdb = "*"
[pipenv] [pipenv]
allow_prereleases = true allow_prereleases = true

View File

@ -5,9 +5,7 @@ from typing import Tuple, ClassVar, Dict
from eth_tester import EthereumTester, PyEVMBackend from eth_tester import EthereumTester, PyEVMBackend
from web3 import Web3, EthereumTesterProvider from web3 import Web3, EthereumTesterProvider
from web3.contract import ConciseContract from web3.contract import ConciseContract, Contract
from web3.contract import Contract
from web3.providers.tester import EthereumTesterProvider
from nkms.blockchain.eth.sol.compile import compile_interfaces, SolidityConfig from nkms.blockchain.eth.sol.compile import compile_interfaces, SolidityConfig
@ -89,7 +87,7 @@ class Registrar:
WARNING: Unless you are developing the KMS/work at NuCypher, you most WARNING: Unless you are developing the KMS/work at NuCypher, you most
likely won't ever need to use this. likely won't ever need to use this.
""" """
__DEFAULT_REGISTRAR_FILEPATH = None # TODO __DEFAULT_REGISTRAR_FILEPATH = os.path.join(_DEFAULT_CONFIGURATION_DIR, 'registrar.json')
__DEFAULT_CHAIN_NAME = 'tester' __DEFAULT_CHAIN_NAME = 'tester'
class NoKnownContract(KeyError): class NoKnownContract(KeyError):
@ -189,7 +187,7 @@ class Provider:
if provider_backend is None: if provider_backend is None:
# https: // github.com / ethereum / eth - tester # available-backends # https: // github.com / ethereum / eth - tester # available-backends
eth_tester = EthereumTester(backend=PyEVMBackend()) # TODO: Discuss backend choice eth_tester = EthereumTester(backend=PyEVMBackend()) # TODO: Discuss backend choice
provider_backend = EthereumTesterProvider(ethereum_tester=eth_tester, api_endpoints=None) provider_backend = EthereumTesterProvider(ethereum_tester=eth_tester) # , api_endpoints=None)
self.provider = provider_backend self.provider = provider_backend
self.w3 = Web3(self.provider) self.w3 = Web3(self.provider)
@ -197,7 +195,9 @@ class Provider:
registrar = Registrar() # TODO: make a default registrar = Registrar() # TODO: make a default
self.__registrar = registrar self.__registrar = registrar
self.__contract_cache = self.cache_contracts()
self.__contract_cache = None # set on the next line
self.cache_contracts(compile=True)
@staticmethod @staticmethod
def __compile(config: SolidityConfig=None) -> Dict[str, Contract]: def __compile(config: SolidityConfig=None) -> Dict[str, Contract]:
@ -215,21 +215,21 @@ class Provider:
web3_contracts = dict() web3_contracts = dict()
for contract_name, interface in interfaces.items(): for contract_name, interface in interfaces.items():
bytecode = None if contract_factory is ConciseContract else interface['bin'] bytecode = None if contract_factory is ConciseContract else interface['bin']
contract = self.w3.eth.contract(abi=interface['abi'], contract = self.w3.eth.contract(abi=interface['abi'],
bytecode=bytecode, # Optional, needed for deployment bytecode=bytecode, # Optional, needed for deployment
ContractFactoryClass=contract_factory) ContractFactoryClass=contract_factory)
web3_contracts.update(contract_name=contract) web3_contracts[contract_name] = contract
return web3_contracts return web3_contracts
def cache_contracts(self, compile=False): def cache_contracts(self, compile: bool=False) -> None:
"""Loads from registrar or compiles""" """Loads from contract interface data registrar or compiles"""
if compile is False: if compile is False:
records = list(self.__registrar.get_chain_data().keys()) contract_records = self.__registrar.get_chain_data()
interfaces = {} # TODO interfaces = {name: contract_records[name]['abi'] for name in contract_records}
contracts = self.__make_web3_contracts(interfaces)
else: else:
interfaces = self.__compile() interfaces = self.__compile()
contracts = self.__make_web3_contracts(interfaces) contracts = self.__make_web3_contracts(interfaces)
@ -239,16 +239,23 @@ class Provider:
contract = ConciseContract(self.__contract_cache[contract_name]) contract = ConciseContract(self.__contract_cache[contract_name])
return contract return contract
def deploy_contract(self, contract_name: str, deploy_transaction: dict) -> Tuple[str, str]: def deploy_contract(self, contract_name: str, *args, **kwargs) -> Tuple[str, str]:
# transaction = {'from': w3.eth.accounts[0], 'gas': 410000}
txhash = self.__contract_cache[contract_name].deploy(transaction=deploy_transaction) contract = self.__contract_cache[contract_name]
address = self.w3.eth.getTransactionReceipt(txhash)['contractAddress'] deploy_bytecode = contract.constructor(*args, **kwargs).buildTransaction()
cached_contract = self.__contract_cache[contract_name] # TODO: Handlle KeyError txhash = self.w3.eth.sendTransaction(deploy_bytecode) # deploy!
self.__registrar.enroll(contract_name=contract_name, receipt = self.w3.eth.getTransactionReceipt(txhash)
contract_address=address, address = receipt['contractAddress']
contract_abi=cached_contract.abi)
try:
cached_contract = self.__contract_cache[contract_name]
except KeyError:
raise # TODO
else:
self.__registrar.enroll(contract_name=contract_name,
contract_address=address,
contract_abi=cached_contract.abi)
return address, txhash return address, txhash

View File

@ -20,7 +20,7 @@ class KMSConfigurationError(RuntimeError):
class EthereumConfig: class EthereumConfig:
""" """
TODO TODO: Unmock
""" """
def __init__(self, registrar=None, provider=None): def __init__(self, registrar=None, provider=None):

View File