Relocate NetworksInventory to nucypher.blockchain.eth.networks

pull/1576/head
David Núñez 2020-01-19 23:15:03 +01:00
parent 3da6bdf087
commit f1daae2463
7 changed files with 52 additions and 37 deletions

View File

@ -115,7 +115,7 @@ class NucypherTokenActor:
self.checksum_address = checksum_address # type: str
self.registry = registry
if domains: # FIXME: This is horrible, but I'm forced to do it as StakeHolder config inherits from character config, which has 'domains'
if domains: # StakeHolder config inherits from character config, which has 'domains' - #1580
self.network = list(domains)[0]
self.token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=self.registry) # type: NucypherTokenAgent
self._saved_receipts = list() # track receipts of transmitted transactions

View File

@ -0,0 +1,43 @@
"""
This file is part of nucypher.
nucypher is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
nucypher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
class NetworksInventory: # TODO: See #1564
MAINNET = 'mainnet'
MIRANDA = 'miranda'
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 = {
MAINNET: 1, # Ethereum Mainnet
MIRANDA: 5, # Goerli
FRANCES: 5, # Goerli
CASSANDRA: 5, # Goerli
}
networks = tuple(__to_ethereum_chain_id.keys())
@classmethod
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:
return 1337 # TODO: what about chain id when testing?

View File

@ -28,37 +28,11 @@ import requests
from constant_sorrow.constants import REGISTRY_COMMITTED, NO_REGISTRY_SOURCE
from twisted.logger import Logger
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
from nucypher.blockchain.eth.constants import PREALLOCATION_ESCROW_CONTRACT_NAME
class NetworksInventory: # TODO: Rename & relocate. See also #1564
MAINNET = 'mainnet'
MIRANDA = 'miranda'
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
FRANCES: 5, # Goerli
CASSANDRA: 5, # Goerli
}
networks = tuple(__to_ethereum_chain_id.keys())
@classmethod
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:
return 1337 # TODO: what about chain id when testing?
class CanonicalRegistrySource(ABC):
logger = Logger('RegistrySource')

View File

@ -14,7 +14,7 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import functools
import os
import click
@ -26,9 +26,9 @@ from nucypher.blockchain.eth.registry import (
BaseContractRegistry,
InMemoryContractRegistry,
RegistrySourceManager,
GithubRegistrySource,
NetworksInventory
GithubRegistrySource
)
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.token import NU
from nucypher.cli.actions import (
get_client_password,

View File

@ -35,9 +35,9 @@ from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import (
BaseContractRegistry,
InMemoryContractRegistry,
LocalContractRegistry,
NetworksInventory
LocalContractRegistry
)
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.config.base import BaseConfiguration
from nucypher.config.keyring import NucypherKeyring
from nucypher.config.storages import NodeStorage, ForgetfulNodeStorage, LocalFileBasedNodeStorage

View File

@ -24,11 +24,9 @@ import tempfile
import time
from datetime import datetime
from random import SystemRandom
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
@ -136,7 +134,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 # FIXME?
TEMPORARY_DOMAIN = ":TEMPORARY_DOMAIN:" # for use with `--dev` node runtimes and tests
GETH_DEV_URI = f'ipc://{BASE_TEMP_DIR}/geth.ipc' # Standard IPC path for `geth --dev`

View File

@ -47,11 +47,11 @@ from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import (
InMemoryContractRegistry,
RegistrySourceManager,
NetworksInventory,
BaseContractRegistry,
IndividualAllocationRegistry,
CanonicalRegistrySource
)
from nucypher.blockchain.eth.networks import NetworksInventory
from nucypher.blockchain.eth.sol.compile import SolidityCompiler
from nucypher.blockchain.eth.token import NU
from nucypher.characters.lawful import Enrico, Bob