diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..78f30c8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,37 @@ +[build-system] +requires = [ + "setuptools>=61.0", + "wheel", + "protobuf~=6.30", + "grpcio-tools~=1.59" +] +build-backend = "setuptools.build_meta" + +[project] +name = "snet-sdk" +version = "5.1.0" +description = "SingularityNET Python SDK" +readme = "README.md" +requires-python = ">=3.10" +license = "MIT" +authors = [ + {name = "SingularityNET Foundation", email = "info@singularitynet.io"} +] +urls = {Homepage = "https://github.com/singnet/snet-sdk-python"} + +# Cleaned dependencies list +dependencies = [ + "protobuf~=6.30", + "grpcio~=1.71", + "grpcio-tools~=1.71", + "grpcio-health-checking~=1.71", + "wheel~=0.45", + "rlp~=4.0", + "ipfshttpclient==0.4.13.2", + "snet-contracts==1.0.1", + "lighthouseweb3~=0.1.4", + "py-multihash~=3.0" +] + +[tool.setuptools.packages.find] +include = ["snet*"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 91fc6b0..ae67cb6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,10 @@ -protobuf==5.* -grpcio-tools>=1.71.0 -wheel>=0.45.0 -rlp>=4.1.0 -web3==7.* -ipfshttpclient==0.4.13 -rfc3986>=2.0.0 -base58>=2.1.1 -grpcio-health-checking>=1.71.0 +protobuf~=6.30 +grpcio~=1.71 +grpcio-tools~=1.71 +grpcio-health-checking~=1.71 +wheel~=0.45 +rlp~=4.0 +ipfshttpclient==0.4.13.2 snet-contracts==1.0.1 -lighthouseweb3>=0.1.4 -pymultihash==0.* \ No newline at end of file +lighthouseweb3~=0.1.4 +py-multihash~=3.0 diff --git a/setup.py b/setup.py index 2497a9e..82676d8 100644 --- a/setup.py +++ b/setup.py @@ -1,34 +1,73 @@ -import os -from setuptools import find_namespace_packages, setup +from pathlib import Path +from setuptools import setup +from setuptools.command.develop import develop as _develop +from setuptools.command.install import install as _install +from setuptools.command.build_py import build_py as _build_py +from grpc_tools import protoc +import importlib.resources -from version import __version__ -PACKAGE_NAME = 'snet-sdk' +def install_and_compile_proto(): + """ + Compiles protobuf files directly. + """ + proto_dir = Path(__file__).absolute().parent.joinpath( + "snet", "sdk", "resources", "proto") + grpc_protos_include = str(importlib.resources.files('grpc_tools').joinpath('_proto')) -this_directory = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f: - long_description = f.read() + print(f"Proto directory: {proto_dir}") + print(f"Grpc include directory: {grpc_protos_include}") + if not proto_dir.exists(): + print(f"Warning: Proto directory not found at {proto_dir}") + return -with open("./requirements.txt") as f: - requirements_str = f.read() -requirements = requirements_str.split("\n") + # glob('*.proto') is non-recursive. It will NOT look inside subfolders. + for fn in proto_dir.glob('*.proto'): + print(f"Compiling protobuf: {fn}") + + command = [ + 'grpc_tools.protoc', + f'-I{proto_dir}', + f'-I{grpc_protos_include}', + f'--python_out={proto_dir}', + f'--grpc_python_out={proto_dir}', + str(fn) + ] + + if protoc.main(command) != 0: + print(f"Error: Failed to compile {fn}") + raise RuntimeError(f"Protocol buffer compilation failed for {fn}") + + +class build_py(_build_py): + """ + This is the hook used by 'python -m build'. + """ + def run(self): + self.execute(install_and_compile_proto, (), msg="Compile protocol buffers") + _build_py.run(self) + + +class develop(_develop): + """Post-installation for development mode (pip install -e .).""" + def run(self): + self.execute(install_and_compile_proto, (), msg="Compile protocol buffers") + _develop.run(self) + + +class install(_install): + """Post-installation for legacy installation mode.""" + def run(self): + self.execute(install_and_compile_proto, (), msg="Compile protocol buffers") + _install.run(self) setup( - name=PACKAGE_NAME, - version=__version__, - packages=find_namespace_packages(include=['snet*']), - namespace_packages=['snet'], - url='https://github.com/singnet/snet-sdk-python', - author='SingularityNET Foundation', - author_email='info@singularitynet.io', - description='SingularityNET Python SDK', - long_description=long_description, - long_description_content_type='text/markdown', - license='MIT', - python_requires='>=3.10', - install_requires=requirements, - include_package_data=True -) + cmdclass={ + 'develop': develop, + 'install': install, + 'build_py': build_py, + }, +) \ No newline at end of file diff --git a/snet/sdk/resources/proto/control_service_pb2.py b/snet/sdk/resources/proto/control_service_pb2.py deleted file mode 100644 index 43b685a..0000000 --- a/snet/sdk/resources/proto/control_service_pb2.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: control_service.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15\x63ontrol_service.proto\x12\x06\x65scrow\"W\n\x16GetPaymentsListRequest\x12\x13\n\x0bmpe_address\x18\x01 \x01(\t\x12\x15\n\rcurrent_block\x18\x02 \x01(\x04\x12\x11\n\tsignature\x18\x03 \x01(\x0c\"O\n\x11StartClaimRequest\x12\x13\n\x0bmpe_address\x18\x01 \x01(\t\x12\x12\n\nchannel_id\x18\x02 \x01(\x0c\x12\x11\n\tsignature\x18\x03 \x01(\x0c\"c\n\x0cPaymentReply\x12\x12\n\nchannel_id\x18\x01 \x01(\x0c\x12\x15\n\rchannel_nonce\x18\x02 \x01(\x0c\x12\x15\n\rsigned_amount\x18\x03 \x01(\x0c\x12\x11\n\tsignature\x18\x04 \x01(\x0c\";\n\x11PaymentsListReply\x12&\n\x08payments\x18\x01 \x03(\x0b\x32\x14.escrow.PaymentReply2\xfc\x01\n\x16ProviderControlService\x12O\n\x10GetListUnclaimed\x12\x1e.escrow.GetPaymentsListRequest\x1a\x19.escrow.PaymentsListReply\"\x00\x12P\n\x11GetListInProgress\x12\x1e.escrow.GetPaymentsListRequest\x1a\x19.escrow.PaymentsListReply\"\x00\x12?\n\nStartClaim\x12\x19.escrow.StartClaimRequest\x1a\x14.escrow.PaymentReply\"\x00\x62\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'control_service_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - _globals['_GETPAYMENTSLISTREQUEST']._serialized_start=33 - _globals['_GETPAYMENTSLISTREQUEST']._serialized_end=120 - _globals['_STARTCLAIMREQUEST']._serialized_start=122 - _globals['_STARTCLAIMREQUEST']._serialized_end=201 - _globals['_PAYMENTREPLY']._serialized_start=203 - _globals['_PAYMENTREPLY']._serialized_end=302 - _globals['_PAYMENTSLISTREPLY']._serialized_start=304 - _globals['_PAYMENTSLISTREPLY']._serialized_end=363 - _globals['_PROVIDERCONTROLSERVICE']._serialized_start=366 - _globals['_PROVIDERCONTROLSERVICE']._serialized_end=618 -# @@protoc_insertion_point(module_scope) diff --git a/snet/sdk/resources/proto/control_service_pb2_grpc.py b/snet/sdk/resources/proto/control_service_pb2_grpc.py deleted file mode 100644 index 818e476..0000000 --- a/snet/sdk/resources/proto/control_service_pb2_grpc.py +++ /dev/null @@ -1,137 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -import control_service_pb2 as control__service__pb2 - - -class ProviderControlServiceStub(object): - """Missing associated documentation comment in .proto file.""" - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.GetListUnclaimed = channel.unary_unary( - '/escrow.ProviderControlService/GetListUnclaimed', - request_serializer=control__service__pb2.GetPaymentsListRequest.SerializeToString, - response_deserializer=control__service__pb2.PaymentsListReply.FromString, - ) - self.GetListInProgress = channel.unary_unary( - '/escrow.ProviderControlService/GetListInProgress', - request_serializer=control__service__pb2.GetPaymentsListRequest.SerializeToString, - response_deserializer=control__service__pb2.PaymentsListReply.FromString, - ) - self.StartClaim = channel.unary_unary( - '/escrow.ProviderControlService/StartClaim', - request_serializer=control__service__pb2.StartClaimRequest.SerializeToString, - response_deserializer=control__service__pb2.PaymentReply.FromString, - ) - - -class ProviderControlServiceServicer(object): - """Missing associated documentation comment in .proto file.""" - - def GetListUnclaimed(self, request, context): - """get list of all unclaimed "payments". - in PaymentsSignatureReply signatures MUST be omited - if signature field is present then response should be considered as invalid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def GetListInProgress(self, request, context): - """get list of all payments in progress - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def StartClaim(self, request, context): - """initilize claim for specific channel - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_ProviderControlServiceServicer_to_server(servicer, server): - rpc_method_handlers = { - 'GetListUnclaimed': grpc.unary_unary_rpc_method_handler( - servicer.GetListUnclaimed, - request_deserializer=control__service__pb2.GetPaymentsListRequest.FromString, - response_serializer=control__service__pb2.PaymentsListReply.SerializeToString, - ), - 'GetListInProgress': grpc.unary_unary_rpc_method_handler( - servicer.GetListInProgress, - request_deserializer=control__service__pb2.GetPaymentsListRequest.FromString, - response_serializer=control__service__pb2.PaymentsListReply.SerializeToString, - ), - 'StartClaim': grpc.unary_unary_rpc_method_handler( - servicer.StartClaim, - request_deserializer=control__service__pb2.StartClaimRequest.FromString, - response_serializer=control__service__pb2.PaymentReply.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'escrow.ProviderControlService', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - # This class is part of an EXPERIMENTAL API. -class ProviderControlService(object): - """Missing associated documentation comment in .proto file.""" - - @staticmethod - def GetListUnclaimed(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.ProviderControlService/GetListUnclaimed', - control__service__pb2.GetPaymentsListRequest.SerializeToString, - control__service__pb2.PaymentsListReply.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def GetListInProgress(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.ProviderControlService/GetListInProgress', - control__service__pb2.GetPaymentsListRequest.SerializeToString, - control__service__pb2.PaymentsListReply.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def StartClaim(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.ProviderControlService/StartClaim', - control__service__pb2.StartClaimRequest.SerializeToString, - control__service__pb2.PaymentReply.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/snet/sdk/resources/proto/state_service_pb2.py b/snet/sdk/resources/proto/state_service_pb2.py deleted file mode 100644 index 1661c44..0000000 --- a/snet/sdk/resources/proto/state_service_pb2.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: state_service.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x13state_service.proto\x12\x06\x65scrow\"S\n\x13\x43hannelStateRequest\x12\x12\n\nchannel_id\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c\x12\x15\n\rcurrent_block\x18\x03 \x01(\x04\"\xcf\x01\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\x12\x1f\n\x17old_nonce_signed_amount\x18\x04 \x01(\x0c\x12\x1b\n\x13old_nonce_signature\x18\x05 \x01(\x0c\x12\x16\n\x0eplanned_amount\x18\x06 \x01(\x04\x12\x13\n\x0bused_amount\x18\x07 \x01(\x04\"\xba\x01\n\x17GetFreeCallTokenRequest\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12\x11\n\tsignature\x18\x02 \x01(\x0c\x12\x15\n\rcurrent_block\x18\x03 \x01(\x04\x12\x14\n\x07user_id\x18\x04 \x01(\tH\x00\x88\x01\x01\x12%\n\x18token_lifetime_in_blocks\x18\x05 \x01(\x04H\x01\x88\x01\x01\x42\n\n\x08_user_idB\x1b\n\x19_token_lifetime_in_blocks\"Q\n\rFreeCallToken\x12\r\n\x05token\x18\x01 \x01(\x0c\x12\x11\n\ttoken_hex\x18\x02 \x01(\t\x12\x1e\n\x16token_expiration_block\x18\x03 \x01(\x04\"\x8c\x01\n\x14\x46reeCallStateRequest\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\x12\x14\n\x07user_id\x18\x02 \x01(\tH\x00\x88\x01\x01\x12\x17\n\x0f\x66ree_call_token\x18\x03 \x01(\x0c\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x15\n\rcurrent_block\x18\x05 \x01(\x04\x42\n\n\x08_user_id\"2\n\x12\x46reeCallStateReply\x12\x1c\n\x14\x66ree_calls_available\x18\x01 \x01(\x04\x32i\n\x1aPaymentChannelStateService\x12K\n\x0fGetChannelState\x12\x1b.escrow.ChannelStateRequest\x1a\x19.escrow.ChannelStateReply\"\x00\x32\xb9\x01\n\x14\x46reeCallStateService\x12S\n\x15GetFreeCallsAvailable\x12\x1c.escrow.FreeCallStateRequest\x1a\x1a.escrow.FreeCallStateReply\"\x00\x12L\n\x10GetFreeCallToken\x12\x1f.escrow.GetFreeCallTokenRequest\x1a\x15.escrow.FreeCallToken\"\x00\x42,\n\x1fio.singularitynet.daemon.escrowZ\t../escrowb\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'state_service_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'\n\037io.singularitynet.daemon.escrowZ\t../escrow' - _globals['_CHANNELSTATEREQUEST']._serialized_start=31 - _globals['_CHANNELSTATEREQUEST']._serialized_end=114 - _globals['_CHANNELSTATEREPLY']._serialized_start=117 - _globals['_CHANNELSTATEREPLY']._serialized_end=324 - _globals['_GETFREECALLTOKENREQUEST']._serialized_start=327 - _globals['_GETFREECALLTOKENREQUEST']._serialized_end=513 - _globals['_FREECALLTOKEN']._serialized_start=515 - _globals['_FREECALLTOKEN']._serialized_end=596 - _globals['_FREECALLSTATEREQUEST']._serialized_start=599 - _globals['_FREECALLSTATEREQUEST']._serialized_end=739 - _globals['_FREECALLSTATEREPLY']._serialized_start=741 - _globals['_FREECALLSTATEREPLY']._serialized_end=791 - _globals['_PAYMENTCHANNELSTATESERVICE']._serialized_start=793 - _globals['_PAYMENTCHANNELSTATESERVICE']._serialized_end=898 - _globals['_FREECALLSTATESERVICE']._serialized_start=901 - _globals['_FREECALLSTATESERVICE']._serialized_end=1086 -# @@protoc_insertion_point(module_scope) diff --git a/snet/sdk/resources/proto/state_service_pb2_grpc.py b/snet/sdk/resources/proto/state_service_pb2_grpc.py deleted file mode 100644 index 6c47edb..0000000 --- a/snet/sdk/resources/proto/state_service_pb2_grpc.py +++ /dev/null @@ -1,185 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -import 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, see - https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#formal-specification-of-the-encoding - These values may be or may be not padded by zeros, service supports both - options. - """ - - 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, see - https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#formal-specification-of-the-encoding - These values may be or may be not padded by zeros, service supports both - options. - """ - - 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,)) - - - # This class is part of an EXPERIMENTAL API. -class PaymentChannelStateService(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, see - https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#formal-specification-of-the-encoding - These values may be or may be not padded by zeros, service supports both - options. - """ - - @staticmethod - def GetChannelState(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.PaymentChannelStateService/GetChannelState', - state__service__pb2.ChannelStateRequest.SerializeToString, - state__service__pb2.ChannelStateReply.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - -class FreeCallStateServiceStub(object): - """Used to determine free calls available for a given user. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.GetFreeCallsAvailable = channel.unary_unary( - '/escrow.FreeCallStateService/GetFreeCallsAvailable', - request_serializer=state__service__pb2.FreeCallStateRequest.SerializeToString, - response_deserializer=state__service__pb2.FreeCallStateReply.FromString, - ) - self.GetFreeCallToken = channel.unary_unary( - '/escrow.FreeCallStateService/GetFreeCallToken', - request_serializer=state__service__pb2.GetFreeCallTokenRequest.SerializeToString, - response_deserializer=state__service__pb2.FreeCallToken.FromString, - ) - - -class FreeCallStateServiceServicer(object): - """Used to determine free calls available for a given user. - """ - - def GetFreeCallsAvailable(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def GetFreeCallToken(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_FreeCallStateServiceServicer_to_server(servicer, server): - rpc_method_handlers = { - 'GetFreeCallsAvailable': grpc.unary_unary_rpc_method_handler( - servicer.GetFreeCallsAvailable, - request_deserializer=state__service__pb2.FreeCallStateRequest.FromString, - response_serializer=state__service__pb2.FreeCallStateReply.SerializeToString, - ), - 'GetFreeCallToken': grpc.unary_unary_rpc_method_handler( - servicer.GetFreeCallToken, - request_deserializer=state__service__pb2.GetFreeCallTokenRequest.FromString, - response_serializer=state__service__pb2.FreeCallToken.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'escrow.FreeCallStateService', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - # This class is part of an EXPERIMENTAL API. -class FreeCallStateService(object): - """Used to determine free calls available for a given user. - """ - - @staticmethod - def GetFreeCallsAvailable(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.FreeCallStateService/GetFreeCallsAvailable', - state__service__pb2.FreeCallStateRequest.SerializeToString, - state__service__pb2.FreeCallStateReply.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def GetFreeCallToken(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.FreeCallStateService/GetFreeCallToken', - state__service__pb2.GetFreeCallTokenRequest.SerializeToString, - state__service__pb2.FreeCallToken.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/snet/sdk/resources/proto/token_service_pb2.py b/snet/sdk/resources/proto/token_service_pb2.py deleted file mode 100644 index 038ca7f..0000000 --- a/snet/sdk/resources/proto/token_service_pb2.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: token_service.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x13token_service.proto\x12\x06\x65scrow\"\x93\x01\n\x0cTokenRequest\x12\x12\n\nchannel_id\x18\x01 \x01(\x04\x12\x15\n\rcurrent_nonce\x18\x02 \x01(\x04\x12\x15\n\rsigned_amount\x18\x03 \x01(\x04\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x15\n\rcurrent_block\x18\x05 \x01(\x04\x12\x17\n\x0f\x63laim_signature\x18\x06 \x01(\x0c\"\\\n\nTokenReply\x12\x12\n\nchannel_id\x18\x01 \x01(\x04\x12\r\n\x05token\x18\x02 \x01(\t\x12\x16\n\x0eplanned_amount\x18\x03 \x01(\x04\x12\x13\n\x0bused_amount\x18\x04 \x01(\x04\x32\x46\n\x0cTokenService\x12\x36\n\x08GetToken\x12\x14.escrow.TokenRequest\x1a\x12.escrow.TokenReply\"\x00\x42!\n\x1fio.singularitynet.daemon.escrowb\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'token_service_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'\n\037io.singularitynet.daemon.escrow' - _globals['_TOKENREQUEST']._serialized_start=32 - _globals['_TOKENREQUEST']._serialized_end=179 - _globals['_TOKENREPLY']._serialized_start=181 - _globals['_TOKENREPLY']._serialized_end=273 - _globals['_TOKENSERVICE']._serialized_start=275 - _globals['_TOKENSERVICE']._serialized_end=345 -# @@protoc_insertion_point(module_scope) diff --git a/snet/sdk/resources/proto/token_service_pb2_grpc.py b/snet/sdk/resources/proto/token_service_pb2_grpc.py deleted file mode 100644 index dd1bc73..0000000 --- a/snet/sdk/resources/proto/token_service_pb2_grpc.py +++ /dev/null @@ -1,98 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -import token_service_pb2 as token__service__pb2 - - -class TokenServiceStub(object): - """It is expected that the user would call the GetChannelState to Determine the Current state of the Channel - Based on the usage forecast, the user/client will have to sign for an amount L + U , where L is the last amount Signed - and U is the amount based on expected usage. - Please be aware that the Signing up an amount upfront ( Pre Paid) does come with a risk and hence the - user must exercise caution on the amount signed specially with new service providers. - If there is no need of making concurrent calls then you may consider pay per mode. - Using a Token, the Client can now make concurrent calls, which was not supported previously with the pay per mode. - However the pay per mode is a lot secure than the pre-paid mode. - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.GetToken = channel.unary_unary( - '/escrow.TokenService/GetToken', - request_serializer=token__service__pb2.TokenRequest.SerializeToString, - response_deserializer=token__service__pb2.TokenReply.FromString, - ) - - -class TokenServiceServicer(object): - """It is expected that the user would call the GetChannelState to Determine the Current state of the Channel - Based on the usage forecast, the user/client will have to sign for an amount L + U , where L is the last amount Signed - and U is the amount based on expected usage. - Please be aware that the Signing up an amount upfront ( Pre Paid) does come with a risk and hence the - user must exercise caution on the amount signed specially with new service providers. - If there is no need of making concurrent calls then you may consider pay per mode. - Using a Token, the Client can now make concurrent calls, which was not supported previously with the pay per mode. - However the pay per mode is a lot secure than the pre-paid mode. - """ - - def GetToken(self, request, context): - """GetToken method checks the Signature sent and returns a Token - 1) The Signature is valid and has to be signed in the below format - "__MPE_claim_message"+MpeContractAddress+ChannelID+ChannelNonce+SignedAmount - Signature is to let the Service Provider make a claim - 2) Signed amount >= Last amount Signed. - if Signed amount == Last Signed amount , then check if planned_amount < used_amount - if Signed amount > Last Signed amount , then update the planned amount = Signed Amount - GetToken method in a way behaves as a renew Token too!. - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_TokenServiceServicer_to_server(servicer, server): - rpc_method_handlers = { - 'GetToken': grpc.unary_unary_rpc_method_handler( - servicer.GetToken, - request_deserializer=token__service__pb2.TokenRequest.FromString, - response_serializer=token__service__pb2.TokenReply.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'escrow.TokenService', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - # This class is part of an EXPERIMENTAL API. -class TokenService(object): - """It is expected that the user would call the GetChannelState to Determine the Current state of the Channel - Based on the usage forecast, the user/client will have to sign for an amount L + U , where L is the last amount Signed - and U is the amount based on expected usage. - Please be aware that the Signing up an amount upfront ( Pre Paid) does come with a risk and hence the - user must exercise caution on the amount signed specially with new service providers. - If there is no need of making concurrent calls then you may consider pay per mode. - Using a Token, the Client can now make concurrent calls, which was not supported previously with the pay per mode. - However the pay per mode is a lot secure than the pre-paid mode. - """ - - @staticmethod - def GetToken(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/escrow.TokenService/GetToken', - token__service__pb2.TokenRequest.SerializeToString, - token__service__pb2.TokenReply.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/snet/sdk/resources/proto/training_daemon_pb2.py b/snet/sdk/resources/proto/training_daemon_pb2.py deleted file mode 100644 index 6923330..0000000 --- a/snet/sdk/resources/proto/training_daemon_pb2.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: training_daemon.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2 -from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 -import training_pb2 as training__pb2 -from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15training_daemon.proto\x12\x08training\x1a google/protobuf/descriptor.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x0etraining.proto\x1a\x1bgoogle/protobuf/empty.proto\"i\n\x14\x41uthorizationDetails\x12\x15\n\rcurrent_block\x18\x01 \x01(\x04\x12\x0f\n\x07message\x18\x02 \x01(\t\x12\x11\n\tsignature\x18\x03 \x01(\x0c\x12\x16\n\x0esigner_address\x18\x04 \x01(\t\"k\n\x0fNewModelRequest\x12\x35\n\rauthorization\x18\x01 \x01(\x0b\x32\x1e.training.AuthorizationDetails\x12!\n\x05model\x18\x02 \x01(\x0b\x32\x12.training.NewModel\"z\n\x13\x41uthValidateRequest\x12\x35\n\rauthorization\x18\x01 \x01(\x0b\x32\x1e.training.AuthorizationDetails\x12\x10\n\x08model_id\x18\x02 \x01(\t\x12\x1a\n\x12training_data_link\x18\x03 \x01(\t\"~\n\x18UploadAndValidateRequest\x12\x35\n\rauthorization\x18\x01 \x01(\x0b\x32\x1e.training.AuthorizationDetails\x12+\n\x0cupload_input\x18\x02 \x01(\x0b\x32\x15.training.UploadInput\"X\n\rCommonRequest\x12\x35\n\rauthorization\x18\x01 \x01(\x0b\x32\x1e.training.AuthorizationDetails\x12\x10\n\x08model_id\x18\x02 \x01(\t\"\xc5\x01\n\x12UpdateModelRequest\x12\x35\n\rauthorization\x18\x01 \x01(\x0b\x32\x1e.training.AuthorizationDetails\x12\x10\n\x08model_id\x18\x02 \x01(\t\x12\x17\n\nmodel_name\x18\x03 \x01(\tH\x00\x88\x01\x01\x12\x18\n\x0b\x64\x65scription\x18\x04 \x01(\tH\x01\x88\x01\x01\x12\x14\n\x0c\x61\x64\x64ress_list\x18\x05 \x03(\tB\r\n\x0b_model_nameB\x0e\n\x0c_description\"A\n\x0eModelsResponse\x12/\n\x0elist_of_models\x18\x01 \x03(\x0b\x32\x17.training.ModelResponse\"^\n\x15MethodMetadataRequest\x12\x10\n\x08model_id\x18\x01 \x01(\t\x12\x18\n\x10grpc_method_name\x18\x02 \x01(\t\x12\x19\n\x11grpc_service_name\x18\x03 \x01(\t\"\x93\x02\n\x10\x41llModelsRequest\x12\x35\n\rauthorization\x18\x01 \x01(\x0b\x32\x1e.training.AuthorizationDetails\x12\"\n\x08statuses\x18\x03 \x03(\x0e\x32\x10.training.Status\x12\x16\n\tis_public\x18\x04 \x01(\x08H\x00\x88\x01\x01\x12\x18\n\x10grpc_method_name\x18\x05 \x01(\t\x12\x19\n\x11grpc_service_name\x18\x06 \x01(\t\x12\x0c\n\x04name\x18\x07 \x01(\t\x12\x1a\n\x12\x63reated_by_address\x18\x08 \x01(\t\x12\x11\n\tpage_size\x18\t \x01(\x04\x12\x0c\n\x04page\x18\n \x01(\x04\x42\x0c\n\n_is_public\"\xe2\x01\n\x10TrainingMetadata\x12\x17\n\x0ftrainingEnabled\x18\x01 \x01(\x08\x12\x17\n\x0ftrainingInProto\x18\x02 \x01(\x08\x12H\n\x0ftrainingMethods\x18\x03 \x03(\x0b\x32/.training.TrainingMetadata.TrainingMethodsEntry\x1aR\n\x14TrainingMethodsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.ListValue:\x02\x38\x01\"\x8d\x02\n\x0eMethodMetadata\x12\x1a\n\x10\x64\x65\x66\x61ult_model_id\x18\xd1\x86\x03 \x01(\t\x12\x1d\n\x13max_models_per_user\x18\xd2\x86\x03 \x01(\x04\x12\x1d\n\x13\x64\x61taset_max_size_mb\x18\xd3\x86\x03 \x01(\x04\x12!\n\x17\x64\x61taset_max_count_files\x18\xd4\x86\x03 \x01(\x04\x12)\n\x1f\x64\x61taset_max_size_single_file_mb\x18\xd5\x86\x03 \x01(\x04\x12\x1c\n\x12\x64\x61taset_files_type\x18\xd6\x86\x03 \x01(\t\x12\x16\n\x0c\x64\x61taset_type\x18\xd7\x86\x03 \x01(\t\x12\x1d\n\x13\x64\x61taset_description\x18\xd8\x86\x03 \x01(\t2\x93\x07\n\x06\x44\x61\x65mon\x12\x44\n\x0c\x63reate_model\x12\x19.training.NewModelRequest\x1a\x17.training.ModelResponse\"\x00\x12R\n\x14validate_model_price\x12\x1d.training.AuthValidateRequest\x1a\x19.training.PriceInBaseUnit\"\x00\x12W\n\x13upload_and_validate\x12\".training.UploadAndValidateRequest\x1a\x18.training.StatusResponse\"\x00(\x01\x12K\n\x0evalidate_model\x12\x1d.training.AuthValidateRequest\x1a\x18.training.StatusResponse\"\x00\x12I\n\x11train_model_price\x12\x17.training.CommonRequest\x1a\x19.training.PriceInBaseUnit\"\x00\x12\x42\n\x0btrain_model\x12\x17.training.CommonRequest\x1a\x18.training.StatusResponse\"\x00\x12\x43\n\x0c\x64\x65lete_model\x12\x17.training.CommonRequest\x1a\x18.training.StatusResponse\"\x00\x12H\n\x0eget_all_models\x12\x1a.training.AllModelsRequest\x1a\x18.training.ModelsResponse\"\x00\x12?\n\tget_model\x12\x17.training.CommonRequest\x1a\x17.training.ModelResponse\"\x00\x12G\n\x0cupdate_model\x12\x1c.training.UpdateModelRequest\x1a\x17.training.ModelResponse\"\x00\x12M\n\x15get_training_metadata\x12\x16.google.protobuf.Empty\x1a\x1a.training.TrainingMetadata\"\x00\x12R\n\x13get_method_metadata\x12\x1f.training.MethodMetadataRequest\x1a\x18.training.MethodMetadata\"\x00\x42,Z*github.com/singnet/snet-daemon/v5/trainingb\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'training_daemon_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'Z*github.com/singnet/snet-daemon/v5/training' - _TRAININGMETADATA_TRAININGMETHODSENTRY._options = None - _TRAININGMETADATA_TRAININGMETHODSENTRY._serialized_options = b'8\001' - _globals['_AUTHORIZATIONDETAILS']._serialized_start=144 - _globals['_AUTHORIZATIONDETAILS']._serialized_end=249 - _globals['_NEWMODELREQUEST']._serialized_start=251 - _globals['_NEWMODELREQUEST']._serialized_end=358 - _globals['_AUTHVALIDATEREQUEST']._serialized_start=360 - _globals['_AUTHVALIDATEREQUEST']._serialized_end=482 - _globals['_UPLOADANDVALIDATEREQUEST']._serialized_start=484 - _globals['_UPLOADANDVALIDATEREQUEST']._serialized_end=610 - _globals['_COMMONREQUEST']._serialized_start=612 - _globals['_COMMONREQUEST']._serialized_end=700 - _globals['_UPDATEMODELREQUEST']._serialized_start=703 - _globals['_UPDATEMODELREQUEST']._serialized_end=900 - _globals['_MODELSRESPONSE']._serialized_start=902 - _globals['_MODELSRESPONSE']._serialized_end=967 - _globals['_METHODMETADATAREQUEST']._serialized_start=969 - _globals['_METHODMETADATAREQUEST']._serialized_end=1063 - _globals['_ALLMODELSREQUEST']._serialized_start=1066 - _globals['_ALLMODELSREQUEST']._serialized_end=1341 - _globals['_TRAININGMETADATA']._serialized_start=1344 - _globals['_TRAININGMETADATA']._serialized_end=1570 - _globals['_TRAININGMETADATA_TRAININGMETHODSENTRY']._serialized_start=1488 - _globals['_TRAININGMETADATA_TRAININGMETHODSENTRY']._serialized_end=1570 - _globals['_METHODMETADATA']._serialized_start=1573 - _globals['_METHODMETADATA']._serialized_end=1842 - _globals['_DAEMON']._serialized_start=1845 - _globals['_DAEMON']._serialized_end=2760 -# @@protoc_insertion_point(module_scope) diff --git a/snet/sdk/resources/proto/training_daemon_pb2_grpc.py b/snet/sdk/resources/proto/training_daemon_pb2_grpc.py deleted file mode 100644 index 24378b1..0000000 --- a/snet/sdk/resources/proto/training_daemon_pb2_grpc.py +++ /dev/null @@ -1,445 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 -import training_daemon_pb2 as training__daemon__pb2 -import training_pb2 as training__pb2 - - -class DaemonStub(object): - """These methods are implemented only by the daemon; the service provider should ignore them - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.create_model = channel.unary_unary( - '/training.Daemon/create_model', - request_serializer=training__daemon__pb2.NewModelRequest.SerializeToString, - response_deserializer=training__pb2.ModelResponse.FromString, - ) - self.validate_model_price = channel.unary_unary( - '/training.Daemon/validate_model_price', - request_serializer=training__daemon__pb2.AuthValidateRequest.SerializeToString, - response_deserializer=training__pb2.PriceInBaseUnit.FromString, - ) - self.upload_and_validate = channel.stream_unary( - '/training.Daemon/upload_and_validate', - request_serializer=training__daemon__pb2.UploadAndValidateRequest.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.validate_model = channel.unary_unary( - '/training.Daemon/validate_model', - request_serializer=training__daemon__pb2.AuthValidateRequest.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.train_model_price = channel.unary_unary( - '/training.Daemon/train_model_price', - request_serializer=training__daemon__pb2.CommonRequest.SerializeToString, - response_deserializer=training__pb2.PriceInBaseUnit.FromString, - ) - self.train_model = channel.unary_unary( - '/training.Daemon/train_model', - request_serializer=training__daemon__pb2.CommonRequest.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.delete_model = channel.unary_unary( - '/training.Daemon/delete_model', - request_serializer=training__daemon__pb2.CommonRequest.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.get_all_models = channel.unary_unary( - '/training.Daemon/get_all_models', - request_serializer=training__daemon__pb2.AllModelsRequest.SerializeToString, - response_deserializer=training__daemon__pb2.ModelsResponse.FromString, - ) - self.get_model = channel.unary_unary( - '/training.Daemon/get_model', - request_serializer=training__daemon__pb2.CommonRequest.SerializeToString, - response_deserializer=training__pb2.ModelResponse.FromString, - ) - self.update_model = channel.unary_unary( - '/training.Daemon/update_model', - request_serializer=training__daemon__pb2.UpdateModelRequest.SerializeToString, - response_deserializer=training__pb2.ModelResponse.FromString, - ) - self.get_training_metadata = channel.unary_unary( - '/training.Daemon/get_training_metadata', - request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, - response_deserializer=training__daemon__pb2.TrainingMetadata.FromString, - ) - self.get_method_metadata = channel.unary_unary( - '/training.Daemon/get_method_metadata', - request_serializer=training__daemon__pb2.MethodMetadataRequest.SerializeToString, - response_deserializer=training__daemon__pb2.MethodMetadata.FromString, - ) - - -class DaemonServicer(object): - """These methods are implemented only by the daemon; the service provider should ignore them - """ - - def create_model(self, request, context): - """Free - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def validate_model_price(self, request, context): - """Free - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def upload_and_validate(self, request_iterator, context): - """Paid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def validate_model(self, request, context): - """Paid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def train_model_price(self, request, context): - """Free, one signature for both train_model_price & train_model methods - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def train_model(self, request, context): - """Paid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def delete_model(self, request, context): - """Free - After deleting the model, the status becomes DELETED in etcd - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def get_all_models(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def get_model(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def update_model(self, request, context): - """Missing associated documentation comment in .proto file.""" - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def get_training_metadata(self, request, context): - """Unique methods by daemon - One signature for all getters - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def get_method_metadata(self, request, context): - """Free & without authorization - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_DaemonServicer_to_server(servicer, server): - rpc_method_handlers = { - 'create_model': grpc.unary_unary_rpc_method_handler( - servicer.create_model, - request_deserializer=training__daemon__pb2.NewModelRequest.FromString, - response_serializer=training__pb2.ModelResponse.SerializeToString, - ), - 'validate_model_price': grpc.unary_unary_rpc_method_handler( - servicer.validate_model_price, - request_deserializer=training__daemon__pb2.AuthValidateRequest.FromString, - response_serializer=training__pb2.PriceInBaseUnit.SerializeToString, - ), - 'upload_and_validate': grpc.stream_unary_rpc_method_handler( - servicer.upload_and_validate, - request_deserializer=training__daemon__pb2.UploadAndValidateRequest.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'validate_model': grpc.unary_unary_rpc_method_handler( - servicer.validate_model, - request_deserializer=training__daemon__pb2.AuthValidateRequest.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'train_model_price': grpc.unary_unary_rpc_method_handler( - servicer.train_model_price, - request_deserializer=training__daemon__pb2.CommonRequest.FromString, - response_serializer=training__pb2.PriceInBaseUnit.SerializeToString, - ), - 'train_model': grpc.unary_unary_rpc_method_handler( - servicer.train_model, - request_deserializer=training__daemon__pb2.CommonRequest.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'delete_model': grpc.unary_unary_rpc_method_handler( - servicer.delete_model, - request_deserializer=training__daemon__pb2.CommonRequest.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'get_all_models': grpc.unary_unary_rpc_method_handler( - servicer.get_all_models, - request_deserializer=training__daemon__pb2.AllModelsRequest.FromString, - response_serializer=training__daemon__pb2.ModelsResponse.SerializeToString, - ), - 'get_model': grpc.unary_unary_rpc_method_handler( - servicer.get_model, - request_deserializer=training__daemon__pb2.CommonRequest.FromString, - response_serializer=training__pb2.ModelResponse.SerializeToString, - ), - 'update_model': grpc.unary_unary_rpc_method_handler( - servicer.update_model, - request_deserializer=training__daemon__pb2.UpdateModelRequest.FromString, - response_serializer=training__pb2.ModelResponse.SerializeToString, - ), - 'get_training_metadata': grpc.unary_unary_rpc_method_handler( - servicer.get_training_metadata, - request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, - response_serializer=training__daemon__pb2.TrainingMetadata.SerializeToString, - ), - 'get_method_metadata': grpc.unary_unary_rpc_method_handler( - servicer.get_method_metadata, - request_deserializer=training__daemon__pb2.MethodMetadataRequest.FromString, - response_serializer=training__daemon__pb2.MethodMetadata.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'training.Daemon', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - # This class is part of an EXPERIMENTAL API. -class Daemon(object): - """These methods are implemented only by the daemon; the service provider should ignore them - """ - - @staticmethod - def create_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/create_model', - training__daemon__pb2.NewModelRequest.SerializeToString, - training__pb2.ModelResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def validate_model_price(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/validate_model_price', - training__daemon__pb2.AuthValidateRequest.SerializeToString, - training__pb2.PriceInBaseUnit.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def upload_and_validate(request_iterator, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.stream_unary(request_iterator, target, '/training.Daemon/upload_and_validate', - training__daemon__pb2.UploadAndValidateRequest.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def validate_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/validate_model', - training__daemon__pb2.AuthValidateRequest.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def train_model_price(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/train_model_price', - training__daemon__pb2.CommonRequest.SerializeToString, - training__pb2.PriceInBaseUnit.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def train_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/train_model', - training__daemon__pb2.CommonRequest.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def delete_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/delete_model', - training__daemon__pb2.CommonRequest.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def get_all_models(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/get_all_models', - training__daemon__pb2.AllModelsRequest.SerializeToString, - training__daemon__pb2.ModelsResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def get_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/get_model', - training__daemon__pb2.CommonRequest.SerializeToString, - training__pb2.ModelResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def update_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/update_model', - training__daemon__pb2.UpdateModelRequest.SerializeToString, - training__pb2.ModelResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def get_training_metadata(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/get_training_metadata', - google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, - training__daemon__pb2.TrainingMetadata.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def get_method_metadata(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Daemon/get_method_metadata', - training__daemon__pb2.MethodMetadataRequest.SerializeToString, - training__daemon__pb2.MethodMetadata.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/snet/sdk/resources/proto/training_pb2.py b/snet/sdk/resources/proto/training_pb2.py deleted file mode 100644 index 728189e..0000000 --- a/snet/sdk/resources/proto/training_pb2.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by the protocol buffer compiler. DO NOT EDIT! -# source: training.proto -"""Generated protocol buffer code.""" -from google.protobuf import descriptor as _descriptor -from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import symbol_database as _symbol_database -from google.protobuf.internal import builder as _builder -# @@protoc_insertion_point(imports) - -_sym_db = _symbol_database.Default() - - -from google.protobuf import descriptor_pb2 as google_dot_protobuf_dot_descriptor__pb2 - - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0etraining.proto\x12\x08training\x1a google/protobuf/descriptor.proto\"\xc4\x02\n\rModelResponse\x12\x10\n\x08model_id\x18\x01 \x01(\t\x12 \n\x06status\x18\x02 \x01(\x0e\x32\x10.training.Status\x12\x14\n\x0c\x63reated_date\x18\x03 \x01(\t\x12\x14\n\x0cupdated_date\x18\x04 \x01(\t\x12\x0c\n\x04name\x18\x05 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x06 \x01(\t\x12\x18\n\x10grpc_method_name\x18\x07 \x01(\t\x12\x19\n\x11grpc_service_name\x18\x08 \x01(\t\x12\x14\n\x0c\x61\x64\x64ress_list\x18\t \x03(\t\x12\x11\n\tis_public\x18\n \x01(\x08\x12\x1a\n\x12training_data_link\x18\x0b \x01(\t\x12\x1a\n\x12\x63reated_by_address\x18\x0c \x01(\t\x12\x1a\n\x12updated_by_address\x18\r \x01(\t\"\xca\x01\n\x08NewModel\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x02 \x01(\t\x12\x18\n\x10grpc_method_name\x18\x03 \x01(\t\x12\x19\n\x11grpc_service_name\x18\x04 \x01(\t\x12\x14\n\x0c\x61\x64\x64ress_list\x18\x05 \x03(\t\x12\x11\n\tis_public\x18\x06 \x01(\x08\x12\x17\n\x0forganization_id\x18\x07 \x01(\t\x12\x12\n\nservice_id\x18\x08 \x01(\t\x12\x10\n\x08group_id\x18\t \x01(\t\"\x1b\n\x07ModelID\x12\x10\n\x08model_id\x18\x01 \x01(\t\" \n\x0fPriceInBaseUnit\x12\r\n\x05price\x18\x01 \x01(\x04\"2\n\x0eStatusResponse\x12 \n\x06status\x18\x01 \x01(\x0e\x32\x10.training.Status\"\x92\x01\n\x0bUploadInput\x12\x10\n\x08model_id\x18\x01 \x01(\t\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x12\x11\n\tfile_name\x18\x03 \x01(\t\x12\x11\n\tfile_size\x18\x04 \x01(\x04\x12\x12\n\nbatch_size\x18\x05 \x01(\x04\x12\x14\n\x0c\x62\x61tch_number\x18\x06 \x01(\x04\x12\x13\n\x0b\x62\x61tch_count\x18\x07 \x01(\x04\"?\n\x0fValidateRequest\x12\x10\n\x08model_id\x18\x02 \x01(\t\x12\x1a\n\x12training_data_link\x18\x03 \x01(\t*n\n\x06Status\x12\x0b\n\x07\x43REATED\x10\x00\x12\x0e\n\nVALIDATING\x10\x01\x12\r\n\tVALIDATED\x10\x02\x12\x0c\n\x08TRAINING\x10\x03\x12\x10\n\x0cREADY_TO_USE\x10\x04\x12\x0b\n\x07\x45RRORED\x10\x05\x12\x0b\n\x07\x44\x45LETED\x10\x06\x32\xaa\x04\n\x05Model\x12\x37\n\x0c\x63reate_model\x12\x12.training.NewModel\x1a\x11.training.ModelID\"\x00\x12N\n\x14validate_model_price\x12\x19.training.ValidateRequest\x1a\x19.training.PriceInBaseUnit\"\x00\x12J\n\x13upload_and_validate\x12\x15.training.UploadInput\x1a\x18.training.StatusResponse\"\x00(\x01\x12G\n\x0evalidate_model\x12\x19.training.ValidateRequest\x1a\x18.training.StatusResponse\"\x00\x12\x43\n\x11train_model_price\x12\x11.training.ModelID\x1a\x19.training.PriceInBaseUnit\"\x00\x12<\n\x0btrain_model\x12\x11.training.ModelID\x1a\x18.training.StatusResponse\"\x00\x12=\n\x0c\x64\x65lete_model\x12\x11.training.ModelID\x1a\x18.training.StatusResponse\"\x00\x12\x41\n\x10get_model_status\x12\x11.training.ModelID\x1a\x18.training.StatusResponse\"\x00::\n\x10\x64\x65\x66\x61ult_model_id\x12\x1e.google.protobuf.MethodOptions\x18\xd1\x86\x03 \x01(\t:=\n\x13max_models_per_user\x12\x1e.google.protobuf.MethodOptions\x18\xd2\x86\x03 \x01(\x04:=\n\x13\x64\x61taset_max_size_mb\x12\x1e.google.protobuf.MethodOptions\x18\xd3\x86\x03 \x01(\x04:A\n\x17\x64\x61taset_max_count_files\x12\x1e.google.protobuf.MethodOptions\x18\xd4\x86\x03 \x01(\x04:I\n\x1f\x64\x61taset_max_size_single_file_mb\x12\x1e.google.protobuf.MethodOptions\x18\xd5\x86\x03 \x01(\x04:<\n\x12\x64\x61taset_files_type\x12\x1e.google.protobuf.MethodOptions\x18\xd6\x86\x03 \x01(\t:6\n\x0c\x64\x61taset_type\x12\x1e.google.protobuf.MethodOptions\x18\xd7\x86\x03 \x01(\t:=\n\x13\x64\x61taset_description\x12\x1e.google.protobuf.MethodOptions\x18\xd8\x86\x03 \x01(\tB,Z*github.com/singnet/snet-daemon/v5/trainingb\x06proto3') - -_globals = globals() -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'training_pb2', _globals) -if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'Z*github.com/singnet/snet-daemon/v5/training' - _globals['_STATUS']._serialized_start=923 - _globals['_STATUS']._serialized_end=1033 - _globals['_MODELRESPONSE']._serialized_start=63 - _globals['_MODELRESPONSE']._serialized_end=387 - _globals['_NEWMODEL']._serialized_start=390 - _globals['_NEWMODEL']._serialized_end=592 - _globals['_MODELID']._serialized_start=594 - _globals['_MODELID']._serialized_end=621 - _globals['_PRICEINBASEUNIT']._serialized_start=623 - _globals['_PRICEINBASEUNIT']._serialized_end=655 - _globals['_STATUSRESPONSE']._serialized_start=657 - _globals['_STATUSRESPONSE']._serialized_end=707 - _globals['_UPLOADINPUT']._serialized_start=710 - _globals['_UPLOADINPUT']._serialized_end=856 - _globals['_VALIDATEREQUEST']._serialized_start=858 - _globals['_VALIDATEREQUEST']._serialized_end=921 - _globals['_MODEL']._serialized_start=1036 - _globals['_MODEL']._serialized_end=1590 -# @@protoc_insertion_point(module_scope) diff --git a/snet/sdk/resources/proto/training_pb2_grpc.py b/snet/sdk/resources/proto/training_pb2_grpc.py deleted file mode 100644 index 480dfcf..0000000 --- a/snet/sdk/resources/proto/training_pb2_grpc.py +++ /dev/null @@ -1,310 +0,0 @@ -# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! -"""Client and server classes corresponding to protobuf-defined services.""" -import grpc - -import training_pb2 as training__pb2 - - -class ModelStub(object): - """Methods that the service provider must implement - """ - - def __init__(self, channel): - """Constructor. - - Args: - channel: A grpc.Channel. - """ - self.create_model = channel.unary_unary( - '/training.Model/create_model', - request_serializer=training__pb2.NewModel.SerializeToString, - response_deserializer=training__pb2.ModelID.FromString, - ) - self.validate_model_price = channel.unary_unary( - '/training.Model/validate_model_price', - request_serializer=training__pb2.ValidateRequest.SerializeToString, - response_deserializer=training__pb2.PriceInBaseUnit.FromString, - ) - self.upload_and_validate = channel.stream_unary( - '/training.Model/upload_and_validate', - request_serializer=training__pb2.UploadInput.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.validate_model = channel.unary_unary( - '/training.Model/validate_model', - request_serializer=training__pb2.ValidateRequest.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.train_model_price = channel.unary_unary( - '/training.Model/train_model_price', - request_serializer=training__pb2.ModelID.SerializeToString, - response_deserializer=training__pb2.PriceInBaseUnit.FromString, - ) - self.train_model = channel.unary_unary( - '/training.Model/train_model', - request_serializer=training__pb2.ModelID.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.delete_model = channel.unary_unary( - '/training.Model/delete_model', - request_serializer=training__pb2.ModelID.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - self.get_model_status = channel.unary_unary( - '/training.Model/get_model_status', - request_serializer=training__pb2.ModelID.SerializeToString, - response_deserializer=training__pb2.StatusResponse.FromString, - ) - - -class ModelServicer(object): - """Methods that the service provider must implement - """ - - def create_model(self, request, context): - """Free - Can pass the address of the model creator - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def validate_model_price(self, request, context): - """Free - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def upload_and_validate(self, request_iterator, context): - """Paid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def validate_model(self, request, context): - """Paid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def train_model_price(self, request, context): - """Free, one signature for both train_model_price & train_model methods - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def train_model(self, request, context): - """Paid - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def delete_model(self, request, context): - """Free - After model deletion, the status becomes DELETED in etcd - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - def get_model_status(self, request, context): - """Free - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - - -def add_ModelServicer_to_server(servicer, server): - rpc_method_handlers = { - 'create_model': grpc.unary_unary_rpc_method_handler( - servicer.create_model, - request_deserializer=training__pb2.NewModel.FromString, - response_serializer=training__pb2.ModelID.SerializeToString, - ), - 'validate_model_price': grpc.unary_unary_rpc_method_handler( - servicer.validate_model_price, - request_deserializer=training__pb2.ValidateRequest.FromString, - response_serializer=training__pb2.PriceInBaseUnit.SerializeToString, - ), - 'upload_and_validate': grpc.stream_unary_rpc_method_handler( - servicer.upload_and_validate, - request_deserializer=training__pb2.UploadInput.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'validate_model': grpc.unary_unary_rpc_method_handler( - servicer.validate_model, - request_deserializer=training__pb2.ValidateRequest.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'train_model_price': grpc.unary_unary_rpc_method_handler( - servicer.train_model_price, - request_deserializer=training__pb2.ModelID.FromString, - response_serializer=training__pb2.PriceInBaseUnit.SerializeToString, - ), - 'train_model': grpc.unary_unary_rpc_method_handler( - servicer.train_model, - request_deserializer=training__pb2.ModelID.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'delete_model': grpc.unary_unary_rpc_method_handler( - servicer.delete_model, - request_deserializer=training__pb2.ModelID.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - 'get_model_status': grpc.unary_unary_rpc_method_handler( - servicer.get_model_status, - request_deserializer=training__pb2.ModelID.FromString, - response_serializer=training__pb2.StatusResponse.SerializeToString, - ), - } - generic_handler = grpc.method_handlers_generic_handler( - 'training.Model', rpc_method_handlers) - server.add_generic_rpc_handlers((generic_handler,)) - - - # This class is part of an EXPERIMENTAL API. -class Model(object): - """Methods that the service provider must implement - """ - - @staticmethod - def create_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/create_model', - training__pb2.NewModel.SerializeToString, - training__pb2.ModelID.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def validate_model_price(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/validate_model_price', - training__pb2.ValidateRequest.SerializeToString, - training__pb2.PriceInBaseUnit.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def upload_and_validate(request_iterator, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.stream_unary(request_iterator, target, '/training.Model/upload_and_validate', - training__pb2.UploadInput.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def validate_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/validate_model', - training__pb2.ValidateRequest.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def train_model_price(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/train_model_price', - training__pb2.ModelID.SerializeToString, - training__pb2.PriceInBaseUnit.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def train_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/train_model', - training__pb2.ModelID.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def delete_model(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/delete_model', - training__pb2.ModelID.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def get_model_status(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/training.Model/get_model_status', - training__pb2.ModelID.SerializeToString, - training__pb2.StatusResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/snet/sdk/service_client.py b/snet/sdk/service_client.py index 9e367b6..46796ab 100644 --- a/snet/sdk/service_client.py +++ b/snet/sdk/service_client.py @@ -10,7 +10,7 @@ from hexbytes import HexBytes import web3 from eth_account.messages import defunct_hash_message -from rfc3986 import urlparse +from urllib.parse import urlparse from snet.sdk import generic_client_interceptor, FreeCallPaymentStrategy from snet.sdk.account import Account diff --git a/snet/sdk/utils/ipfs_utils.py b/snet/sdk/utils/ipfs_utils.py index 64cdf9a..446d5a1 100644 --- a/snet/sdk/utils/ipfs_utils.py +++ b/snet/sdk/utils/ipfs_utils.py @@ -1,33 +1,41 @@ -""" Utilities related to ipfs """ -import base58 import ipfshttpclient import multihash +import hashlib def get_from_ipfs_and_checkhash(ipfs_client, ipfs_hash_base58, validate=True): """ - Get file from IPFS. If validate is True, verify the integrity of the file using its hash. + Get file from IPFS and validate hash """ - data = ipfs_client.cat(ipfs_hash_base58) if validate: block_data = ipfs_client.block.get(ipfs_hash_base58) - # print(f"IPFS hash (Base58): {ipfs_hash_base58}") - # print(f"Block data length: {len(block_data)}") - - # Decode Base58 bash to multihash try: - mh = multihash.decode(ipfs_hash_base58.encode('ascii'), "base58") - except Exception as e: - raise ValueError(f"Invalid multihash for IPFS hash: {ipfs_hash_base58}. Error: {str(e)}") from e + mh_bytes = multihash.from_b58_string(ipfs_hash_base58) + decoded = multihash.decode(mh_bytes) + + hash_func_name = decoded.name + expected_digest = decoded.digest - if not mh.verify(block_data): # Correctly using mh instance for verification - raise Exception("IPFS hash mismatch with data") + if hash_func_name == 'sha2-256': # Standard for IPFS (CIDv0) + actual_digest = hashlib.sha256(block_data).digest() + else: + # Handle other algorithms supported by hashlib if necessary + h = hashlib.new(hash_func_name.replace('-', '')) + h.update(block_data) + actual_digest = h.digest() + + if actual_digest != expected_digest: + raise Exception("IPFS hash mismatch with data") + + except Exception as e: + raise ValueError(f"Integrity check failed: {str(e)}") from e return data + def get_ipfs_client(config): ipfs_endpoint = config.get_ipfs_endpoint() return ipfshttpclient.connect(ipfs_endpoint) diff --git a/version.py b/version.py deleted file mode 100644 index ba7be38..0000000 --- a/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "5.0.0"