Include private testnet generic genesis json deploy file, localize chain init to dev-only processes

pull/1040/head
Kieran Prasch 2019-04-27 23:02:59 +03:00
parent 6ee4e5fb7a
commit 0239a4f88f
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
3 changed files with 35 additions and 12 deletions

View File

@ -0,0 +1,20 @@
{
"coinbase" : "0xA87722643685B38D37ecc7637ACA9C1E09c8C5e1",
"difficulty" : "10000",
"extraData" : "0x",
"gasLimit" : "8000000",
"nonce" : "0x0112358132134550",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00",
"alloc": {
"0xA87722643685B38D37ecc7637ACA9C1E09c8C5e1": {"balance": "100000000000000000000000"}
},
"config": {
"chainId": 112358,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0
}
}

View File

@ -13,7 +13,7 @@ from geth.chain import (
from geth.process import BaseGethProcess from geth.process import BaseGethProcess
from twisted.logger import Logger from twisted.logger import Logger
from nucypher.config.constants import DEFAULT_CONFIG_ROOT from nucypher.config.constants import DEFAULT_CONFIG_ROOT, BASE_DIR, DEPLOY_DIR
NUCYPHER_CHAIN_IDS = { NUCYPHER_CHAIN_IDS = {
'devnet': 112358, 'devnet': 112358,
@ -22,8 +22,6 @@ NUCYPHER_CHAIN_IDS = {
class NuCypherGethProcess(BaseGethProcess, LoggingMixin): class NuCypherGethProcess(BaseGethProcess, LoggingMixin):
GENESIS_FILENAME = 'genesis.json'
GENESIS_SOURCE_FILEPATH = os.path.join('deploy', 'geth', GENESIS_FILENAME)
IPC_PROTOCOL = 'ipc' IPC_PROTOCOL = 'ipc'
IPC_FILENAME = 'geth.ipc' IPC_FILENAME = 'geth.ipc'
VERBOSITY = 5 VERBOSITY = 5
@ -46,15 +44,6 @@ class NuCypherGethProcess(BaseGethProcess, LoggingMixin):
super().start() super().start()
self.wait_for_ipc(timeout=timeout) self.wait_for_ipc(timeout=timeout)
def initialize_blockchain(self, geth_kwargs: dict) -> None:
log = Logger('nucypher-geth-init')
with open(self.GENESIS_SOURCE_FILEPATH) as file:
genesis_data = json.loads(file.read())
log.info(f"Read genesis file '{self.GENESIS_SOURCE_FILEPATH}'")
log.info(f'Initializing new blockchain database and genesis block.')
initialize_chain(genesis_data, **geth_kwargs)
class NuCypherGethDevProcess(NuCypherGethProcess): class NuCypherGethDevProcess(NuCypherGethProcess):
@ -76,6 +65,9 @@ class NuCypherGethDevProcess(NuCypherGethProcess):
class NuCypherGethDevnetProcess(NuCypherGethProcess): class NuCypherGethDevnetProcess(NuCypherGethProcess):
GENESIS_FILENAME = 'testnet_genesis.json'
GENESIS_SOURCE_FILEPATH = os.path.join(DEPLOY_DIR, GENESIS_FILENAME)
P2P_PORT = 30303 P2P_PORT = 30303
_CHAIN_NAME = 'devnet' _CHAIN_NAME = 'devnet'
__CHAIN_ID = NUCYPHER_CHAIN_IDS[_CHAIN_NAME] __CHAIN_ID = NUCYPHER_CHAIN_IDS[_CHAIN_NAME]
@ -127,6 +119,16 @@ class NuCypherGethDevnetProcess(NuCypherGethProcess):
super().__init__(geth_kwargs) super().__init__(geth_kwargs)
@classmethod
def initialize_blockchain(cls, geth_kwargs: dict) -> None:
log = Logger('nucypher-geth-init')
with open(cls.GENESIS_SOURCE_FILEPATH) as file:
genesis_data = json.loads(file.read())
log.info(f"Read genesis file '{cls.GENESIS_SOURCE_FILEPATH}'")
log.info(f'Initializing new blockchain database and genesis block.')
initialize_chain(genesis_data, **geth_kwargs)
@classmethod @classmethod
def ensure_account_exists(cls, password: str, data_dir: str): def ensure_account_exists(cls, password: str, data_dir: str):
geth_kwargs = {'network_id': str(cls.__CHAIN_ID), geth_kwargs = {'network_id': str(cls.__CHAIN_ID),

View File

@ -29,6 +29,7 @@ from nucypher.blockchain.eth import sol
# Base Filepaths # Base Filepaths
BASE_DIR = abspath(dirname(dirname(nucypher.__file__))) BASE_DIR = abspath(dirname(dirname(nucypher.__file__)))
DEPLOY_DIR = os.path.join(BASE_DIR, 'deploy')
PROJECT_ROOT = abspath(dirname(nucypher.__file__)) PROJECT_ROOT = abspath(dirname(nucypher.__file__))
CONTRACT_ROOT = os.path.join(abspath(dirname(sol.__file__)), 'source', 'contracts') CONTRACT_ROOT = os.path.join(abspath(dirname(sol.__file__)), 'source', 'contracts')