Skip to content

Commit

Permalink
Allow overriding the network chain endpoint (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kahtaf authored Nov 29, 2024
1 parent 1cc768a commit 69715f6
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vana"
version = "0.29.0"
version = "0.30.0"
description = ""
authors = ["Tim Nunamaker <[email protected]>", "Volodymyr Isai <[email protected]>", "Kahtaf Alam <[email protected]>"]
readme = "README.md"
Expand Down
10 changes: 8 additions & 2 deletions vana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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 = [
Expand Down
56 changes: 34 additions & 22 deletions vana/chain_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -48,52 +48,49 @@ 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,
evaluated_endpoint,
) = 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,
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion vana/commands/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vana/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
10 changes: 10 additions & 0 deletions vana/contracts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion vana/logging/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions vana/logging/loggingmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions vana/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.",
Expand Down
4 changes: 2 additions & 2 deletions vana/mock/wallet_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion vana/utils/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions vana/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 69715f6

Please sign in to comment.