Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/sdk/snet/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
import web3
from rfc3986 import urlparse
import ipfshttpclient
from snet.contracts import get_contract_object

from snet.sdk.service_client import ServiceClient
from snet.sdk.account import Account
from snet.sdk.mpe.mpe_contract import MPEContract

from snet.snet_cli.utils.utils import get_contract_object

from snet.snet_cli.utils.ipfs_utils import bytesuri_to_hash, get_from_ipfs_and_checkhash
from snet.snet_cli.metadata.service import mpe_service_metadata_from_json

Expand Down Expand Up @@ -58,9 +57,9 @@ def __init__(
# Get Registry contract address from config if specified; mostly for local testing
_registry_contract_address = self._config.get("registry_contract_address", None)
if _registry_contract_address is None:
self.registry_contract = get_contract_object(self.web3, "Registry.json")
self.registry_contract = get_contract_object(self.web3, "Registry")
else:
self.registry_contract = get_contract_object(self.web3, "Registry.json", _registry_contract_address)
self.registry_contract = get_contract_object(self.web3, "Registry", _registry_contract_address)

self.account = Account(self.web3, config, self.mpe_contract)

Expand Down
8 changes: 5 additions & 3 deletions packages/sdk/snet/sdk/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json

from snet.snet_cli.utils.utils import get_address_from_private, get_contract_object, normalize_private_key
from snet.contracts import get_contract_object

from snet.snet_cli.utils.utils import get_address_from_private, normalize_private_key

DEFAULT_GAS = 300000
TRANSACTION_TIMEOUT = 500
Expand All @@ -26,10 +28,10 @@ def __init__(self, w3, config, mpe_contract):
_token_contract_address = self.config.get("token_contract_address", None)
if _token_contract_address is None:
self.token_contract = get_contract_object(
self.web3, "SingularityNetToken.json")
self.web3, "SingularityNetToken")
else:
self.token_contract = get_contract_object(
self.web3, "SingularityNetToken.json", _token_contract_address)
self.web3, "SingularityNetToken", _token_contract_address)

private_key = config.get("private_key", None)
signer_private_key = config.get("signer_private_key", None)
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/snet/sdk/mpe/mpe_contract.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from snet.snet_cli.utils.utils import get_contract_deployment_block, get_contract_object
from snet.contracts import get_contract_deployment_block, get_contract_object


class MPEContract:
def __init__(self, w3, address=None):
self.web3 = w3
if address is None:
self.contract = get_contract_object(self.web3, "MultiPartyEscrow.json")
self.contract = get_contract_object(self.web3, "MultiPartyEscrow")
else:
self.contract = get_contract_object(self.web3, "MultiPartyEscrow.json", address)
self.contract = get_contract_object(self.web3, "MultiPartyEscrow", address)
self.event_topics = [self.web3.keccak(
text="ChannelOpen(uint256,uint256,address,address,address,bytes32,uint256,uint256)").hex()]
self.deployment_block = get_contract_deployment_block(
self.web3, "MultiPartyEscrow.json")
self.web3, "MultiPartyEscrow")

def balance(self, address):
return self.contract.functions.balances(address).call()
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/snet/sdk/mpe/payment_channel_provider.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import web3
from web3._utils.events import get_event_data
from eth_abi.codec import ABICodec
from snet.contracts import get_contract_deployment_block

from snet.sdk.mpe.mpe_contract import MPEContract

from snet.sdk.mpe.payment_channel import PaymentChannel
from snet.snet_cli.utils.utils import get_contract_deployment_block


BLOCKS_PER_BATCH = 5000
Expand All @@ -20,7 +20,7 @@ def __init__(self, w3, payment_channel_state_service_client, mpe_contract):
self.event_topics = [self.web3.keccak(
text="ChannelOpen(uint256,uint256,address,address,address,bytes32,uint256,uint256)").hex()]
self.deployment_block = get_contract_deployment_block(
self.web3, "MultiPartyEscrow.json")
self.web3, "MultiPartyEscrow")
self.payment_channel_state_service_client = payment_channel_state_service_client

def get_past_open_channels(self, account, payment_address, group_id, starting_block_number=0, to_block_number=None):
Expand Down
3 changes: 2 additions & 1 deletion packages/snet_cli/common_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
'argcomplete==3.1.2',
'grpcio-health-checking==1.59.0',
'jsonschema==4.0.0',
'eth-account==0.9.0'
'eth-account==0.9.0',
'snet.contracts==0.0.10'
]


Expand Down
24 changes: 0 additions & 24 deletions packages/snet_cli/snet/snet_cli/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,30 +280,6 @@ def rgetattr(obj, attr):
return functools.reduce(getattr, [obj] + attr.split('.'))


def get_contract_object(w3, contract_file, address=None):
with open(RESOURCES_PATH.joinpath("contracts", "abi", contract_file)) as f:
abi = json.load(f)
if address:
return w3.eth.contract(abi=abi, address=w3.to_checksum_address(address))
with open(RESOURCES_PATH.joinpath("contracts", "networks", contract_file)) as f:
networks = json.load(f)
address = w3.to_checksum_address(networks[w3.net.version]["address"])
return w3.eth.contract(abi=abi, address=address)


def get_contract_deployment_block(w3, contract_file):
try:
with open(RESOURCES_PATH.joinpath("contracts", "networks", contract_file)) as f:
networks = json.load(f)
txn_hash = networks[w3.net.version]["transactionHash"]
return w3.eth.get_transaction_receipt(txn_hash).blockNumber
except Exception:
# TODO Hack as currenlty dependecy is on snet-cli so for test purpose return 0,need to remove dependecies from snet-cli ,currently very tightly coupled with it
if w3.net.version in [1, 5, 11155111]:
raise Exception("Transaction hash not found for deployed mpe contract")
return 0


def normalize_private_key(private_key):
if private_key.startswith("0x"):
private_key = bytes(bytearray.fromhex(private_key[2:]))
Expand Down
4 changes: 3 additions & 1 deletion packages/snet_cli/test/functional_tests/mint/mint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from packages.snet_cli.snet.snet_cli.utils.utils import get_web3, get_contract_object
from snet.contracts import get_contract_object

from packages.snet_cli.snet.snet_cli.utils.utils import get_web3
from web3.gas_strategies.time_based import medium_gas_price_strategy

TRANSACTION_TIMEOUT = 500
Expand Down