From 69715f697e386f7812e958d1e391397953aa5a3c Mon Sep 17 00:00:00 2001 From: Kahtaf Alam Date: Fri, 29 Nov 2024 15:51:00 -0500 Subject: [PATCH] Allow overriding the network chain endpoint (#47) --- README.md | 2 +- pyproject.toml | 2 +- vana/__init__.py | 10 ++++-- vana/chain_manager.py | 56 +++++++++++++++++++++------------- vana/commands/transfer.py | 2 +- vana/commands/wallets.py | 2 +- vana/contracts/__init__.py | 10 ++++++ vana/logging/defines.py | 2 +- vana/logging/loggingmachine.py | 10 +++--- vana/message.py | 6 ++-- vana/mock/wallet_mock.py | 4 +-- vana/utils/wallet_utils.py | 2 +- vana/wallet.py | 4 +-- 13 files changed, 70 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 0912e6e..43d3249 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ You should be able to view your keys by navigating to `~/.vana/wallets` ```bash $ tree ~/.vana/ .vana/ # Root directory. - wallets/ # The folder containing all opendata wallets. + wallets/ # The folder containing all vana wallets. default/ # The name of your wallet, "default" coldkey # Your encrypted coldkey. coldkeypub.txt # Your coldkey public address diff --git a/pyproject.toml b/pyproject.toml index fcdde1f..56fd468 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vana" -version = "0.29.0" +version = "0.30.0" description = "" authors = ["Tim Nunamaker ", "Volodymyr Isai ", "Kahtaf Alam "] readme = "README.md" diff --git a/vana/__init__.py b/vana/__init__.py index 44a6d26..de46ca4 100644 --- a/vana/__init__.py +++ b/vana/__init__.py @@ -15,7 +15,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -__version__ = "0.29.0" +__version__ = "0.30.0" import rich @@ -119,10 +119,14 @@ def debug(on: bool = True): logging.set_debug(on) -__networks__ = ["vana", "satori", "moksha", "local", "test", "archive"] +__networks__ = ["vana", "islander", "maya", "satori", "moksha", "local", "test", "archive"] __vana_entrypoint__ = "https://rpc.vana.org" +__islander_entrypoint__ = "https://rpc.islander.vana.org" + +__maya_entrypoint__ = "https://rpc.maya.vana.org" + __satori_entrypoint__ = "https://rpc.satori.vana.org" __moksha_entrypoint__ = "https://rpc.moksha.vana.org" @@ -135,6 +139,8 @@ def debug(on: bool = True): "vana": "https://vanascan.io/tx/{}", "moksha": "https://moksha.vanascan.io/tx/{}", "satori": "https://satori.vanascan.io/tx/{}", + "islander": "https://islander.vanascan.io/tx/{}", + "maya": "https://maya.vanascan.io/tx/{}", } configs = [ diff --git a/vana/chain_manager.py b/vana/chain_manager.py index dbdf3bc..f7c5f48 100644 --- a/vana/chain_manager.py +++ b/vana/chain_manager.py @@ -36,7 +36,7 @@ from vana.utils.transaction import TransactionManager from vana.utils.web3 import decode_custom_error -logger = native_logging.getLogger("opendata") +logger = native_logging.getLogger("vana") Balance = Union[int, Decimal] @@ -48,36 +48,35 @@ class ChainManager: @staticmethod def setup_config(network: str, config: vana.Config): + chain_endpoint = config.chain.get("chain_endpoint") + if network is not None: ( evaluated_network, evaluated_endpoint, - ) = ChainManager.determine_chain_endpoint_and_network(network) + ) = ChainManager.determine_chain_endpoint_and_network(network, chain_endpoint) else: if config.get("__is_set", {}).get("chain.chain_endpoint"): ( evaluated_network, evaluated_endpoint, ) = ChainManager.determine_chain_endpoint_and_network( - config.chain.chain_endpoint + config.chain.chain_endpoint, chain_endpoint ) - elif config.get("__is_set", {}).get("chain.network"): ( evaluated_network, evaluated_endpoint, ) = ChainManager.determine_chain_endpoint_and_network( - config.chain.network + config.chain.network, chain_endpoint ) - elif config.chain.get("chain_endpoint"): ( evaluated_network, evaluated_endpoint, ) = ChainManager.determine_chain_endpoint_and_network( - config.chain.chain_endpoint + config.chain.chain_endpoint, chain_endpoint ) - elif config.chain.get("network"): ( evaluated_network, @@ -85,15 +84,13 @@ def setup_config(network: str, config: vana.Config): ) = ChainManager.determine_chain_endpoint_and_network( config.chain.network ) - else: ( evaluated_network, evaluated_endpoint, ) = ChainManager.determine_chain_endpoint_and_network( - vana.defaults.chain.network + vana.defaults.chain.network, chain_endpoint ) - return ( evaluated_endpoint, evaluated_network, @@ -200,7 +197,8 @@ def state( return state_ - def send_transaction(self, function: ContractFunction, account: LocalAccount, value=0, max_retries=3, base_gas_multiplier=1.5): + def send_transaction(self, function: ContractFunction, account: LocalAccount, value=0, max_retries=3, + base_gas_multiplier=1.5): """ Send a transaction using the TransactionManager """ @@ -255,7 +253,7 @@ def get_total_stake_for_coldkey( # return Balance.from_rao(_result.value) @staticmethod - def determine_chain_endpoint_and_network(network: str): + def determine_chain_endpoint_and_network(network: str, chain_endpoint=None): """Determines the chain endpoint and network from the passed network or chain_endpoint. Args: @@ -269,36 +267,50 @@ def determine_chain_endpoint_and_network(network: str): return None, None if network in vana.__networks__: if network == "vana": - return network, vana.__vana_entrypoint__ + return network, chain_endpoint if chain_endpoint is not None else vana.__vana_entrypoint__ + if network == "islander": + return network, chain_endpoint if chain_endpoint is not None else vana.__islander_entrypoint__ + if network == "maya": + return network, chain_endpoint if chain_endpoint is not None else vana.__maya_entrypoint__ if network == "moksha": - return network, vana.__moksha_entrypoint__ + return network, chain_endpoint if chain_endpoint is not None else vana.__moksha_entrypoint__ if network == "satori": - return network, vana.__satori_entrypoint__ + return network, chain_endpoint if chain_endpoint is not None else vana.__satori_entrypoint__ elif network == "local": - return network, vana.__local_entrypoint__ + return network, chain_endpoint if chain_endpoint is not None else vana.__local_entrypoint__ elif network == "archive": - return network, vana.__archive_entrypoint__ + return network, chain_endpoint if chain_endpoint is not None else vana.__archive_entrypoint__ else: if ( network == vana.__vana_entrypoint__ or "rpc.vana" in network ): - return "vana", vana.__vana_entrypoint__ + return "vana", chain_endpoint if chain_endpoint is not None else vana.__vana_entrypoint__ + elif ( + network == vana.__islander_entrypoint__ + or "rpc.islander.vana" in network + ): + return "islander", chain_endpoint if chain_endpoint is not None else vana.__islander_entrypoint__ + elif ( + network == vana.__maya_entrypoint__ + or "rpc.maya.vana" in network + ): + return "maya", chain_endpoint if chain_endpoint is not None else vana.__maya_entrypoint__ elif ( network == vana.__moksha_entrypoint__ or "rpc.moksha.vana" in network ): - return "moksha", vana.__moksha_entrypoint__ + return "moksha", chain_endpoint if chain_endpoint is not None else vana.__moksha_entrypoint__ elif ( network == vana.__satori_entrypoint__ or "rpc.satori.vana" in network ): - return "satori", vana.__satori_entrypoint__ + return "satori", chain_endpoint if chain_endpoint is not None else vana.__satori_entrypoint__ elif ( network == vana.__archive_entrypoint__ or "archive.vana" in network ): - return "archive", vana.__archive_entrypoint__ + return "archive", chain_endpoint if chain_endpoint is not None else vana.__archive_entrypoint__ elif "127.0.0.1" in network or "localhost" in network: return "local", network else: diff --git a/vana/commands/transfer.py b/vana/commands/transfer.py index 8048000..1265c64 100644 --- a/vana/commands/transfer.py +++ b/vana/commands/transfer.py @@ -84,7 +84,7 @@ def check_config(config: "vana.Config"): # Get destination. if not config.dest and not config.no_prompt: dest = Prompt.ask("Enter destination public key: (h160 or secp256k1)") - if not vana.utils.is_valid_opendata_address_or_public_key(dest): + if not vana.utils.is_valid_vana_address_or_public_key(dest): sys.exit() else: config.dest = str(dest) diff --git a/vana/commands/wallets.py b/vana/commands/wallets.py index 7cd5759..1cb309a 100644 --- a/vana/commands/wallets.py +++ b/vana/commands/wallets.py @@ -200,7 +200,7 @@ def check_config(config: "vana.Config"): config.public_key_hex = prompt_answer else: config.h160_address = prompt_answer - if not vana.utils.is_valid_opendata_address_or_public_key( + if not vana.utils.is_valid_vana_address_or_public_key( address=( config.h160_address if config.h160_address else config.public_key_hex ) diff --git a/vana/contracts/__init__.py b/vana/contracts/__init__.py index 506e06e..5340ae6 100644 --- a/vana/contracts/__init__.py +++ b/vana/contracts/__init__.py @@ -4,6 +4,16 @@ "DataRegistry": "0xEA882bb75C54DE9A08bC46b46c396727B4BFe9a5", "RootNetworkContract": "0xf408A064d640b620219F510963646Ed2bD5606BB", }, + "islander": { + "TeePool": "0xF084Ca24B4E29Aa843898e0B12c465fAFD089965", + "DataRegistry": "0xEA882bb75C54DE9A08bC46b46c396727B4BFe9a5", + "RootNetworkContract": "0xf408A064d640b620219F510963646Ed2bD5606BB", + }, + "maya": { + "TeePool": "0xF084Ca24B4E29Aa843898e0B12c465fAFD089965", + "DataRegistry": "0xEA882bb75C54DE9A08bC46b46c396727B4BFe9a5", + "RootNetworkContract": "0xf408A064d640b620219F510963646Ed2bD5606BB", + }, "satori": { "TeePool": "0xF084Ca24B4E29Aa843898e0B12c465fAFD089965", "DataRegistry": "0xEA882bb75C54DE9A08bC46b46c396727B4BFe9a5", diff --git a/vana/logging/defines.py b/vana/logging/defines.py index db195e3..57bf180 100644 --- a/vana/logging/defines.py +++ b/vana/logging/defines.py @@ -20,7 +20,7 @@ f"%(asctime)s | %(levelname)s | %(name)s:%(filename)s:%(lineno)s | %(message)s" ) DATE_FORMAT = "%Y-%m-%d %H:%M:%S" -OPENDATA_LOGGER_NAME = "vana" +VANA_LOGGER_NAME = "vana" DEFAULT_LOG_FILE_NAME = "vana.log" DEFAULT_MAX_ROTATING_LOG_FILE_SIZE = 25 * 1024 * 1024 DEFAULT_LOG_BACKUP_COUNT = 10 diff --git a/vana/logging/loggingmachine.py b/vana/logging/loggingmachine.py index fdf4e09..78d336b 100644 --- a/vana/logging/loggingmachine.py +++ b/vana/logging/loggingmachine.py @@ -31,7 +31,7 @@ from vana.logging.defines import ( TRACE_LOG_FORMAT, DATE_FORMAT, - OPENDATA_LOGGER_NAME, + VANA_LOGGER_NAME, DEFAULT_LOG_FILE_NAME, DEFAULT_MAX_ROTATING_LOG_FILE_SIZE, DEFAULT_LOG_BACKUP_COUNT, @@ -49,7 +49,7 @@ class LoggingConfig(NamedTuple): class LoggingMachine(StateMachine): """ - Handles logger states for opendata and 3rd party libraries + Handles logger states for vana and 3rd party libraries """ Default = State(initial=True) @@ -83,7 +83,7 @@ class LoggingMachine(StateMachine): | Disabled.to(Disabled) ) - def __init__(self, config: "vana.Config", name: str = OPENDATA_LOGGER_NAME): + def __init__(self, config: "vana.Config", name: str = VANA_LOGGER_NAME): # basics super(LoggingMachine, self).__init__() self._queue = mp.Queue(-1) @@ -362,13 +362,13 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None): parser.add_argument( "--" + prefix_str + "logging.debug", action="store_true", - help="""Turn on opendata debugging information""", + help="""Turn on vana debugging information""", default=default_logging_debug, ) parser.add_argument( "--" + prefix_str + "logging.trace", action="store_true", - help="""Turn on opendata trace level information""", + help="""Turn on vana trace level information""", default=default_logging_trace, ) parser.add_argument( diff --git a/vana/message.py b/vana/message.py index e7531d8..2510110 100644 --- a/vana/message.py +++ b/vana/message.py @@ -198,10 +198,10 @@ class Config: ) _extract_port = pydantic.validator("port", pre=True, allow_reuse=True)(cast_int) - # The opendata version on the terminal as an int. + # The vana version on the terminal as an int. version: Optional[int] = pydantic.Field( title="version", - description="The opendata version on the NodeServer as str(int)", + description="The vana version on the NodeServer as str(int)", examples=111, default=None, allow_mutation=True, @@ -229,7 +229,7 @@ class Config: allow_mutation=True, ) - # The opendata version on the terminal as an int. + # The vana version on the terminal as an int. hotkey: Optional[str] = pydantic.Field( title="hotkey", description="The h160 encoded hotkey string of the terminal wallet.", diff --git a/vana/mock/wallet_mock.py b/vana/mock/wallet_mock.py index 2c0e296..7a6e91e 100644 --- a/vana/mock/wallet_mock.py +++ b/vana/mock/wallet_mock.py @@ -27,11 +27,11 @@ class MockWallet(Wallet): """ - Mocked Version of the opendata wallet class, meant to be used for testing. + Mocked Version of the vana wallet class, meant to be used for testing. """ def __init__(self, **kwargs): - r"""Init opendata wallet object containing a hot and coldkey. + r"""Init vana wallet object containing a hot and coldkey. Args: _mock (required=True, default=False): If true creates a mock wallet with random keys. diff --git a/vana/utils/wallet_utils.py b/vana/utils/wallet_utils.py index e0d5d24..bc1751c 100644 --- a/vana/utils/wallet_utils.py +++ b/vana/utils/wallet_utils.py @@ -54,7 +54,7 @@ def is_valid_secp256k1_pubkey(public_key: Union[str, bytes]) -> bool: return False -def is_valid_opendata_address_or_public_key(address: Union[str, bytes]) -> bool: +def is_valid_vana_address_or_public_key(address: Union[str, bytes]) -> bool: """ Checks if the given address is a valid Ethereum address or public key. diff --git a/vana/wallet.py b/vana/wallet.py index 7aa3429..07fe1ba 100644 --- a/vana/wallet.py +++ b/vana/wallet.py @@ -29,7 +29,7 @@ from rich.panel import Panel import vana -from vana.utils.wallet_utils import is_valid_opendata_address_or_public_key +from vana.utils.wallet_utils import is_valid_vana_address_or_public_key def display_private_key_msg(private_key: str, key_type: str): @@ -618,7 +618,7 @@ def regenerate_coldkeypub( if h160_address is None and public_key is None: raise ValueError("Either h160_address or public_key must be passed") - if not is_valid_opendata_address_or_public_key( + if not is_valid_vana_address_or_public_key( h160_address if h160_address is not None else public_key ): raise ValueError(