Skip to content

Commit

Permalink
Add new functions for CLI (#7) (#8)
Browse files Browse the repository at this point in the history
Added:
* get_contract_def
* get_all_abi_contract_files

Co-authored-by: mabredin <[email protected]>
  • Loading branch information
kiruxaspb and mabredin authored Apr 17, 2024
1 parent 5833fb1 commit ffce87e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion snet/contracts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .utils import *
from .utils import (get_all_abi_contract_files, get_contract_def,
get_contract_deployment_block, get_contract_object)
22 changes: 20 additions & 2 deletions snet/contracts/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import json
import os
from pathlib import PurePath
from pathlib import Path, PurePath
from typing import Any

from eth_typing import BlockNumber
import web3

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")

Expand All @@ -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]
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.10"
__version__ = "0.1.0"

0 comments on commit ffce87e

Please sign in to comment.