Define and use a default network. For the moment the 'unknown' placeholder

pull/1576/head
David Núñez 2020-01-19 02:50:18 +01:00
parent fe55ffc42c
commit 2814dc51b1
7 changed files with 26 additions and 12 deletions

View File

@ -39,6 +39,9 @@ class NetworksInventory: # TODO: Rename & relocate. See also #1564
FRANCES = 'frances'
CASSANDRA = 'cassandra'
UNKNOWN = 'unknown' # TODO: Is there a better way to signal an unknown network?
DEFAULT = UNKNOWN # TODO: This assumes we DON'T have a default. Is that OK? - #1496
__to_ethereum_chain_id = { # TODO: what about chain id when testing?
MAINNET: 1, # Ethereum Mainnet
MIRANDA: 5, # Goerli
@ -49,7 +52,7 @@ class NetworksInventory: # TODO: Rename & relocate. See also #1564
networks = tuple(__to_ethereum_chain_id.keys())
@classmethod
def get_ethereum_chain_id(cls, network):
def get_ethereum_chain_id(cls, network): # TODO: Use this (where?) to make sure we're in the right chain
try:
return cls.__to_ethereum_chain_id[network]
except KeyError:
@ -179,7 +182,7 @@ class RegistrySourceManager:
def get_primary_sources(cls):
return [source for source in cls.__FALLBACK_CHAIN if source.is_primary]
def fetch_latest_publication(self, registry_class, network: str = 'goerli'): # TODO: see #1496
def fetch_latest_publication(self, registry_class, network: str = NetworksInventory.DEFAULT): # TODO: see #1496
"""
Get the latest contract registry data available from a registry source chain.
"""
@ -278,7 +281,7 @@ class BaseContractRegistry(ABC):
raise NotImplementedError
@classmethod
def from_latest_publication(cls, *args, source_manager=None, network: str = 'goerli', **kwargs) -> 'BaseContractRegistry':
def from_latest_publication(cls, *args, source_manager=None, network: str = NetworksInventory.DEFAULT, **kwargs) -> 'BaseContractRegistry': # FIXME: entry point to fix #1496, #1564
"""
Get the latest contract registry available from a registry source chain.
"""

View File

@ -191,7 +191,7 @@ class Character(Learner):
#
self.provider_uri = provider_uri
if not self.federated_only:
self.registry = registry or InMemoryContractRegistry.from_latest_publication()
self.registry = registry or InMemoryContractRegistry.from_latest_publication(domains[0]) # FIXME: entry point to fix #1496, #1564
else:
self.registry = NO_BLOCKCHAIN_CONNECTION.bool_value(False)

View File

@ -386,7 +386,8 @@ def select_client_account(emitter,
prompt: str = None,
default: int = 0,
registry=None,
show_balances: bool = True
show_balances: bool = True,
network: str = None
) -> str:
"""
Note: Setting show_balances to True, causes an eager contract and blockchain connection.
@ -404,7 +405,7 @@ def select_client_account(emitter,
token_agent = None
if show_balances:
if not registry:
registry = InMemoryContractRegistry.from_latest_publication()
registry = InMemoryContractRegistry.from_latest_publication(network)
token_agent = NucypherTokenAgent(registry=registry)
# Real wallet accounts
@ -463,6 +464,7 @@ def handle_client_account_for_staking(emitter,
client_account = select_client_account(prompt="Select staking account",
emitter=emitter,
registry=stakeholder.registry,
network=stakeholder.domains[0], # FIXME: 1496
provider_uri=stakeholder.wallet.blockchain.provider_uri)
staking_address = client_account

View File

@ -210,7 +210,7 @@ def download_registry(general_config, config_root, registry_outfile, network, fo
prompt = f"Fetch and download latest contract registry from {github_source}?"
click.confirm(prompt, abort=True)
try:
registry = InMemoryContractRegistry.from_latest_publication(source_manager=source_manager)
registry = InMemoryContractRegistry.from_latest_publication(source_manager=source_manager, network=network)
except RegistrySourceManager.NoSourcesAvailable:
emitter.message("Registry not available.", color="red")
raise click.Abort

View File

@ -28,6 +28,7 @@ from nucypher.cli.options import (
group_options,
option_geth,
option_light,
option_network,
option_poa,
option_provider_uri,
option_registry_filepath,
@ -40,12 +41,13 @@ class RegistryOptions:
__option_name__ = 'registry_options'
def __init__(self, provider_uri, geth, poa, registry_filepath, light):
def __init__(self, provider_uri, geth, poa, registry_filepath, light, network):
self.provider_uri = provider_uri
self.geth = geth
self.poa = poa
self.registry_filepath = registry_filepath
self.light = light
self.network = network
def get_registry(self, emitter, debug):
try:
@ -74,7 +76,7 @@ class RegistryOptions:
if self.registry_filepath:
registry = LocalContractRegistry(filepath=self.registry_filepath)
else:
registry = InMemoryContractRegistry.from_latest_publication()
registry = InMemoryContractRegistry.from_latest_publication(network=self.network)
return registry
@ -86,6 +88,7 @@ group_registry_options = group_options(
poa=option_poa,
light=option_light,
registry_filepath=option_registry_filepath,
network=option_network,
)

View File

@ -32,7 +32,12 @@ from twisted.logger import Logger
from umbral.signing import Signature
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import BaseContractRegistry, InMemoryContractRegistry, LocalContractRegistry
from nucypher.blockchain.eth.registry import (
BaseContractRegistry,
InMemoryContractRegistry,
LocalContractRegistry,
NetworksInventory
)
from nucypher.config.base import BaseConfiguration
from nucypher.config.keyring import NucypherKeyring
from nucypher.config.storages import NodeStorage, ForgetfulNodeStorage, LocalFileBasedNodeStorage
@ -50,7 +55,7 @@ class CharacterConfiguration(BaseConfiguration):
CHARACTER_CLASS = NotImplemented
DEFAULT_CONTROLLER_PORT = NotImplemented
DEFAULT_DOMAIN = 'goerli' # FIXME: entry point to fix #1496, #1564
DEFAULT_DOMAIN = NetworksInventory.DEFAULT # FIXME: entry point to fix #1496, #1564
DEFAULT_NETWORK_MIDDLEWARE = RestMiddleware
TEMP_CONFIGURATION_DIR_PREFIX = 'tmp-nucypher'

View File

@ -28,6 +28,7 @@ from string import digits, ascii_uppercase
from web3 import Web3
from nucypher.blockchain.eth.registry import NetworksInventory
from nucypher.blockchain.eth.token import NU
from nucypher.config.characters import UrsulaConfiguration
from nucypher.config.constants import BASE_DIR
@ -135,7 +136,7 @@ MOCK_CUSTOM_INSTALLATION_PATH_2 = '/tmp/nucypher-tmp-test-custom-2-{}'.format(ti
MOCK_REGISTRY_FILEPATH = os.path.join(BASE_TEMP_DIR, f'{BASE_TEMP_PREFIX}mock-registry-{datetime.now().strftime(DATETIME_FORMAT)}.json')
TEMPORARY_DOMAIN = ':TEMPORARY_DOMAIN:' # for use with `--dev` node runtimes
TEMPORARY_DOMAIN = NetworksInventory.UNKNOWN # for use with `--dev` node runtimes # FIXME?
GETH_DEV_URI = f'ipc://{BASE_TEMP_DIR}/geth.ipc' # Standard IPC path for `geth --dev`