diff --git a/snet/contracts/__init__.py b/snet/contracts/__init__.py index 90f60fd..84efce2 100644 --- a/snet/contracts/__init__.py +++ b/snet/contracts/__init__.py @@ -1 +1,2 @@ -from .utils import * \ No newline at end of file +from .utils import (get_all_abi_contract_files, get_contract_def, + get_contract_deployment_block, get_contract_object) \ No newline at end of file diff --git a/snet/contracts/utils.py b/snet/contracts/utils.py index 2c36896..aaf8ce0 100644 --- a/snet/contracts/utils.py +++ b/snet/contracts/utils.py @@ -1,6 +1,6 @@ import json import os -from pathlib import PurePath +from pathlib import Path, PurePath from typing import Any from eth_typing import BlockNumber @@ -8,7 +8,7 @@ from web3.contract.contract import Contract -import snet.contracts as contracts +from snet import contracts RESOURCES_PATH = PurePath(os.path.dirname(contracts.__file__)).joinpath("resources") @@ -35,3 +35,21 @@ def get_contract_deployment_block(w3: web3.Web3, contract_file: str) -> BlockNum if w3.net.version in [1, 5, 11155111]: raise Exception("Transaction hash not found for deployed mpe contract") return 0 + + +def get_contract_def(contract_name, contract_artifacts_root=RESOURCES_PATH): + contract_def = {} + with open(Path(__file__).absolute().parent.joinpath(contract_artifacts_root, "abi", + f"{contract_name}.json")) as f: + contract_def["abi"] = json.load(f) + if os.path.isfile(Path(__file__).absolute().parent.joinpath(contract_artifacts_root, "networks", + f"{contract_name}.json")): + with open(Path(__file__).absolute().parent.joinpath(contract_artifacts_root, "networks", + f"{contract_name}.json")) as f: + contract_def["networks"] = json.load(f) + return contract_def + + +def get_all_abi_contract_files(): + contracts = Path(RESOURCES_PATH.joinpath("abi")).glob("*json") + return [*contracts] diff --git a/version.py b/version.py index 9b36b86..3dc1f76 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -__version__ = "0.0.10" +__version__ = "0.1.0"