mirror of https://github.com/nucypher/nucypher.git
Ensure accounts CLI can connect to blockchain with defaults and overrides; Do not validate blank registry.
parent
f791e616ed
commit
3337cdc994
24
cli/main.py
24
cli/main.py
|
@ -126,7 +126,7 @@ class NucypherClickConfig:
|
||||||
if self.compile:
|
if self.compile:
|
||||||
click.confirm("Compile solidity source?", abort=True)
|
click.confirm("Compile solidity source?", abort=True)
|
||||||
self.blockchain = Blockchain.connect(provider_uri=self.provider_uri,
|
self.blockchain = Blockchain.connect(provider_uri=self.provider_uri,
|
||||||
registry_filepath=self.registry_filepath,
|
registry_filepath=self.registry_filepath or self.node_configuration.registry_filepath,
|
||||||
deployer=self.deployer,
|
deployer=self.deployer,
|
||||||
compile=self.compile)
|
compile=self.compile)
|
||||||
if self.poa:
|
if self.poa:
|
||||||
|
@ -214,6 +214,7 @@ def cli(config,
|
||||||
|
|
||||||
# Store config data
|
# Store config data
|
||||||
config.verbose = verbose
|
config.verbose = verbose
|
||||||
|
|
||||||
config.dev = dev
|
config.dev = dev
|
||||||
config.federated_only = federated_only
|
config.federated_only = federated_only
|
||||||
config.config_root = config_root
|
config.config_root = config_root
|
||||||
|
@ -309,19 +310,22 @@ def accounts(config, action, checksum_address):
|
||||||
#
|
#
|
||||||
# Initialize
|
# Initialize
|
||||||
#
|
#
|
||||||
|
config.get_node_configuration()
|
||||||
if not config.federated_only:
|
if not config.federated_only:
|
||||||
config.connect_to_blockchain()
|
config.connect_to_blockchain()
|
||||||
|
config.connect_to_contracts()
|
||||||
|
|
||||||
def __collect_transfer_details(denomination: str):
|
if not checksum_address:
|
||||||
destination = click.prompt("Enter destination checksum_address")
|
checksum_address = config.blockchain.interface.w3.eth.coinbase
|
||||||
if not is_checksum_address(destination):
|
click.echo("WARNING: No checksum address specified - Using the node's default account.")
|
||||||
click.echo("{} is not a valid checksum checksum_address".format(destination))
|
|
||||||
raise click.Abort()
|
|
||||||
amount = click.prompt("Enter amount of {} to transfer".format(denomination), type=int)
|
|
||||||
return destination, amount
|
|
||||||
|
|
||||||
config.connect_to_contracts()
|
def __collect_transfer_details(denomination: str):
|
||||||
config.get_node_configuration()
|
destination = click.prompt("Enter destination checksum_address")
|
||||||
|
if not is_checksum_address(destination):
|
||||||
|
click.echo("{} is not a valid checksum checksum_address".format(destination))
|
||||||
|
raise click.Abort()
|
||||||
|
amount = click.prompt("Enter amount of {} to transfer".format(denomination), type=int)
|
||||||
|
return destination, amount
|
||||||
|
|
||||||
#
|
#
|
||||||
# Action Switch
|
# Action Switch
|
||||||
|
|
|
@ -22,7 +22,6 @@ class BlockchainInterface:
|
||||||
ethereum contracts with the given web3 provider backend.
|
ethereum contracts with the given web3 provider backend.
|
||||||
"""
|
"""
|
||||||
__default_timeout = 10 # seconds
|
__default_timeout = 10 # seconds
|
||||||
__default_network = 'tester'
|
|
||||||
# __default_transaction_gas_limit = 500000 # TODO: determine sensible limit and validate transactions
|
# __default_transaction_gas_limit = 500000 # TODO: determine sensible limit and validate transactions
|
||||||
|
|
||||||
class UnknownContract(Exception):
|
class UnknownContract(Exception):
|
||||||
|
@ -32,7 +31,6 @@ class BlockchainInterface:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
network_name: str = None,
|
|
||||||
provider_uri: str = None,
|
provider_uri: str = None,
|
||||||
providers: list = None,
|
providers: list = None,
|
||||||
autoconnect: bool = True,
|
autoconnect: bool = True,
|
||||||
|
@ -44,33 +42,39 @@ class BlockchainInterface:
|
||||||
A blockchain "network inerface"; The circumflex wraps entirely around the bounds of
|
A blockchain "network inerface"; The circumflex wraps entirely around the bounds of
|
||||||
contract operations including compilation, deployment, and execution.
|
contract operations including compilation, deployment, and execution.
|
||||||
|
|
||||||
|
Filesystem Configuration Client Web3 Node
|
||||||
|
================ ====================== =============== ===================== ===========================
|
||||||
|
|
||||||
Solidity Files -- SolidityCompiler --- --- HTTPProvider --
|
Solidity Files -- SolidityCompiler --- --- HTTPProvider ------ ...
|
||||||
| | |
|
| |
|
||||||
| | -- External EVM (geth, etc.)
|
| |
|
||||||
|
|
|
||||||
*BlockchainInterface* -- IPCProvider --
|
*BlockchainInterface* -- IPCProvider ----- External EVM (geth, parity...)
|
||||||
|
|
||||||
| | |
|
| | |
|
||||||
| | |
|
| | |
|
||||||
Registry File -- ContractRegistry -- | ---- TestProvider -- EthereumTester
|
Registry File -- ContractRegistry --- | ---- TestProvider ----- EthereumTester
|
||||||
|
|
|
|
||||||
| |
|
| |
|
||||||
|
|
|
|
||||||
Pyevm (development chain)
|
PyEVM (Development Chain)
|
||||||
Blockchain
|
Runtime Files --- -------- Blockchain
|
||||||
|
| |
|
||||||
|
| | |
|
||||||
|
|
||||||
|
|
Key Files ------ NodeConfiguration -------- Agent ... (Contract API)
|
||||||
|
|
||||||
Agent ... (Contract API)
|
| | |
|
||||||
|
| |
|
||||||
|
| ---------- Actor ... (Blockchain-Character API)
|
||||||
|
|
|
||||||
|
| |
|
||||||
|
|
||||||
|
|
Configuration File Character ... (Public API)
|
||||||
|
|
||||||
Character / Actor
|
|
||||||
|
|
||||||
|
|
||||||
The circumflex is the junction of the solidity compiler, a contract registry, and a collection of
|
The BlockchainInterface is the junction of the solidity compiler, a contract registry, and a collection of
|
||||||
web3 network __providers as a means of interfacing with the ethereum blockchain to execute
|
web3 network providers as a means of interfacing with the ethereum blockchain to execute
|
||||||
or deploy contract code on the network.
|
or deploy contract code on the network.
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,9 +100,6 @@ class BlockchainInterface:
|
||||||
|
|
||||||
self.log = getLogger("blockchain-interface") # type: Logger
|
self.log = getLogger("blockchain-interface") # type: Logger
|
||||||
|
|
||||||
self.__network = network_name if network_name is not None else self.__default_network
|
|
||||||
self.timeout = timeout if timeout is not None else self.__default_timeout
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Providers
|
# Providers
|
||||||
#
|
#
|
||||||
|
@ -106,6 +107,7 @@ class BlockchainInterface:
|
||||||
self.w3 = constants.NO_BLOCKCHAIN_CONNECTION
|
self.w3 = constants.NO_BLOCKCHAIN_CONNECTION
|
||||||
self.__providers = providers or constants.NO_BLOCKCHAIN_CONNECTION
|
self.__providers = providers or constants.NO_BLOCKCHAIN_CONNECTION
|
||||||
self.provider_uri = constants.NO_BLOCKCHAIN_CONNECTION
|
self.provider_uri = constants.NO_BLOCKCHAIN_CONNECTION
|
||||||
|
self.timeout = timeout if timeout is not None else self.__default_timeout
|
||||||
|
|
||||||
if provider_uri and providers:
|
if provider_uri and providers:
|
||||||
raise self.InterfaceError("Pass a provider URI string, or a list of provider instances.")
|
raise self.InterfaceError("Pass a provider URI string, or a list of provider instances.")
|
||||||
|
@ -167,10 +169,6 @@ class BlockchainInterface:
|
||||||
def providers(self) -> Tuple[Union[IPCProvider, WebsocketProvider, HTTPProvider], ...]:
|
def providers(self) -> Tuple[Union[IPCProvider, WebsocketProvider, HTTPProvider], ...]:
|
||||||
return tuple(self.__providers)
|
return tuple(self.__providers)
|
||||||
|
|
||||||
@property
|
|
||||||
def network(self) -> str:
|
|
||||||
return self.__network
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -179,9 +177,9 @@ class BlockchainInterface:
|
||||||
return self.w3.isConnected()
|
return self.w3.isConnected()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def version(self) -> str:
|
def node_version(self) -> str:
|
||||||
"""Return node version information"""
|
"""Return node version information"""
|
||||||
return self.w3.version.node
|
return self.w3.node_version.node
|
||||||
|
|
||||||
def add_provider(self,
|
def add_provider(self,
|
||||||
provider: Union[IPCProvider, WebsocketProvider, HTTPProvider] = None,
|
provider: Union[IPCProvider, WebsocketProvider, HTTPProvider] = None,
|
||||||
|
@ -215,7 +213,7 @@ class BlockchainInterface:
|
||||||
# w3.middleware_stack.inject(geth_poa_middleware, layer=0)
|
# w3.middleware_stack.inject(geth_poa_middleware, layer=0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise self.InterfaceError("{} is an ambiguous or unsupported blockchain provider URI".format(provider_uri))
|
raise self.InterfaceError("{} is an invalid or unsupported blockchain provider URI".format(provider_uri))
|
||||||
|
|
||||||
# IPC
|
# IPC
|
||||||
elif uri_breakdown.scheme == 'ipc':
|
elif uri_breakdown.scheme == 'ipc':
|
||||||
|
|
|
@ -260,17 +260,22 @@ class NodeConfiguration:
|
||||||
output_filepath = output_filepath or self.registry_filepath
|
output_filepath = output_filepath or self.registry_filepath
|
||||||
source = source or self.REGISTRY_SOURCE
|
source = source or self.REGISTRY_SOURCE
|
||||||
|
|
||||||
# Validate Registry
|
|
||||||
with open(source, 'r') as registry_file:
|
|
||||||
try:
|
|
||||||
json.loads(registry_file.read())
|
|
||||||
except JSONDecodeError:
|
|
||||||
raise self.ConfigurationError("The registry source {} is not valid JSON".format(source))
|
|
||||||
|
|
||||||
if not blank:
|
if not blank:
|
||||||
|
# Validate Registry
|
||||||
|
with open(source, 'r') as registry_file:
|
||||||
|
try:
|
||||||
|
json.loads(registry_file.read())
|
||||||
|
except JSONDecodeError:
|
||||||
|
message = "The registry source {} is not valid JSON".format(source)
|
||||||
|
self.log.critical(message)
|
||||||
|
raise self.ConfigurationError(message)
|
||||||
|
else:
|
||||||
|
self.log.debug("Source registry {} is valid JSON".format(source))
|
||||||
|
self.log.info("Copied contract registry from {}".format(source))
|
||||||
shutil.copyfile(src=source, dst=output_filepath)
|
shutil.copyfile(src=source, dst=output_filepath)
|
||||||
else:
|
else:
|
||||||
open(output_filepath, '').close() # blank
|
self.log.warning("Writing blank registry")
|
||||||
|
open(output_filepath, 'w').close() # blank
|
||||||
|
|
||||||
return output_filepath
|
return output_filepath
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue