diff --git a/.circleci/config.yml b/.circleci/config.yml index a18ffc1c..023b98d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,13 +21,13 @@ jobs: - run: name: Install snet-cli command: | - ./snet_cli/scripts/blockchain install - sudo pip3 install -e ./snet_cli + ./packages/snet_cli/scripts/blockchain install + sudo pip3 install -e ./packages/snet_cli - run: name: Install platform-contracts from master command: | # Install platform-contracts (from master) - # we will deploy contracts from snet_cli/test/utils/reset_enviroment.sh + # we will deploy contracts from packages/snet_cli/test/utils/reset_enviroment.sh cd .. git clone https://github.com/singnet/platform-contracts cd platform-contracts @@ -42,7 +42,7 @@ jobs: - run: name: Functional tests command: | - bash -ex snet_cli/test/utils/run_all_functional.sh + bash -ex packages/snet_cli/test/utils/run_all_functional.sh - run: name: Trigger platform-pipeline build command: | diff --git a/.gitignore b/.gitignore index 85af91f3..101f0af2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +venv/ .idea/ __pycache__ blockchain/node_modules +snet.egg-info/ diff --git a/packages/sdk/.gitignore b/packages/sdk/.gitignore new file mode 100644 index 00000000..674694bb --- /dev/null +++ b/packages/sdk/.gitignore @@ -0,0 +1,4 @@ +venv/ +snet.sdk.egg-info/ +build/ +dist/ diff --git a/snet_cli/LICENSE b/packages/sdk/LICENSE similarity index 100% rename from snet_cli/LICENSE rename to packages/sdk/LICENSE diff --git a/snet_sdk/README.md b/packages/sdk/README.md similarity index 100% rename from snet_sdk/README.md rename to packages/sdk/README.md diff --git a/packages/sdk/requirements.txt b/packages/sdk/requirements.txt new file mode 100644 index 00000000..63cab9eb --- /dev/null +++ b/packages/sdk/requirements.txt @@ -0,0 +1,3 @@ +--index-url https://pypi.python.org/simple +../snet_cli/ +-e . diff --git a/snet_cli/scripts/package-pip b/packages/sdk/scripts/package-pip similarity index 100% rename from snet_cli/scripts/package-pip rename to packages/sdk/scripts/package-pip diff --git a/packages/sdk/setup.py b/packages/sdk/setup.py new file mode 100644 index 00000000..cd28bfe0 --- /dev/null +++ b/packages/sdk/setup.py @@ -0,0 +1,43 @@ +import pkg_resources +from setuptools import setup, find_namespace_packages + + +PACKAGE_NAME = 'snet.sdk' + + +def is_package_installed(package_name): + installed_modules = [p.project_name for p in pkg_resources.working_set] + return package_name in installed_modules + + +dependencies = [] + + +if is_package_installed('snet-cli'): + # The default setup.py in the snet_cli package for local development installs the whole snet_cli package, + # not the standalone snet.snet_cli namespace package; if a strict dependency on snet.snet_cli was enforced, + # this setup.py would fetch it from PyPI. So, if snet_cli is installed and in your Python path, the + # dependency on snet.snet_cli will be skipped. + # If snet_cli is not available, snet.snet_cli will be fetched from PyPI. + print("Package 'snet_cli' is installed and in your PYTHONPATH: skipping snet.snet_cli dependency") +else: + dependencies.append('snet.snet_cli') + + +version_dict = {} +with open("./snet/sdk/version.py") as fp: + exec(fp.read(), version_dict) + +setup( + name=PACKAGE_NAME, + version=version_dict['__version__'], + packages=find_namespace_packages(include=['snet.*']), + namespace_packages=['snet'], + url='https://github.com/singnet/snet-cli/tree/master/snet_sdk', + license='MIT', + author='SingularityNET Foundation', + author_email='info@singularitynet.io', + description='SingularityNET Python SDK', + python_requires='>=3.6', + install_requires=dependencies +) diff --git a/snet_sdk/snet_sdk/__init__.py b/packages/sdk/snet/sdk/__init__.py similarity index 88% rename from snet_sdk/snet_sdk/__init__.py rename to packages/sdk/snet/sdk/__init__.py index 5837883f..59c70790 100644 --- a/snet_sdk/snet_sdk/__init__.py +++ b/packages/sdk/snet/sdk/__init__.py @@ -6,13 +6,14 @@ from web3.gas_strategies.rpc import rpc_gas_price_strategy from rfc3986 import urlparse import ipfsapi -from web3.utils.datastructures import AttributeDict +from web3.datastructures import AttributeDict -from snet_sdk.utils import get_contract_object -from snet_sdk.service_client import ServiceClient -from snet_sdk.account import Account -from snet_sdk.mpe_contract import MPEContract -from snet_sdk.payment_channel_management_strategies.default import PaymentChannelManagementStrategy +from snet.sdk.service_client import ServiceClient +from snet.sdk.account import Account +from snet.sdk.mpe_contract import MPEContract +from snet.sdk.payment_channel_management_strategies.default import PaymentChannelManagementStrategy + +from snet.snet_cli.utils import get_contract_object class SnetSDK: diff --git a/snet_sdk/snet_sdk/account.py b/packages/sdk/snet/sdk/account.py similarity index 96% rename from snet_sdk/snet_sdk/account.py rename to packages/sdk/snet/sdk/account.py index 4164e8ca..eb1a6460 100644 --- a/snet_sdk/snet_sdk/account.py +++ b/packages/sdk/snet/sdk/account.py @@ -1,6 +1,6 @@ import json -from snet_sdk.utils import normalize_private_key, get_address_from_private, get_contract_object +from snet.snet_cli.utils import normalize_private_key, get_address_from_private, get_contract_object DEFAULT_GAS = 210000 diff --git a/snet_sdk/snet_sdk/generic_client_interceptor.py b/packages/sdk/snet/sdk/generic_client_interceptor.py similarity index 100% rename from snet_sdk/snet_sdk/generic_client_interceptor.py rename to packages/sdk/snet/sdk/generic_client_interceptor.py diff --git a/snet_sdk/snet_sdk/mpe_contract.py b/packages/sdk/snet/sdk/mpe_contract.py similarity index 96% rename from snet_sdk/snet_sdk/mpe_contract.py rename to packages/sdk/snet/sdk/mpe_contract.py index 3e879352..8a608fce 100644 --- a/snet_sdk/snet_sdk/mpe_contract.py +++ b/packages/sdk/snet/sdk/mpe_contract.py @@ -1,8 +1,10 @@ import base64 import web3 -from snet_sdk.utils import get_contract_object, get_contract_deployment_block -from snet_sdk.payment_channel import PaymentChannel +from snet.sdk.payment_channel import PaymentChannel + +from snet.snet_cli.utils import get_contract_object, get_contract_deployment_block + BLOCKS_PER_BATCH = 20000 EVENT_ABI = {'anonymous': False, 'inputs': [{'indexed': False, 'name': 'channelId', 'type': 'uint256'}, {'indexed': False, 'name': 'nonce', 'type': 'uint256'}, {'indexed': True, 'name': 'sender', 'type': 'address'}, {'indexed': False, 'name': 'signer', 'type': 'address'}, {'indexed': True, 'name': 'recipient', 'type': 'address'}, {'indexed': True, 'name': 'groupId', 'type': 'bytes32'}, {'indexed': False, 'name': 'amount', 'type': 'uint256'}, {'indexed': False, 'name': 'expiration', 'type': 'uint256'}], 'name': 'ChannelOpen', 'type': 'event'} diff --git a/snet_sdk/snet_sdk/payment_channel.py b/packages/sdk/snet/sdk/payment_channel.py similarity index 91% rename from snet_sdk/snet_sdk/payment_channel.py rename to packages/sdk/snet/sdk/payment_channel.py index 87cdbd30..60538504 100644 --- a/snet_sdk/snet_sdk/payment_channel.py +++ b/packages/sdk/snet/sdk/payment_channel.py @@ -1,7 +1,8 @@ import web3 +import importlib from eth_account.messages import defunct_hash_message -import snet_sdk.state_service_pb2 as state_service_pb2 +from snet.snet_cli.utils import RESOURCES_PATH, add_to_path class PaymentChannel: def __init__(self, channel_id, w3, account, service, mpe_contract): @@ -49,6 +50,8 @@ def _get_current_channel_state(self): stub = self.payment_channel_state_service_client message = web3.Web3.soliditySha3(["uint256"], [self.channel_id]) signature = self.web3.eth.account.signHash(defunct_hash_message(message), self.account.signer_private_key).signature + with add_to_path(str(RESOURCES_PATH.joinpath("proto"))): + state_service_pb2 = importlib.import_module("state_service_pb2") request = state_service_pb2.ChannelStateRequest(channel_id=web3.Web3.toBytes(self.channel_id), signature=bytes(signature)) response = stub.GetChannelState(request) return int.from_bytes(response.current_nonce, byteorder="big"), int.from_bytes(response.current_signed_amount, byteorder="big") diff --git a/snet_cli/snet_cli/_vendor/__init__.py b/packages/sdk/snet/sdk/payment_channel_management_strategies/__init__.py similarity index 100% rename from snet_cli/snet_cli/_vendor/__init__.py rename to packages/sdk/snet/sdk/payment_channel_management_strategies/__init__.py diff --git a/snet_sdk/snet_sdk/payment_channel_management_strategies/default.py b/packages/sdk/snet/sdk/payment_channel_management_strategies/default.py similarity index 100% rename from snet_sdk/snet_sdk/payment_channel_management_strategies/default.py rename to packages/sdk/snet/sdk/payment_channel_management_strategies/default.py diff --git a/snet_sdk/snet_sdk/service_client.py b/packages/sdk/snet/sdk/service_client.py similarity index 94% rename from snet_sdk/snet_sdk/service_client.py rename to packages/sdk/snet/sdk/service_client.py index 3ed39c52..31b71394 100644 --- a/snet_sdk/snet_sdk/service_client.py +++ b/packages/sdk/snet/sdk/service_client.py @@ -1,12 +1,13 @@ import collections +import importlib + import grpc import web3 from rfc3986 import urlparse from eth_account.messages import defunct_hash_message -import snet_sdk.generic_client_interceptor as generic_client_interceptor - -import snet_sdk.state_service_pb2_grpc as state_service_pb2_grpc +import snet.sdk.generic_client_interceptor as generic_client_interceptor +from snet.snet_cli.utils import RESOURCES_PATH, add_to_path class _ClientCallDetails( @@ -111,6 +112,8 @@ def default_channel_expiration(self): def _generate_payment_channel_state_service_client(self): grpc_channel = self._base_grpc_channel + with add_to_path(str(RESOURCES_PATH.joinpath("proto"))): + state_service_pb2_grpc = importlib.import_module("state_service_pb2_grpc") return state_service_pb2_grpc.PaymentChannelStateServiceStub(grpc_channel) diff --git a/packages/sdk/snet/sdk/version.py b/packages/sdk/snet/sdk/version.py new file mode 100644 index 00000000..bbab0242 --- /dev/null +++ b/packages/sdk/snet/sdk/version.py @@ -0,0 +1 @@ +__version__ = "0.1.4" diff --git a/packages/snet_cli/.gitignore b/packages/snet_cli/.gitignore new file mode 100644 index 00000000..e86739fb --- /dev/null +++ b/packages/snet_cli/.gitignore @@ -0,0 +1,8 @@ +venv/ +snet_cli.egg-info/ +snet/snet_cli/resources/contracts/abi +snet/snet_cli/resources/contracts/networks +snet/snet_cli/resources/node_modules +snet/snet_cli/resources/proto/*.py +build/ +dist/ diff --git a/snet_sdk/LICENSE b/packages/snet_cli/LICENSE similarity index 100% rename from snet_sdk/LICENSE rename to packages/snet_cli/LICENSE diff --git a/packages/snet_cli/MANIFEST.in b/packages/snet_cli/MANIFEST.in new file mode 100644 index 00000000..e9df6bc0 --- /dev/null +++ b/packages/snet_cli/MANIFEST.in @@ -0,0 +1,11 @@ +include snet/snet_cli/resources/proto/* +include snet/snet_cli/resources/contracts/abi/* +include snet/snet_cli/resources/contracts/networks/* +include snet/snet_cli/resources/package.json + +recursive-include snet_cli/_vendor * + +recursive-exclude * .git +recursive-exclude * node_modules +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] diff --git a/snet_cli/README.md b/packages/snet_cli/README.md similarity index 100% rename from snet_cli/README.md rename to packages/snet_cli/README.md diff --git a/snet_cli/docs/Makefile b/packages/snet_cli/docs/Makefile similarity index 100% rename from snet_cli/docs/Makefile rename to packages/snet_cli/docs/Makefile diff --git a/snet_cli/docs/build-docs.sh b/packages/snet_cli/docs/build-docs.sh similarity index 100% rename from snet_cli/docs/build-docs.sh rename to packages/snet_cli/docs/build-docs.sh diff --git a/snet_cli/docs/source/conf.py b/packages/snet_cli/docs/source/conf.py similarity index 100% rename from snet_cli/docs/source/conf.py rename to packages/snet_cli/docs/source/conf.py diff --git a/snet_cli/docs/source/generate_rst.py b/packages/snet_cli/docs/source/generate_rst.py similarity index 100% rename from snet_cli/docs/source/generate_rst.py rename to packages/snet_cli/docs/source/generate_rst.py diff --git a/snet_cli/docs/source/img/singularityNET.png b/packages/snet_cli/docs/source/img/singularityNET.png similarity index 100% rename from snet_cli/docs/source/img/singularityNET.png rename to packages/snet_cli/docs/source/img/singularityNET.png diff --git a/snet_cli/docs/source/index_template.tpl b/packages/snet_cli/docs/source/index_template.tpl similarity index 100% rename from snet_cli/docs/source/index_template.tpl rename to packages/snet_cli/docs/source/index_template.tpl diff --git a/snet_cli/docs/source/snet-cli-static/theme.css b/packages/snet_cli/docs/source/snet-cli-static/theme.css similarity index 100% rename from snet_cli/docs/source/snet-cli-static/theme.css rename to packages/snet_cli/docs/source/snet-cli-static/theme.css diff --git a/snet_cli/docs/source/subcommand_template.tpl b/packages/snet_cli/docs/source/subcommand_template.tpl similarity index 100% rename from snet_cli/docs/source/subcommand_template.tpl rename to packages/snet_cli/docs/source/subcommand_template.tpl diff --git a/packages/snet_cli/requirements.txt b/packages/snet_cli/requirements.txt new file mode 100644 index 00000000..ea8d66ba --- /dev/null +++ b/packages/snet_cli/requirements.txt @@ -0,0 +1,2 @@ +--index-url https://pypi.python.org/simple +-e . diff --git a/snet_sdk/scripts/blockchain b/packages/snet_cli/scripts/blockchain similarity index 90% rename from snet_sdk/scripts/blockchain rename to packages/snet_cli/scripts/blockchain index f49e73de..46cf9904 100755 --- a/snet_sdk/scripts/blockchain +++ b/packages/snet_cli/scripts/blockchain @@ -10,12 +10,13 @@ import sys def main(): assert len(sys.argv) > 1, "please select a target from 'install', 'uninstall'" target = sys.argv[1] - blockchain_dir = pathlib.Path(__file__).absolute().parent.parent.parent.joinpath("blockchain") + cur_dir = pathlib.Path(__file__).absolute().parent + blockchain_dir = cur_dir.parent.parent.parent.joinpath("blockchain") node_modules_dir = blockchain_dir.joinpath("node_modules") platform_json_src_dir = node_modules_dir.joinpath("singularitynet-platform-contracts") token_json_src_dir = node_modules_dir.joinpath("singularitynet-token-contracts") token_contract_name = "SingularityNetToken" - contract_json_dest_dir = pathlib.Path(__file__).absolute().parent.parent.joinpath("snet_sdk", "resources", "contracts") + contract_json_dest_dir = cur_dir.parent.joinpath("snet", "snet_cli", "resources", "contracts") abi_contract_names = ["Registry", "MultiPartyEscrow"] networks_contract_names = ["Registry", "MultiPartyEscrow"] diff --git a/snet_sdk/scripts/package-pip b/packages/snet_cli/scripts/package-pip similarity index 100% rename from snet_sdk/scripts/package-pip rename to packages/snet_cli/scripts/package-pip diff --git a/snet_cli/setup.py b/packages/snet_cli/setup.py similarity index 82% rename from snet_cli/setup.py rename to packages/snet_cli/setup.py index e234abc8..fd0fa2d4 100644 --- a/snet_cli/setup.py +++ b/packages/snet_cli/setup.py @@ -1,14 +1,14 @@ -from setuptools import setup, find_packages +from setuptools import setup, find_packages, find_namespace_packages from setuptools.command.develop import develop as _develop from setuptools.command.install import install as _install def install_and_compile_proto(): - import snet_cli - from snet_cli.utils import compile_proto as compile_proto + import snet.snet_cli + from snet.snet_cli.utils import compile_proto as compile_proto from pathlib import Path - proto_dir = Path(__file__).absolute().parent.joinpath("snet_cli", "resources", "proto") - dest_dir = Path(snet_cli.__file__).absolute().parent.joinpath("resources", "proto") + proto_dir = Path(__file__).absolute().parent.joinpath("snet", "snet_cli", "resources", "proto") + dest_dir = Path(snet.snet_cli.__file__).absolute().parent.joinpath("resources", "proto") print(proto_dir, "->", dest_dir) for fn in proto_dir.glob('*.proto'): print("Compiling protobuf", fn) @@ -37,7 +37,8 @@ def run(self): setup( name='snet-cli', version=version_dict['__version__'], - packages=find_packages(), + packages=find_namespace_packages(include=['snet.*'])+find_packages(), + namespace_packages=['snet'], url='https://github.com/singnet/snet-cli', license='MIT', author='SingularityNET Foundation', diff --git a/snet_sdk/snet_sdk/payment_channel_management_strategies/__init__.py b/packages/snet_cli/snet/snet_cli/__init__.py similarity index 100% rename from snet_sdk/snet_sdk/payment_channel_management_strategies/__init__.py rename to packages/snet_cli/snet/snet_cli/__init__.py diff --git a/snet_cli/snet_cli/resources/contracts/placeholder.txt b/packages/snet_cli/snet/snet_cli/resources/contracts/placeholder.txt similarity index 100% rename from snet_cli/snet_cli/resources/contracts/placeholder.txt rename to packages/snet_cli/snet/snet_cli/resources/contracts/placeholder.txt diff --git a/snet_cli/resources/package.json b/packages/snet_cli/snet/snet_cli/resources/package.json similarity index 100% rename from snet_cli/resources/package.json rename to packages/snet_cli/snet/snet_cli/resources/package.json diff --git a/snet_cli/snet_cli/resources/proto/control_service.proto b/packages/snet_cli/snet/snet_cli/resources/proto/control_service.proto similarity index 100% rename from snet_cli/snet_cli/resources/proto/control_service.proto rename to packages/snet_cli/snet/snet_cli/resources/proto/control_service.proto diff --git a/snet_cli/snet_cli/resources/proto/merckledag.proto b/packages/snet_cli/snet/snet_cli/resources/proto/merckledag.proto similarity index 100% rename from snet_cli/snet_cli/resources/proto/merckledag.proto rename to packages/snet_cli/snet/snet_cli/resources/proto/merckledag.proto diff --git a/snet_cli/snet_cli/resources/proto/state_service.proto b/packages/snet_cli/snet/snet_cli/resources/proto/state_service.proto similarity index 100% rename from snet_cli/snet_cli/resources/proto/state_service.proto rename to packages/snet_cli/snet/snet_cli/resources/proto/state_service.proto diff --git a/snet_cli/snet_cli/resources/proto/unixfs.proto b/packages/snet_cli/snet/snet_cli/resources/proto/unixfs.proto similarity index 100% rename from snet_cli/snet_cli/resources/proto/unixfs.proto rename to packages/snet_cli/snet/snet_cli/resources/proto/unixfs.proto diff --git a/snet_cli/snet_cli/utils.py b/packages/snet_cli/snet/snet_cli/utils.py similarity index 80% rename from snet_cli/snet_cli/utils.py rename to packages/snet_cli/snet/snet_cli/utils.py index d85dbefb..7bf982ad 100644 --- a/snet_cli/snet_cli/utils.py +++ b/packages/snet_cli/snet/snet_cli/utils.py @@ -2,9 +2,10 @@ import os import subprocess import functools +import sys from urllib.parse import urlparse -from pathlib import Path +from pathlib import Path, PurePath import web3 import pkg_resources @@ -12,6 +13,9 @@ from grpc_tools.protoc import main as protoc +RESOURCES_PATH = PurePath(os.path.realpath(__file__)).parent.joinpath("resources") + + class DefaultAttributeObject(object): def __init__(self, **kwargs): for k, v in kwargs.items(): @@ -122,7 +126,7 @@ def walk_imports(entry_path): return seen_paths -def get_contract_def(contract_name, contract_artifacts_root=Path(__file__).absolute().parent.joinpath("resources", "contracts")): +def get_contract_def(contract_name, contract_artifacts_root=RESOURCES_PATH.joinpath("contracts")): contract_def = {} with open(Path(__file__).absolute().parent.joinpath(contract_artifacts_root, "abi", "{}.json".format(contract_name))) as f: contract_def["abi"] = json.load(f) @@ -159,12 +163,11 @@ def compile_proto(entry_path, codegen_dir, proto_file=None, target_language="pyt compiler_args.append("--grpc_python_out={}".format(codegen_dir)) compiler = protoc elif target_language == "nodejs": - resources_path = Path(os.path.dirname(os.path.realpath(__file__))).joinpath("resources") - protoc_node_compiler_path = resources_path.joinpath("node_modules").joinpath("grpc-tools").joinpath("bin").joinpath("protoc.js").absolute() - grpc_node_plugin_path = resources_path.joinpath("node_modules").joinpath("grpc-tools").joinpath("bin").joinpath("grpc_node_plugin").resolve() + protoc_node_compiler_path = Path(RESOURCES_PATH.joinpath("node_modules").joinpath("grpc-tools").joinpath("bin").joinpath("protoc.js")).absolute() + grpc_node_plugin_path = Path(RESOURCES_PATH.joinpath("node_modules").joinpath("grpc-tools").joinpath("bin").joinpath("grpc_node_plugin")).resolve() if not os.path.isfile(protoc_node_compiler_path) or not os.path.isfile(grpc_node_plugin_path): print("Missing required node.js protoc compiler. Retrieving from npm...") - subprocess.run(["npm", "install"], cwd=resources_path) + subprocess.run(["npm", "install"], cwd=RESOURCES_PATH) compiler_args.append("--js_out=import_style=commonjs,binary:{}".format(codegen_dir)) compiler_args.append("--grpc_out={}".format(codegen_dir)) compiler_args.append("--plugin=protoc-gen-grpc={}".format(grpc_node_plugin_path)) @@ -181,6 +184,7 @@ def compile_proto(entry_path, codegen_dir, proto_file=None, target_language="pyt return False except Exception as e: + print(e) return False def abi_get_element_by_name(abi, name): @@ -253,3 +257,43 @@ def rgetattr(obj, attr): 2 """ return functools.reduce(getattr, [obj] + attr.split('.')) + + +def get_contract_object(w3, contract_file): + with open(RESOURCES_PATH.joinpath("contracts", "abi", contract_file)) as f: + abi = json.load(f) + with open(RESOURCES_PATH.joinpath("contracts", "networks", contract_file)) as f: + networks = json.load(f) + address = w3.toChecksumAddress(networks[w3.version.network]["address"]) + return w3.eth.contract(abi=abi, address=address) + + +def get_contract_deployment_block(w3, contract_file): + with open(RESOURCES_PATH.joinpath("contracts", "networks", contract_file)) as f: + networks = json.load(f) + txn_hash = networks[w3.version.network]["transactionHash"] + return w3.eth.getTransactionReceipt(txn_hash).blockNumber + + +def normalize_private_key(private_key): + if private_key.startswith("0x"): + private_key = bytes(bytearray.fromhex(private_key[2:])) + else: + private_key = bytes(bytearray.fromhex(private_key)) + return private_key + + +def get_address_from_private(private_key): + return web3.eth.Account.privateKeyToAccount(private_key).address + + +class add_to_path(): + def __init__(self, path): + self.path = path + def __enter__(self): + sys.path.insert(0, self.path) + def __exit__(self, exc_type, exc_value, traceback): + try: + sys.path.remove(self.path) + except ValueError: + pass diff --git a/snet_cli/snet_cli/utils_proto.py b/packages/snet_cli/snet/snet_cli/utils_proto.py similarity index 100% rename from snet_cli/snet_cli/utils_proto.py rename to packages/snet_cli/snet/snet_cli/utils_proto.py diff --git a/snet_cli/snet_cli/__init__.py b/packages/snet_cli/snet_cli/__init__.py similarity index 99% rename from snet_cli/snet_cli/__init__.py rename to packages/snet_cli/snet_cli/__init__.py index 633e954f..6483d16d 100644 --- a/snet_cli/snet_cli/__init__.py +++ b/packages/snet_cli/snet_cli/__init__.py @@ -7,6 +7,7 @@ from snet_cli.config import Config import argcomplete + def main(): try: argv = sys.argv[1:] diff --git a/snet_sdk/snet_sdk/resources/contracts/placeholder.txt b/packages/snet_cli/snet_cli/_vendor/__init__.py similarity index 100% rename from snet_sdk/snet_sdk/resources/contracts/placeholder.txt rename to packages/snet_cli/snet_cli/_vendor/__init__.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/BlueHSMServer_pb2.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/BlueHSMServer_pb2.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/BlueHSMServer_pb2.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/BlueHSMServer_pb2.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/Dongle.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/Dongle.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/Dongle.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/Dongle.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/__init__.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/__init__.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/__init__.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/__init__.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/checkGenuine.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/checkGenuine.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/checkGenuine.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/checkGenuine.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/comm.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/comm.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/comm.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/comm.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/commException.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/commException.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/commException.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/commException.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/commHTTP.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/commHTTP.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/commHTTP.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/commHTTP.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/commU2F.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/commU2F.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/commU2F.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/commU2F.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/deleteApp.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/deleteApp.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/deleteApp.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/deleteApp.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/deployed.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/deployed.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/deployed.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/deployed.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/derivePassphrase.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/derivePassphrase.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/derivePassphrase.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/derivePassphrase.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/ecWrapper.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/ecWrapper.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/ecWrapper.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/ecWrapper.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetup.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetup.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetup.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetup.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetupLedger.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetupLedger.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetupLedger.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/endorsementSetupLedger.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/genCAPair.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/genCAPair.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/genCAPair.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/genCAPair.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/getMemInfo.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/getMemInfo.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/getMemInfo.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/getMemInfo.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/hashApp.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/hashApp.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/hashApp.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/hashApp.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/hexLoader.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/hexLoader.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/hexLoader.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/hexLoader.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/hexParser.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/hexParser.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/hexParser.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/hexParser.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/hostOnboard.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/hostOnboard.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/hostOnboard.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/hostOnboard.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/ledgerWrapper.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/ledgerWrapper.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/ledgerWrapper.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/ledgerWrapper.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/listApps.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/listApps.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/listApps.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/listApps.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/loadApp.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/loadApp.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/loadApp.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/loadApp.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/loadMCU.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/loadMCU.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/loadMCU.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/loadMCU.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/mcuBootloader.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/mcuBootloader.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/mcuBootloader.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/mcuBootloader.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/resetCustomCA.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/resetCustomCA.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/resetCustomCA.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/resetCustomCA.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/runApp.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/runApp.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/runApp.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/runApp.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/runScript.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/runScript.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/runScript.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/runScript.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/setupCustomCA.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/setupCustomCA.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/setupCustomCA.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/setupCustomCA.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/signApp.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/signApp.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/signApp.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/signApp.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/updateFirmware.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/updateFirmware.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/updateFirmware.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/updateFirmware.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/verifyApp.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/verifyApp.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/verifyApp.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/verifyApp.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement1.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement1.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement1.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement1.py diff --git a/snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement2.py b/packages/snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement2.py similarity index 100% rename from snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement2.py rename to packages/snet_cli/snet_cli/_vendor/ledgerblue/verifyEndorsement2.py diff --git a/snet_cli/snet_cli/arguments.py b/packages/snet_cli/snet_cli/arguments.py similarity index 99% rename from snet_cli/snet_cli/arguments.py rename to packages/snet_cli/snet_cli/arguments.py index 259de685..92c334bd 100644 --- a/snet_cli/snet_cli/arguments.py +++ b/packages/snet_cli/snet_cli/arguments.py @@ -7,7 +7,6 @@ from snet_cli.commands import IdentityCommand, SessionSetCommand, SessionShowCommand, NetworkCommand, ContractCommand, \ OrganizationCommand, VersionCommand from snet_cli.identity import get_identity_types -from snet_cli.utils import type_converter, get_contract_def from snet_cli.mpe_account_command import MPEAccountCommand from snet_cli.mpe_service_command import MPEServiceCommand from snet_cli.mpe_channel_command import MPEChannelCommand @@ -17,6 +16,8 @@ from snet_cli.utils_agi2cogs import stragi2cogs from snet_cli.config import Config, get_session_keys, get_session_network_keys_removable +from snet.snet_cli.utils import type_converter, get_contract_def, RESOURCES_PATH + class CustomParser(argparse.ArgumentParser): def __init__(self, default_choice=None, *args, **kwargs): @@ -234,7 +235,7 @@ def add_contract_options(parser): subparsers = parser.add_subparsers(title="contracts", metavar="CONTRACT") subparsers.required = True - for path in Path(__file__).absolute().parent.joinpath("resources", "contracts", "abi").glob("*json"): + for path in Path(RESOURCES_PATH.joinpath("contracts", "abi")).glob("*json"): contract_name = re.search(r"([^.]*)\.json", os.path.basename(path)).group(1) contract_p = subparsers.add_parser(contract_name, help="{} contract".format(contract_name)) add_contract_function_options(contract_p, contract_name) diff --git a/snet_cli/snet_cli/commands.py b/packages/snet_cli/snet_cli/commands.py similarity index 99% rename from snet_cli/snet_cli/commands.py rename to packages/snet_cli/snet_cli/commands.py index 16d27169..0f5ffd20 100644 --- a/snet_cli/snet_cli/commands.py +++ b/packages/snet_cli/snet_cli/commands.py @@ -3,23 +3,22 @@ import sys from textwrap import indent from urllib.parse import urljoin +import secrets +import string +from web3.eth import is_checksum_address +from web3.gas_strategies.time_based import fast_gas_price_strategy, medium_gas_price_strategy, slow_gas_price_strategy import ipfsapi import yaml from rfc3986 import urlparse -from snet_cli.contract import Contract -from snet_cli.identity import get_kws_for_identity_type -from snet_cli.utils import DefaultAttributeObject, get_web3, serializable, type_converter, get_contract_def, get_cli_version, bytes32_to_str - from snet_cli.utils_config import get_contract_address, get_field_from_args_or_session, read_default_contract_address from snet_cli.identity import RpcIdentityProvider, MnemonicIdentityProvider, TrezorIdentityProvider, \ LedgerIdentityProvider, KeyIdentityProvider, KeyStoreIdentityProvider -from web3.eth import is_checksum_address -import secrets -import string -from web3.gas_strategies.time_based import fast_gas_price_strategy, medium_gas_price_strategy, slow_gas_price_strategy +from snet_cli.contract import Contract +from snet_cli.identity import get_kws_for_identity_type +from snet.snet_cli.utils import DefaultAttributeObject, get_web3, serializable, type_converter, get_contract_def, get_cli_version, bytes32_to_str class Command(object): diff --git a/snet_cli/snet_cli/config.py b/packages/snet_cli/snet_cli/config.py similarity index 100% rename from snet_cli/snet_cli/config.py rename to packages/snet_cli/snet_cli/config.py diff --git a/snet_cli/snet_cli/contract.py b/packages/snet_cli/snet_cli/contract.py similarity index 100% rename from snet_cli/snet_cli/contract.py rename to packages/snet_cli/snet_cli/contract.py diff --git a/snet_cli/snet_cli/identity.py b/packages/snet_cli/snet_cli/identity.py similarity index 97% rename from snet_cli/snet_cli/identity.py rename to packages/snet_cli/snet_cli/identity.py index bad5b0d1..4b8a2f89 100644 --- a/snet_cli/snet_cli/identity.py +++ b/packages/snet_cli/snet_cli/identity.py @@ -16,7 +16,10 @@ from snet_cli._vendor.ledgerblue.comm import getDongle from snet_cli._vendor.ledgerblue.commException import CommException - + +from snet.snet_cli.utils import get_address_from_private, normalize_private_key + + BIP32_HARDEN = 0x80000000 @@ -37,12 +40,8 @@ def sign_message_after_soliditySha3(self, message): class KeyIdentityProvider(IdentityProvider): def __init__(self, w3, private_key): self.w3 = w3 - if private_key.startswith("0x"): - self.private_key = bytes(bytearray.fromhex(private_key[2:])) - else: - self.private_key = bytes(bytearray.fromhex(private_key)) - - self.address = web3.eth.Account.privateKeyToAccount(self.private_key).address + self.private_key = normalize_private_key(private_key) + self.address = get_address_from_private(self.private_key) def get_address(self): return self.address @@ -116,7 +115,7 @@ def __init__(self, w3, mnemonic, index): change_subtree = account_subtree.subkey(i=0) account = change_subtree.subkey(i=index) self.private_key = account.secret_exponent().to_bytes(32, 'big') - self.address = web3.eth.Account.privateKeyToAccount(self.private_key).address + self.address = get_address_from_private(self.private_key) def get_address(self): return self.address diff --git a/snet_cli/snet_cli/mpe_account_command.py b/packages/snet_cli/snet_cli/mpe_account_command.py similarity index 100% rename from snet_cli/snet_cli/mpe_account_command.py rename to packages/snet_cli/snet_cli/mpe_account_command.py diff --git a/snet_cli/snet_cli/mpe_channel_command.py b/packages/snet_cli/snet_cli/mpe_channel_command.py similarity index 99% rename from snet_cli/snet_cli/mpe_channel_command.py rename to packages/snet_cli/snet_cli/mpe_channel_command.py index faf114da..ad027878 100644 --- a/snet_cli/snet_cli/mpe_channel_command.py +++ b/packages/snet_cli/snet_cli/mpe_channel_command.py @@ -1,19 +1,21 @@ - -from snet_cli.mpe_service_command import MPEServiceCommand -from snet_cli.utils import compile_proto import base64 from pathlib import Path import os -from snet_cli.utils import get_contract_def, abi_get_element_by_name, abi_decode_struct_to_dict -from snet_cli.mpe_service_metadata import load_mpe_service_metadata -from snet_cli.utils_ipfs import safe_extract_proto_from_ipfs import shutil import tempfile -from snet_cli.utils_agi2cogs import cogs2stragi import pickle +from collections import defaultdict + from web3.utils.encoding import pad_hex from web3.utils.events import get_event_data -from collections import defaultdict + +from snet_cli.mpe_service_command import MPEServiceCommand +from snet_cli.mpe_service_metadata import load_mpe_service_metadata +from snet_cli.utils_ipfs import safe_extract_proto_from_ipfs +from snet_cli.utils_agi2cogs import cogs2stragi + +from snet.snet_cli.utils import compile_proto, get_contract_def, abi_get_element_by_name, abi_decode_struct_to_dict + # we inherit MPEServiceCommand because we need _get_service_metadata_from_registry class MPEChannelCommand(MPEServiceCommand): diff --git a/snet_cli/snet_cli/mpe_client_command.py b/packages/snet_cli/snet_cli/mpe_client_command.py similarity index 95% rename from snet_cli/snet_cli/mpe_client_command.py rename to packages/snet_cli/snet_cli/mpe_client_command.py index 8e1e1e8c..82fa1885 100644 --- a/snet_cli/snet_cli/mpe_client_command.py +++ b/packages/snet_cli/snet_cli/mpe_client_command.py @@ -1,13 +1,16 @@ -from snet_cli.mpe_channel_command import MPEChannelCommand import base64 from pathlib import Path import json import sys + import grpc from eth_account.messages import defunct_hash_message -from snet_cli.utils_proto import import_protobuf_from_dir, switch_to_json_payload_encoding + +from snet_cli.mpe_channel_command import MPEChannelCommand from snet_cli.utils_agi2cogs import cogs2stragi -from snet_cli.utils import open_grpc_channel, rgetattr, compile_proto + +from snet.snet_cli.utils import open_grpc_channel, rgetattr, compile_proto, RESOURCES_PATH +from snet.snet_cli.utils_proto import import_protobuf_from_dir, switch_to_json_payload_encoding # we inherit MPEChannelCommand because client needs channels @@ -149,14 +152,10 @@ def call_server_lowlevel(self): # III. Stateless client related functions def _get_channel_state_from_server(self, grpc_channel, channel_id): - # Compile protobuf if needed - codegen_dir = Path.home().joinpath(".snet", "mpe_client", "state_service") - proto_dir = Path(__file__).absolute().parent.joinpath("resources", "proto") - if (not codegen_dir.joinpath("state_service_pb2.py").is_file()): - compile_proto(proto_dir, codegen_dir, proto_file = "state_service.proto") + proto_dir = RESOURCES_PATH.joinpath("proto") # make PaymentChannelStateService.GetChannelState call to the daemon - stub_class, request_class, _ = import_protobuf_from_dir(codegen_dir, "GetChannelState") + stub_class, request_class, _ = import_protobuf_from_dir(proto_dir, "GetChannelState") message = self.w3.soliditySha3(["uint256"], [channel_id]) signature = self.ident.sign_message_after_soliditySha3(message) diff --git a/snet_cli/snet_cli/mpe_service_command.py b/packages/snet_cli/snet_cli/mpe_service_command.py similarity index 99% rename from snet_cli/snet_cli/mpe_service_command.py rename to packages/snet_cli/snet_cli/mpe_service_command.py index 22e035c3..9c8f416f 100644 --- a/snet_cli/snet_cli/mpe_service_command.py +++ b/packages/snet_cli/snet_cli/mpe_service_command.py @@ -1,14 +1,17 @@ -from snet_cli.commands import BlockchainCommand -import snet_cli.utils_ipfs as utils_ipfs -from snet_cli.mpe_service_metadata import MPEServiceMetadata, load_mpe_service_metadata, mpe_service_metadata_from_json -from snet_cli.utils import type_converter, bytes32_to_str, open_grpc_channel -from snet_cli.utils_ipfs import hash_to_bytesuri, bytesuri_to_hash, get_from_ipfs_and_checkhash, safe_extract_proto_from_ipfs import web3 import json import grpc +from collections import defaultdict + from grpc_health.v1 import health_pb2 as heartb_pb2 from grpc_health.v1 import health_pb2_grpc as heartb_pb2_grpc -from collections import defaultdict + +from snet_cli.commands import BlockchainCommand +import snet_cli.utils_ipfs as utils_ipfs +from snet_cli.mpe_service_metadata import MPEServiceMetadata, load_mpe_service_metadata, mpe_service_metadata_from_json +from snet_cli.utils_ipfs import hash_to_bytesuri, bytesuri_to_hash, get_from_ipfs_and_checkhash, safe_extract_proto_from_ipfs + +from snet.snet_cli.utils import type_converter, bytes32_to_str, open_grpc_channel class MPEServiceCommand(BlockchainCommand): @@ -218,4 +221,4 @@ def extract_service_api_from_registry(self): def delete_service_registration(self): params = [type_converter("bytes32")(self.args.org_id), type_converter("bytes32")(self.args.service_id)] - self.transact_contract_command("Registry", "deleteServiceRegistration", params) \ No newline at end of file + self.transact_contract_command("Registry", "deleteServiceRegistration", params) diff --git a/snet_cli/snet_cli/mpe_service_metadata.py b/packages/snet_cli/snet_cli/mpe_service_metadata.py similarity index 99% rename from snet_cli/snet_cli/mpe_service_metadata.py rename to packages/snet_cli/snet_cli/mpe_service_metadata.py index 91c935b4..9ab8054c 100644 --- a/snet_cli/snet_cli/mpe_service_metadata.py +++ b/packages/snet_cli/snet_cli/mpe_service_metadata.py @@ -39,9 +39,10 @@ import base64 import secrets -from snet_cli.utils import is_valid_endpoint from collections import defaultdict +from snet.snet_cli.utils import is_valid_endpoint + # TODO: we should use some standard solution here class MPEServiceMetadata: diff --git a/snet_cli/snet_cli/mpe_treasurer_command.py b/packages/snet_cli/snet_cli/mpe_treasurer_command.py similarity index 97% rename from snet_cli/snet_cli/mpe_treasurer_command.py rename to packages/snet_cli/snet_cli/mpe_treasurer_command.py index f603cec1..5452cec3 100644 --- a/snet_cli/snet_cli/mpe_treasurer_command.py +++ b/packages/snet_cli/snet_cli/mpe_treasurer_command.py @@ -1,11 +1,13 @@ -from snet_cli.mpe_client_command import MPEClientCommand -from snet_cli.utils import compile_proto, open_grpc_channel from pathlib import Path + +import web3 import grpc -from snet_cli.utils_proto import import_protobuf_from_dir -from snet_cli.utils import int4bytes_big + +from snet_cli.mpe_client_command import MPEClientCommand from snet_cli.utils_agi2cogs import cogs2stragi -import web3 + +from snet.snet_cli.utils_proto import import_protobuf_from_dir +from snet.snet_cli.utils import compile_proto, open_grpc_channel, int4bytes_big, RESOURCES_PATH class MPETreasurerCommand(MPEClientCommand): @@ -32,7 +34,7 @@ def _get_stub_and_request_classes(self, service_name): """ import protobuf and return stub and request class """ # Compile protobuf if needed codegen_dir = Path.home().joinpath(".snet", "mpe_client", "control_service") - proto_dir = Path(__file__).absolute().parent.joinpath("resources", "proto") + proto_dir = RESOURCES_PATH.joinpath("proto") if (not codegen_dir.joinpath("control_service_pb2.py").is_file()): compile_proto(proto_dir, codegen_dir, proto_file = "control_service.proto") diff --git a/snet_cli/snet_cli/sdk_command.py b/packages/snet_cli/snet_cli/sdk_command.py similarity index 95% rename from snet_cli/snet_cli/sdk_command.py rename to packages/snet_cli/snet_cli/sdk_command.py index e31ba930..a4a651c0 100644 --- a/snet_cli/snet_cli/sdk_command.py +++ b/packages/snet_cli/snet_cli/sdk_command.py @@ -1,12 +1,13 @@ -from snet_cli.mpe_service_command import MPEServiceCommand import os from pathlib import Path, PurePath from tempfile import TemporaryDirectory -from snet_cli.utils import type_converter, bytes32_to_str, compile_proto +from snet_cli.mpe_service_command import MPEServiceCommand from snet_cli.utils_ipfs import bytesuri_to_hash, get_from_ipfs_and_checkhash, safe_extract_proto_from_ipfs from snet_cli.mpe_service_metadata import mpe_service_metadata_from_json +from snet.snet_cli.utils import type_converter, bytes32_to_str, compile_proto + class SDKCommand(MPEServiceCommand): def generate_client_library(self): diff --git a/snet_cli/snet_cli/utils_agi2cogs.py b/packages/snet_cli/snet_cli/utils_agi2cogs.py similarity index 100% rename from snet_cli/snet_cli/utils_agi2cogs.py rename to packages/snet_cli/snet_cli/utils_agi2cogs.py diff --git a/snet_cli/snet_cli/utils_config.py b/packages/snet_cli/snet_cli/utils_config.py similarity index 98% rename from snet_cli/snet_cli/utils_config.py rename to packages/snet_cli/snet_cli/utils_config.py index f1e4a66f..f07e1a38 100644 --- a/snet_cli/snet_cli/utils_config.py +++ b/packages/snet_cli/snet_cli/utils_config.py @@ -1,4 +1,4 @@ -from snet_cli.utils import get_contract_def +from snet.snet_cli.utils import get_contract_def def get_contract_address(cmd, contract_name, error_message = None): """ diff --git a/snet_cli/snet_cli/utils_ipfs.py b/packages/snet_cli/snet_cli/utils_ipfs.py similarity index 96% rename from snet_cli/snet_cli/utils_ipfs.py rename to packages/snet_cli/snet_cli/utils_ipfs.py index 28a2ba1c..c5f24a7a 100644 --- a/snet_cli/snet_cli/utils_ipfs.py +++ b/packages/snet_cli/snet_cli/utils_ipfs.py @@ -38,8 +38,8 @@ def get_from_ipfs_and_checkhash(ipfs_client, ipfs_hash_base58, validate=True): We must check the hash becasue we cannot believe that ipfs_client wasn't been compromise """ if validate: - from snet_cli.resources.proto.unixfs_pb2 import Data - from snet_cli.resources.proto.merckledag_pb2 import MerkleNode + from snet.snet_cli.resources.proto.unixfs_pb2 import Data + from snet.snet_cli.resources.proto.merckledag_pb2 import MerkleNode # No nice Python library to parse ipfs blocks, so do it ourselves. block_data = ipfs_client.block_get(ipfs_hash_base58) diff --git a/snet_cli/snet_cli/version.py b/packages/snet_cli/snet_cli/version.py similarity index 100% rename from snet_cli/snet_cli/version.py rename to packages/snet_cli/snet_cli/version.py diff --git a/snet_cli/test/README.md b/packages/snet_cli/test/README.md similarity index 100% rename from snet_cli/test/README.md rename to packages/snet_cli/test/README.md diff --git a/snet_cli/test/functional_tests/script10_claim_timeout_all.sh b/packages/snet_cli/test/functional_tests/script10_claim_timeout_all.sh similarity index 100% rename from snet_cli/test/functional_tests/script10_claim_timeout_all.sh rename to packages/snet_cli/test/functional_tests/script10_claim_timeout_all.sh diff --git a/snet_cli/test/functional_tests/script11_update_metadata.sh b/packages/snet_cli/test/functional_tests/script11_update_metadata.sh similarity index 100% rename from snet_cli/test/functional_tests/script11_update_metadata.sh rename to packages/snet_cli/test/functional_tests/script11_update_metadata.sh diff --git a/snet_cli/test/functional_tests/script12_extend_add_for_service.sh b/packages/snet_cli/test/functional_tests/script12_extend_add_for_service.sh similarity index 100% rename from snet_cli/test/functional_tests/script12_extend_add_for_service.sh rename to packages/snet_cli/test/functional_tests/script12_extend_add_for_service.sh diff --git a/snet_cli/test/functional_tests/script13_call_reinitialize.sh b/packages/snet_cli/test/functional_tests/script13_call_reinitialize.sh similarity index 100% rename from snet_cli/test/functional_tests/script13_call_reinitialize.sh rename to packages/snet_cli/test/functional_tests/script13_call_reinitialize.sh diff --git a/snet_cli/test/functional_tests/script15_sdk_generate_client_library.sh b/packages/snet_cli/test/functional_tests/script15_sdk_generate_client_library.sh similarity index 100% rename from snet_cli/test/functional_tests/script15_sdk_generate_client_library.sh rename to packages/snet_cli/test/functional_tests/script15_sdk_generate_client_library.sh diff --git a/snet_cli/test/functional_tests/script1_twogroups.sh b/packages/snet_cli/test/functional_tests/script1_twogroups.sh similarity index 100% rename from snet_cli/test/functional_tests/script1_twogroups.sh rename to packages/snet_cli/test/functional_tests/script1_twogroups.sh diff --git a/snet_cli/test/functional_tests/script2_deposit_transfer.sh b/packages/snet_cli/test/functional_tests/script2_deposit_transfer.sh similarity index 100% rename from snet_cli/test/functional_tests/script2_deposit_transfer.sh rename to packages/snet_cli/test/functional_tests/script2_deposit_transfer.sh diff --git a/snet_cli/test/functional_tests/script3_without_addresses.sh b/packages/snet_cli/test/functional_tests/script3_without_addresses.sh similarity index 98% rename from snet_cli/test/functional_tests/script3_without_addresses.sh rename to packages/snet_cli/test/functional_tests/script3_without_addresses.sh index 85120223..57f9d014 100755 --- a/snet_cli/test/functional_tests/script3_without_addresses.sh +++ b/packages/snet_cli/test/functional_tests/script3_without_addresses.sh @@ -2,7 +2,7 @@ # check how snet-cli works if we pass contract address via command line interface # remove networks -rm -rf ../../snet_cli/resources/contracts/networks/*.json +rm -rf ../../snet/snet_cli/resources/contracts/networks/*.json #unset addresses snet unset current_singularitynettoken_at || echo "could fail if hasn't been set (it is ok)" diff --git a/snet_cli/test/functional_tests/script4_only_with_networks.sh b/packages/snet_cli/test/functional_tests/script4_only_with_networks.sh similarity index 90% rename from snet_cli/test/functional_tests/script4_only_with_networks.sh rename to packages/snet_cli/test/functional_tests/script4_only_with_networks.sh index a2050646..9bbd80da 100755 --- a/snet_cli/test/functional_tests/script4_only_with_networks.sh +++ b/packages/snet_cli/test/functional_tests/script4_only_with_networks.sh @@ -7,7 +7,7 @@ # In this test we check this priority -rm -rf ../../snet_cli/resources/contracts/networks/*.json +rm -rf ../../snet/snet_cli/resources/contracts/networks/*.json #unset addresses snet unset current_singularitynettoken_at || echo "could fail if hasn't been set (it is ok)" @@ -20,9 +20,9 @@ snet organization create testo --org-id testo -y -q && exit 1 || echo "fail as # set networks -echo '{"829257324":{"events":{},"links":{},"address":"0x5c7a4290f6f8ff64c69eeffdfafc8644a4ec3a4e","transactionHash":""}}' > ../../snet_cli/resources/contracts/networks/MultiPartyEscrow.json -echo '{"829257324":{"events":{},"links":{},"address":"0x4e74fefa82e83e0964f0d9f53c68e03f7298a8b2","transactionHash":""}}' > ../../snet_cli/resources/contracts/networks/Registry.json -echo '{"829257324":{"events":{},"links":{},"address":"0x6e5f20669177f5bdf3703ec5ea9c4d4fe3aabd14","transactionHash":""}}' > ../../snet_cli/resources/contracts/networks/SingularityNetToken.json +echo '{"829257324":{"events":{},"links":{},"address":"0x5c7a4290f6f8ff64c69eeffdfafc8644a4ec3a4e","transactionHash":""}}' > ../../snet/snet_cli/resources/contracts/networks/MultiPartyEscrow.json +echo '{"829257324":{"events":{},"links":{},"address":"0x4e74fefa82e83e0964f0d9f53c68e03f7298a8b2","transactionHash":""}}' > ../../snet/snet_cli/resources/contracts/networks/Registry.json +echo '{"829257324":{"events":{},"links":{},"address":"0x6e5f20669177f5bdf3703ec5ea9c4d4fe3aabd14","transactionHash":""}}' > ../../snet/snet_cli/resources/contracts/networks/SingularityNetToken.json # this should work @@ -50,9 +50,9 @@ snet organization delete testo -y -q --registry-at 0x4e74fefa82e8 # set INVALID networks -echo '{"829257324":{"events":{},"links":{},"address":"0x1c7a4290f6f8ff64c69eeffdfafc8644a4ec3a4e","transactionHash":""}}' > ../../snet_cli/resources/contracts/networks/MultiPartyEscrow.json -echo '{"829257324":{"events":{},"links":{},"address":"0x1e74fefa82e83e0964f0d9f53c68e03f7298a8b2","transactionHash":""}}' > ../../snet_cli/resources/contracts/networks/Registry.json -echo '{"829257324":{"events":{},"links":{},"address":"0x1e5f20669177f5bdf3703ec5ea9c4d4fe3aabd14","transactionHash":""}}' > ../../snet_cli/resources/contracts/networks/SingularityNetToken.json +echo '{"829257324":{"events":{},"links":{},"address":"0x1c7a4290f6f8ff64c69eeffdfafc8644a4ec3a4e","transactionHash":""}}' > ../../snet/snet_cli/resources/contracts/networks/MultiPartyEscrow.json +echo '{"829257324":{"events":{},"links":{},"address":"0x1e74fefa82e83e0964f0d9f53c68e03f7298a8b2","transactionHash":""}}' > ../../snet/snet_cli/resources/contracts/networks/Registry.json +echo '{"829257324":{"events":{},"links":{},"address":"0x1e5f20669177f5bdf3703ec5ea9c4d4fe3aabd14","transactionHash":""}}' > ../../snet/snet_cli/resources/contracts/networks/SingularityNetToken.json # this should fail (because addresses in networks are invalid ) snet account balance && exit 1 || echo "fail as expected" diff --git a/snet_cli/test/functional_tests/script5_identity1_rpc_mnemonic.sh b/packages/snet_cli/test/functional_tests/script5_identity1_rpc_mnemonic.sh similarity index 100% rename from snet_cli/test/functional_tests/script5_identity1_rpc_mnemonic.sh rename to packages/snet_cli/test/functional_tests/script5_identity1_rpc_mnemonic.sh diff --git a/snet_cli/test/functional_tests/script6_organization.sh b/packages/snet_cli/test/functional_tests/script6_organization.sh similarity index 100% rename from snet_cli/test/functional_tests/script6_organization.sh rename to packages/snet_cli/test/functional_tests/script6_organization.sh diff --git a/snet_cli/test/functional_tests/script7_contracts.sh b/packages/snet_cli/test/functional_tests/script7_contracts.sh similarity index 100% rename from snet_cli/test/functional_tests/script7_contracts.sh rename to packages/snet_cli/test/functional_tests/script7_contracts.sh diff --git a/snet_cli/test/functional_tests/script8_networks.sh b/packages/snet_cli/test/functional_tests/script8_networks.sh similarity index 100% rename from snet_cli/test/functional_tests/script8_networks.sh rename to packages/snet_cli/test/functional_tests/script8_networks.sh diff --git a/snet_cli/test/functional_tests/script9_treasurer.sh b/packages/snet_cli/test/functional_tests/script9_treasurer.sh similarity index 100% rename from snet_cli/test/functional_tests/script9_treasurer.sh rename to packages/snet_cli/test/functional_tests/script9_treasurer.sh diff --git a/snet_cli/test/functional_tests/service_spec1/ExampleService.proto b/packages/snet_cli/test/functional_tests/service_spec1/ExampleService.proto similarity index 100% rename from snet_cli/test/functional_tests/service_spec1/ExampleService.proto rename to packages/snet_cli/test/functional_tests/service_spec1/ExampleService.proto diff --git a/snet_cli/test/functional_tests/simple_daemon/test_simple_daemon.py b/packages/snet_cli/test/functional_tests/simple_daemon/test_simple_daemon.py similarity index 95% rename from snet_cli/test/functional_tests/simple_daemon/test_simple_daemon.py rename to packages/snet_cli/test/functional_tests/simple_daemon/test_simple_daemon.py index a43aaa7e..8681b573 100644 --- a/snet_cli/test/functional_tests/simple_daemon/test_simple_daemon.py +++ b/packages/snet_cli/test/functional_tests/simple_daemon/test_simple_daemon.py @@ -1,14 +1,16 @@ -from snet_cli.utils import compile_proto, DefaultAttributeObject from concurrent import futures import time import web3 + from snet_cli.mpe_channel_command import MPEChannelCommand from snet_cli.config import Config +from snet.snet_cli.utils import compile_proto, DefaultAttributeObject + compile_proto("../service_spec1", ".", proto_file = "ExampleService.proto") -compile_proto("../../../snet_cli/resources/proto/", ".", proto_file = "state_service.proto") -compile_proto("../../../snet_cli/resources/proto/", ".", proto_file = "control_service.proto") +compile_proto("../../../snet/snet_cli/resources/proto/", ".", proto_file = "state_service.proto") +compile_proto("../../../snet/snet_cli/resources/proto/", ".", proto_file = "control_service.proto") PRICE = 10000 import grpc diff --git a/snet_cli/test/unit_tests/test_mpe_service_metadata_1.py b/packages/snet_cli/test/unit_tests/test_mpe_service_metadata_1.py similarity index 100% rename from snet_cli/test/unit_tests/test_mpe_service_metadata_1.py rename to packages/snet_cli/test/unit_tests/test_mpe_service_metadata_1.py diff --git a/snet_cli/test/utils/reset_environment.sh b/packages/snet_cli/test/utils/reset_environment.sh similarity index 98% rename from snet_cli/test/utils/reset_environment.sh rename to packages/snet_cli/test/utils/reset_environment.sh index d35f6d49..ed2b534a 100755 --- a/snet_cli/test/utils/reset_environment.sh +++ b/packages/snet_cli/test/utils/reset_environment.sh @@ -16,7 +16,7 @@ fi # I. restart ipfs killall ipfs || echo "supress an error" -sudo rm -rf ~/.ipfs/ +sudo rm -rf ~/.ipfs ipfs init ipfs bootstrap rm --all ipfs config Addresses.API /ip4/127.0.0.1/tcp/5002 diff --git a/packages/snet_cli/test/utils/run_all_functional.sh b/packages/snet_cli/test/utils/run_all_functional.sh new file mode 100755 index 00000000..63c69ece --- /dev/null +++ b/packages/snet_cli/test/utils/run_all_functional.sh @@ -0,0 +1,5 @@ +for f in packages/snet_cli/test/functional_tests/*.sh +do + bash -ex packages/snet_cli/test/utils/reset_environment.sh --i-no-what-i-am-doing + bash -ex -c "cd packages/snet_cli/test/functional_tests; bash -ex `basename $f`" +done diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..89b31b4f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +--index-url https://pypi.python.org/simple +packages/snet_cli/ +packages/sdk/ +-e . diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..3f40806e --- /dev/null +++ b/setup.py @@ -0,0 +1,53 @@ +import sys +import os +import subprocess +from setuptools import setup +from setuptools.command.develop import develop +from setuptools.command.install import install + +PACKAGE_NAME = 'snet' +SOURCES = { + 'snet_cli': 'packages/snet_cli', + 'sdk': 'packages/sdk', +} + +def install_packages(sources, develop=False): + print("installing all packages in {} mode".format( + "development" if develop else "normal")) + wd = os.getcwd() + for k, v in sources.items(): + try: + os.chdir(os.path.join(wd, v)) + if develop: + subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-e', '.']) + else: + subprocess.check_call([sys.executable, '-m', 'pip', 'install', '.']) + except Exception as e: + print("Oops, something went wrong installing", k) + print(e) + finally: + os.chdir(wd) + +class DevelopCmd(develop): + """ Add custom steps for the develop command """ + def run(self): + install_packages(SOURCES, develop=True) + develop.run(self) + +class InstallCmd(install): + """ Add custom steps for the install command """ + def run(self): + install_packages(SOURCES, develop=False) + install.run(self) +setup( + name=PACKAGE_NAME, + version="0.0.1", + author="SingularityNET Foundation", + author_email="info@singularitynet.io", + description="SingularityNET Monorepo", + license="MIT", + cmdclass={ + 'install': InstallCmd, + 'develop': DevelopCmd, + } +) diff --git a/snet_cli/.gitignore b/snet_cli/.gitignore deleted file mode 100644 index 3e31273b..00000000 --- a/snet_cli/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -venv/ -snet_cli.egg-info/ -snet_cli/resources/contracts/abi -snet_cli/resources/contracts/networks -snet_cli/resources/proto/*.py -build/ -dist/ diff --git a/snet_cli/MANIFEST.in b/snet_cli/MANIFEST.in deleted file mode 100644 index c5e35bef..00000000 --- a/snet_cli/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include snet_cli/resources/proto/* -include snet_cli/resources/contracts/abi/* -include snet_cli/resources/contracts/networks/* -include snet_cli/resources/package.json -include snet_cli/_vendor/* diff --git a/snet_cli/scripts/blockchain b/snet_cli/scripts/blockchain deleted file mode 100755 index 4edb62ef..00000000 --- a/snet_cli/scripts/blockchain +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python3 - -import os -import pathlib -import shutil -import subprocess -import sys - - -def main(): - assert len(sys.argv) > 1, "please select a target from 'install', 'uninstall'" - target = sys.argv[1] - blockchain_dir = pathlib.Path(__file__).absolute().parent.parent.parent.joinpath("blockchain") - node_modules_dir = blockchain_dir.joinpath("node_modules") - platform_json_src_dir = node_modules_dir.joinpath("singularitynet-platform-contracts") - token_json_src_dir = node_modules_dir.joinpath("singularitynet-token-contracts") - token_contract_name = "SingularityNetToken" - contract_json_dest_dir = pathlib.Path(__file__).absolute().parent.parent.joinpath("snet_cli", "resources", "contracts") - abi_contract_names = ["Registry", "MultiPartyEscrow"] - networks_contract_names = ["Registry", "MultiPartyEscrow"] - - npm_location = shutil.which('npm') - if not npm_location: - raise Exception("This script requires 'npm' to be installed and in your PATH") - - if target == "install": - shutil.rmtree(contract_json_dest_dir) - - subprocess.call([npm_location, "install"], cwd=blockchain_dir) - - os.makedirs(contract_json_dest_dir.joinpath("abi"), exist_ok=True) - os.makedirs(contract_json_dest_dir.joinpath("networks"), exist_ok=True) - - for contract_name in abi_contract_names: - shutil.copy(platform_json_src_dir.joinpath("abi", "{}.json".format(contract_name)), - contract_json_dest_dir.joinpath("abi", "{}.json".format(contract_name))) - for contract_name in networks_contract_names: - shutil.copy(platform_json_src_dir.joinpath("networks", "{}.json".format(contract_name)), - contract_json_dest_dir.joinpath("networks", "{}.json".format(contract_name))) - - shutil.copy(token_json_src_dir.joinpath("abi", "{}.json".format(token_contract_name)), - contract_json_dest_dir.joinpath("abi", "{}.json".format(token_contract_name))) - shutil.copy(token_json_src_dir.joinpath("networks", "{}.json".format(token_contract_name)), - contract_json_dest_dir.joinpath("networks", "{}.json".format(token_contract_name))) - elif target == "uninstall": - try: - shutil.rmtree(node_modules_dir) - shutil.rmtree(contract_json_dest_dir.joinpath("abi")) - shutil.rmtree(contract_json_dest_dir.joinpath("networks")) - except FileNotFoundError: - pass - - -if __name__ == "__main__": - main() diff --git a/snet_cli/test/utils/run_all_functional.sh b/snet_cli/test/utils/run_all_functional.sh deleted file mode 100755 index 7d38afb8..00000000 --- a/snet_cli/test/utils/run_all_functional.sh +++ /dev/null @@ -1,5 +0,0 @@ -for f in snet_cli/test/functional_tests/*.sh -do - bash -ex snet_cli/test/utils/reset_environment.sh --i-no-what-i-am-doing - bash -ex -c "cd snet_cli/test/functional_tests; bash -ex `basename $f`" -done diff --git a/snet_sdk/.gitignore b/snet_sdk/.gitignore deleted file mode 100644 index bbdffa01..00000000 --- a/snet_sdk/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -venv/ -snet_sdk.egg-info/ -snet_sdk/resources/contracts/abi -snet_sdk/resources/contracts/networks -build/ -dist/ diff --git a/snet_sdk/MANIFEST.in b/snet_sdk/MANIFEST.in deleted file mode 100644 index 03b788b6..00000000 --- a/snet_sdk/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include snet_sdk/resources/contracts/abi/* -include snet_sdk/resources/contracts/networks/* diff --git a/snet_sdk/blockchain/package.json b/snet_sdk/blockchain/package.json deleted file mode 100644 index 733f416d..00000000 --- a/snet_sdk/blockchain/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "dependencies": { - "singularitynet-platform-contracts": "0.2.6", - "singularitynet-token-contracts": "2.0.1" - } -} diff --git a/snet_sdk/setup.py b/snet_sdk/setup.py deleted file mode 100644 index e81f6706..00000000 --- a/snet_sdk/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -from setuptools import setup, find_packages -import re - -version_dict = {} -with open("./snet_sdk/version.py") as fp: - exec(fp.read(), version_dict) - -setup( - name='snet_sdk', - version=version_dict['__version__'], - packages=find_packages(), - url='https://github.com/singnet/snet-cli/tree/master/snet_sdk', - license='MIT', - author='SingularityNET Foundation', - author_email='info@singularitynet.io', - description='SingularityNET Python SDK', - python_requires='>=3.6', - install_requires=[ - 'grpcio-tools==1.17.1', - 'ecdsa==0.13', - 'web3==4.2.1', - 'ipfsapi==0.4.2.post1', - 'rfc3986==1.1.0' - ], - include_package_data=True -) diff --git a/snet_sdk/snet_sdk/contract.py b/snet_sdk/snet_sdk/contract.py deleted file mode 100644 index c23eaddc..00000000 --- a/snet_sdk/snet_sdk/contract.py +++ /dev/null @@ -1,27 +0,0 @@ -class Contract: - def __init__(self, w3, address, abi): - self.w3 = w3 - self.contract = self.w3.eth.contract(address=self.w3.toChecksumAddress(address), abi=abi) - self.abi = abi - - def call(self, function_name, *positional_inputs, **named_inputs): - return getattr(self.contract.functions, function_name)(*positional_inputs, **named_inputs).call() - - def build_transaction(self, function_name, from_address, gas_price, *positional_inputs, **named_inputs): - nonce = self.w3.eth.getTransactionCount(from_address) - chain_id = self.w3.version.network - return getattr(self.contract.functions, function_name)(*positional_inputs, **named_inputs).buildTransaction({ - "from": from_address, - "nonce": nonce, - "gasPrice": gas_price, - "chainId": int(chain_id) - }) - - def process_receipt(self, receipt): - events = [] - - contract_events = map(lambda e: e["name"], filter(lambda e: e["type"] == "event", self.abi)) - for contract_event in contract_events: - events.extend(getattr(self.contract.events, contract_event)().processReceipt(receipt)) - - return events diff --git a/snet_sdk/snet_sdk/state_service_pb2.py b/snet_sdk/snet_sdk/state_service_pb2.py deleted file mode 100644 index bac2e3fa..00000000 --- a/snet_sdk/snet_sdk/state_service_pb2.py +++ /dev/null @@ -1,153 +0,0 @@ -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: state_service.proto - -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) -from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection -from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor.FileDescriptor( - name='state_service.proto', - package='escrow', - syntax='proto3', - serialized_pb=_b('\n\x13state_service.proto\x12\x06\x65scrow\"<\n\x13\x43hannelStateRequest\x12\x12\n\nchannel_id\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c\"d\n\x11\x43hannelStateReply\x12\x15\n\rcurrent_nonce\x18\x01 \x01(\x0c\x12\x1d\n\x15\x63urrent_signed_amount\x18\x02 \x01(\x0c\x12\x19\n\x11\x63urrent_signature\x18\x03 \x01(\x0c\x32i\n\x1aPaymentChannelStateService\x12K\n\x0fGetChannelState\x12\x1b.escrow.ChannelStateRequest\x1a\x19.escrow.ChannelStateReply\"\x00\x62\x06proto3') -) - - - - -_CHANNELSTATEREQUEST = _descriptor.Descriptor( - name='ChannelStateRequest', - full_name='escrow.ChannelStateRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='channel_id', full_name='escrow.ChannelStateRequest.channel_id', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='signature', full_name='escrow.ChannelStateRequest.signature', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=31, - serialized_end=91, -) - - -_CHANNELSTATEREPLY = _descriptor.Descriptor( - name='ChannelStateReply', - full_name='escrow.ChannelStateReply', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='current_nonce', full_name='escrow.ChannelStateReply.current_nonce', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='current_signed_amount', full_name='escrow.ChannelStateReply.current_signed_amount', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='current_signature', full_name='escrow.ChannelStateReply.current_signature', index=2, - number=3, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=93, - serialized_end=193, -) - -DESCRIPTOR.message_types_by_name['ChannelStateRequest'] = _CHANNELSTATEREQUEST -DESCRIPTOR.message_types_by_name['ChannelStateReply'] = _CHANNELSTATEREPLY -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -ChannelStateRequest = _reflection.GeneratedProtocolMessageType('ChannelStateRequest', (_message.Message,), dict( - DESCRIPTOR = _CHANNELSTATEREQUEST, - __module__ = 'state_service_pb2' - # @@protoc_insertion_point(class_scope:escrow.ChannelStateRequest) - )) -_sym_db.RegisterMessage(ChannelStateRequest) - -ChannelStateReply = _reflection.GeneratedProtocolMessageType('ChannelStateReply', (_message.Message,), dict( - DESCRIPTOR = _CHANNELSTATEREPLY, - __module__ = 'state_service_pb2' - # @@protoc_insertion_point(class_scope:escrow.ChannelStateReply) - )) -_sym_db.RegisterMessage(ChannelStateReply) - - - -_PAYMENTCHANNELSTATESERVICE = _descriptor.ServiceDescriptor( - name='PaymentChannelStateService', - full_name='escrow.PaymentChannelStateService', - file=DESCRIPTOR, - index=0, - options=None, - serialized_start=195, - serialized_end=300, - methods=[ - _descriptor.MethodDescriptor( - name='GetChannelState', - full_name='escrow.PaymentChannelStateService.GetChannelState', - index=0, - containing_service=None, - input_type=_CHANNELSTATEREQUEST, - output_type=_CHANNELSTATEREPLY, - options=None, - ), -]) -_sym_db.RegisterServiceDescriptor(_PAYMENTCHANNELSTATESERVICE) - -DESCRIPTOR.services_by_name['PaymentChannelStateService'] = _PAYMENTCHANNELSTATESERVICE - -# @@protoc_insertion_point(module_scope) diff --git a/snet_sdk/snet_sdk/state_service_pb2_grpc.py b/snet_sdk/snet_sdk/state_service_pb2_grpc.py deleted file mode 100644 index bb7e8122..00000000 --- a/snet_sdk/snet_sdk/state_service_pb2_grpc.py +++ /dev/null @@ -1,54 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -import grpc - -import snet_sdk.state_service_pb2 as state__service__pb2 - - -class PaymentChannelStateServiceStub(object): - """PaymentChannelStateService contains methods to get the MultiPartyEscrow - payment channel state. - channel_id, channel_nonce, value and amount fields below in fact are - Solidity uint256 values. Which are big-endian integers padded by zeros, see - https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#formal-specification-of-the-encoding - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.GetChannelState = channel.unary_unary( - '/escrow.PaymentChannelStateService/GetChannelState', - request_serializer=state__service__pb2.ChannelStateRequest.SerializeToString, - response_deserializer=state__service__pb2.ChannelStateReply.FromString, - ) - - -class PaymentChannelStateServiceServicer(object): - """PaymentChannelStateService contains methods to get the MultiPartyEscrow - payment channel state. - channel_id, channel_nonce, value and amount fields below in fact are - Solidity uint256 values. Which are big-endian integers padded by zeros, see - https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#formal-specification-of-the-encoding - """ - - def GetChannelState(self, request, context): - """GetChannelState method returns a channel state by channel id. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_PaymentChannelStateServiceServicer_to_server(servicer, server): - rpc_method_handlers = { - 'GetChannelState': grpc.unary_unary_rpc_method_handler( - servicer.GetChannelState, - request_deserializer=state__service__pb2.ChannelStateRequest.FromString, - response_serializer=state__service__pb2.ChannelStateReply.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'escrow.PaymentChannelStateService', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) diff --git a/snet_sdk/snet_sdk/utils.py b/snet_sdk/snet_sdk/utils.py deleted file mode 100644 index 5654523d..00000000 --- a/snet_sdk/snet_sdk/utils.py +++ /dev/null @@ -1,41 +0,0 @@ -import os -import json -from pathlib import PurePath - -import web3 -import ecdsa -import hashlib - - -cur_dir = PurePath(os.path.realpath(__file__)).parent - - -def get_contract_object(w3, contract_file): - with open(cur_dir.joinpath("resources", "contracts", "abi", contract_file)) as f: - abi = json.load(f) - with open(cur_dir.joinpath("resources", "contracts", "networks", contract_file)) as f: - networks = json.load(f) - address = w3.toChecksumAddress(networks[w3.version.network]["address"]) - return w3.eth.contract(abi=abi, address=address) - - -def get_contract_deployment_block(w3, contract_file): - with open(cur_dir.joinpath("resources", "contracts", "networks", contract_file)) as f: - networks = json.load(f) - txn_hash = networks[w3.version.network]["transactionHash"] - return w3.eth.getTransactionReceipt(txn_hash).blockNumber - - -def normalize_private_key(private_key): - if private_key.startswith("0x"): - private_key = bytes(bytearray.fromhex(private_key[2:])) - else: - private_key = bytes(bytearray.fromhex(private_key)) - return private_key - - -def get_address_from_private(private_key): - public_key = ecdsa.SigningKey.from_string(string=private_key, - curve=ecdsa.SECP256k1, - hashfunc=hashlib.sha256).get_verifying_key() - return web3.Web3.toChecksumAddress("0x" + web3.Web3.sha3(hexstr=public_key.to_string().hex())[12:].hex()) diff --git a/snet_sdk/snet_sdk/version.py b/snet_sdk/snet_sdk/version.py deleted file mode 100644 index ae736254..00000000 --- a/snet_sdk/snet_sdk/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "0.1.3"