diff --git a/README.md b/README.md index 80eb3de..a3dd405 100644 --- a/README.md +++ b/README.md @@ -149,23 +149,17 @@ visit the [Payment](#payment) section. ### Free call -If you want to use the free calls you will need to pass these arguments to the `create_service_client()` method: +If you want to use the free calls you will need to pass this argument to the `create_service_client()` method: ```python -free_call_auth_token_bin = "f2548d27ffd319b9c05918eeac15ebab934e5cfcd68e1ec3db2b92765", -free_call_token_expiry_block = 172800, -email = "test@test.com" # which using in AI marketplace account +address = "YOUR_ETHEREUM_ADDRESS" ``` -You can receive these for a given service from the [Dapp](https://beta.singularitynet.io/) - Creating a service client with free calls included would look like this: ```python service_client = snet_sdk.create_service_client(org_id="26072b8b6a0e448180f8c0e702ab6d2f", - service_id="Exampleservice" - free_call_auth_token_bin="f2548d27ffd319b9c05918eeac15ebab934e5cfcd68e1ec3db2b92765", - free_call_token_expiry_block=172800, - email="test@mail.com") + service_id="Exampleservice", + address="0xtest") ``` ### Paid call diff --git a/docs/main/init.md b/docs/main/init.md index 7a82f64..1436cc5 100644 --- a/docs/main/init.md +++ b/docs/main/init.md @@ -73,8 +73,7 @@ of the `ServiceClient` class with all the required parameters, which is then ret - `service_id` (str): The ID of the service. - `group_name` (str): The name of the payment group. Defaults to _None_. - `payment_strategy` (PaymentStrategy): The payment channel management strategy. Defaults to _None_. -- `free_call_auth_token_bin` (str): The free call authentication token in binary format. Defaults to _None_. -- `free_call_token_expiry_block` (int): The block number when the free call token expires. Defaults to _None_. +- `address` (str): Wallet address to use free calls. Defaults to _None_. - `options` (dict): Additional options for the service client. Defaults to _None_. - `concurrent_calls` (int): The number of concurrent calls allowed. Defaults to 1. diff --git a/docs/payment_strategies/freecall_payment_strategy.md b/docs/payment_strategies/freecall_payment_strategy.md index 67424ac..e6f5934 100644 --- a/docs/payment_strategies/freecall_payment_strategy.md +++ b/docs/payment_strategies/freecall_payment_strategy.md @@ -7,6 +7,8 @@ Entities: - [is_free_call_available](#is_free_call_available) - [get_payment_metadata](#get_payment_metadata) - [generate_signature](#generate_signature) + - [get_free_call_token_details](#get_free_call_token_details) + - [select_channel](#select_channel) ### Class `FreeCallPaymentStrategy` @@ -17,7 +19,7 @@ is extended by: - #### description The `FreeCallPaymentStrategy` class is a concrete implementation of the `PaymentStrategy` interface. -It allows you to use free calls (which can be received from the [Dapp](https://beta.singularitynet.io/)) to +It allows you to use free calls (which can be received from the daemon) to call services. #### methods @@ -68,3 +70,31 @@ Generates a signature for the given service client using the provided free call ###### raises: - Exception: If any of the required parameters for the free call strategy are missing. + +#### `get_free_call_token_details` + +Sends a request to the daemon and receives a free call token. + +###### args: + +- `service_client` (ServiceClient): The service client instance. + +###### returns: + +- A tuple containing the free call token and the token expiration block number. (tuple[str, int]) + +###### raises: + +- Exception: If an error occurred while receiving the token. + +#### `select_channel` + +Creates a channel to the daemon. + +###### args: + +- `service_client` (ServiceClient): The service client object. + +###### returns: + +- The channel for the service calling. \ No newline at end of file diff --git a/snet/sdk/__init__.py b/snet/sdk/__init__.py index ee8b4e7..3bdf743 100644 --- a/snet/sdk/__init__.py +++ b/snet/sdk/__init__.py @@ -26,7 +26,7 @@ from snet.sdk.client_lib_generator import ClientLibGenerator from snet.sdk.mpe.mpe_contract import MPEContract from snet.sdk.mpe.payment_channel_provider import PaymentChannelProvider -from snet.sdk.payment_strategies.default_payment_strategy import DefaultPaymentStrategy as PaymentStrategy +from snet.sdk.payment_strategies.default_payment_strategy import DefaultPaymentStrategy from snet.sdk.service_client import ServiceClient from snet.sdk.storage_provider.storage_provider import StorageProvider from snet.sdk.custom_typing import ModuleName, ServiceStub @@ -93,9 +93,7 @@ def create_service_client(self, service_id: str, group_name=None, payment_strategy=None, - free_call_auth_token_bin=None, - free_call_token_expiry_block=None, - email=None, + address=None, options=None, concurrent_calls: int = 1): @@ -121,20 +119,13 @@ def create_service_client(self, self.lib_generator.generate_client_library() if payment_strategy is None: - payment_strategy = PaymentStrategy( + payment_strategy = DefaultPaymentStrategy( concurrent_calls=concurrent_calls ) if options is None: options = dict() - options['free_call_auth_token-bin'] = ( - bytes.fromhex(free_call_auth_token_bin) if - free_call_token_expiry_block else "" - ) - options['free-call-token-expiry-block'] = ( - free_call_token_expiry_block if free_call_token_expiry_block else 0 - ) - options['email'] = email if email else "" + options['user_address'] = address if address else "" options['concurrency'] = self._sdk_config.get("concurrency", True) service_metadata = self._metadata_provider.enhance_service_metadata( diff --git a/snet/sdk/payment_strategies/freecall_payment_strategy.py b/snet/sdk/payment_strategies/freecall_payment_strategy.py index aae70b6..5134b50 100644 --- a/snet/sdk/payment_strategies/freecall_payment_strategy.py +++ b/snet/sdk/payment_strategies/freecall_payment_strategy.py @@ -2,87 +2,109 @@ from urllib.parse import urlparse import grpc +from grpc import _channel import web3 -from snet.sdk.resources.root_certificate import certificate -from snet.sdk.utils.utils import RESOURCES_PATH, add_to_path from snet.sdk.payment_strategies.payment_strategy import PaymentStrategy - +from snet.sdk.resources.root_certificate import certificate +from snet.sdk.utils.utils import RESOURCES_PATH, add_to_path class FreeCallPaymentStrategy(PaymentStrategy): - def is_free_call_available(self, service_client): + def is_free_call_available(self, service_client) -> bool: try: - org_id, service_id, group_id, daemon_endpoint = service_client.get_service_details() - email, token_for_free_call, token_expiry_date_block = service_client.get_free_call_config() + self._user_address = service_client.options["user_address"] + self._free_call_token, self._token_expiry_date_block = self.get_free_call_token_details(service_client) - if not token_for_free_call: + if not self._free_call_token: return False - signature, current_block_number = self.generate_signature(service_client) with add_to_path(str(RESOURCES_PATH.joinpath("proto"))): state_service_pb2 = importlib.import_module("state_service_pb2") with add_to_path(str(RESOURCES_PATH.joinpath("proto"))): state_service_pb2_grpc = importlib.import_module("state_service_pb2_grpc") + signature, current_block_number = self.generate_signature(service_client) + request = state_service_pb2.FreeCallStateRequest() - request.user_id = email - request.token_for_free_call = token_for_free_call - request.token_expiry_date_block = token_expiry_date_block + request.user_address = self._user_address + request.token_for_free_call = self._free_call_token + request.token_expiry_date_block = self._token_expiry_date_block request.signature = signature request.current_block = current_block_number - endpoint_object = urlparse(daemon_endpoint) - if endpoint_object.port is not None: - channel_endpoint = endpoint_object.hostname + ":" + str(endpoint_object.port) - else: - channel_endpoint = endpoint_object.hostname - - if endpoint_object.scheme == "http": - channel = grpc.insecure_channel(channel_endpoint) - elif endpoint_object.scheme == "https": - channel = grpc.secure_channel(channel_endpoint, grpc.ssl_channel_credentials(root_certificates=certificate)) - else: - raise ValueError('Unsupported scheme in service metadata ("{}")'.format(endpoint_object.scheme)) + channel = self.select_channel(service_client) stub = state_service_pb2_grpc.FreeCallStateServiceStub(channel) response = stub.GetFreeCallsAvailable(request) if response.free_calls_available > 0: return True return False + except grpc.RpcError as e: + if self._user_address: + print(f"Warning: {e.details()}") + return False except Exception as e: return False - def get_payment_metadata(self, service_client): - email, token_for_free_call, token_expiry_date_block = service_client.get_free_call_config() + def get_payment_metadata(self, service_client) -> list: signature, current_block_number = self.generate_signature(service_client) - metadata = [("snet-free-call-auth-token-bin", token_for_free_call), - ("snet-free-call-token-expiry-block", str(token_expiry_date_block)), + metadata = [("snet-free-call-auth-token-bin", self._free_call_token), + ("snet-free-call-token-expiry-block", str(self._token_expiry_date_block)), ("snet-payment-type", "free-call"), - ("snet-free-call-user-id", email), + ("snet-free-call-user-id", self._user_address), ("snet-current-block-number", str(current_block_number)), ("snet-payment-channel-signature-bin", signature)] return metadata - def select_channel(self, service_client): - pass - - def generate_signature(self, service_client): - org_id, service_id, group_id, daemon_endpoint = service_client.get_service_details() - email, token_for_free_call, token_expiry_date_block = service_client.get_free_call_config() - - if token_expiry_date_block == 0 or len(email) == 0 or len(token_for_free_call) == 0: + def select_channel(self, service_client) -> _channel.Channel: + _, _, _, daemon_endpoint = service_client.get_service_details() + endpoint_object = urlparse(daemon_endpoint) + if endpoint_object.port is not None: + channel_endpoint = endpoint_object.hostname + ":" + str(endpoint_object.port) + else: + channel_endpoint = endpoint_object.hostname + + if endpoint_object.scheme == "http": + channel = grpc.insecure_channel(channel_endpoint) + elif endpoint_object.scheme == "https": + channel = grpc.secure_channel(channel_endpoint, grpc.ssl_channel_credentials(root_certificates=certificate)) + else: + raise ValueError('Unsupported scheme in service metadata ("{}")'.format(endpoint_object.scheme)) + return channel + + def generate_signature(self, service_client) -> tuple[bytes, int]: + org_id, service_id, group_id, _ = service_client.get_service_details() + + if self._token_expiry_date_block == 0 or len(self._user_address) == 0 or len(self._free_call_token) == 0: raise Exception( "You are using default 'FreeCallPaymentStrategy' to use this strategy you need to pass " - "'free_call_auth_token-bin','email','free-call-token-expiry-block' in config") + "'free_call_auth_token-bin','user_address','free-call-token-expiry-block' in config") current_block_number = service_client.get_current_block_number() message = web3.Web3.solidity_keccak( ["string", "string", "string", "string", "string", "uint256", "bytes32"], - ["__prefix_free_trial", email, org_id, service_id, group_id, current_block_number, - token_for_free_call] + ["__prefix_free_trial", self._user_address, org_id, service_id, group_id, current_block_number, + self._free_call_token] ) return service_client.generate_signature(message), current_block_number + + def get_free_call_token_details(self, service_client) -> tuple[bytes, int]: + with add_to_path(str(RESOURCES_PATH.joinpath("proto"))): + state_service_pb2 = importlib.import_module("state_service_pb2") + + request = state_service_pb2.GetFreeCallTokenRequest() + request.address = self._user_address + + with add_to_path(str(RESOURCES_PATH.joinpath("proto"))): + state_service_pb2_grpc = importlib.import_module("state_service_pb2_grpc") + + channel = self.select_channel(service_client) + stub = state_service_pb2_grpc.FreeCallStateServiceStub(channel) + response = stub.GetFreeCallToken(request) + + return response.token, response.token_expiration_block + \ No newline at end of file diff --git a/snet/sdk/resources/proto/state_service.proto b/snet/sdk/resources/proto/state_service.proto index a2ce9aa..e6d505a 100644 --- a/snet/sdk/resources/proto/state_service.proto +++ b/snet/sdk/resources/proto/state_service.proto @@ -1,81 +1,97 @@ -syntax = "proto3"; - -package escrow; - -option java_package = "io.singularitynet.daemon.escrow"; - -// 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. -service PaymentChannelStateService { - // GetChannelState method returns a channel state by channel id. - rpc GetChannelState(ChannelStateRequest) returns (ChannelStateReply) {} -} - -// ChanelStateRequest is a request for channel state. -message ChannelStateRequest { - // channel_id contains id of the channel which state is requested. - bytes channel_id = 1; - - // signature is a client signature of the message which contains - // channel_id. It is used for client authorization. - bytes signature = 2; - - //current block number (signature will be valid only for short time around this block number) - uint64 current_block = 3; -} - -// ChannelStateReply message contains a latest channel state. current_nonce and -// current_value fields can be different from ones stored in the blockchain if -// server started withdrawing funds froms channel but transaction is still not -// finished. -message ChannelStateReply { - // current_nonce is a latest nonce of the payment channel. - bytes current_nonce = 1; - - // current_signed_amount is a last amount which were signed by client with current_nonce - //it could be absent if none message was signed with current_nonce - bytes current_signed_amount = 2; - - // current_signature is a last signature sent by client with current_nonce - // it could be absent if none message was signed with current nonce - bytes current_signature = 3; - - // last amount which was signed by client with nonce=current_nonce - 1 - bytes old_nonce_signed_amount = 4; - - // last signature sent by client with nonce = current_nonce - 1 - bytes old_nonce_signature = 5; - } - -//Used to determine free calls available for a given user. -service FreeCallStateService { - rpc GetFreeCallsAvailable(FreeCallStateRequest) returns (FreeCallStateReply) {} -} - -message FreeCallStateRequest { - //Has the user email id - string user_id = 1; - //signer-token = (user@mail, user-public-key, token_issue_date), this is generated my Market place Dapp - //to leverage free calls from SDK/ snet-cli, you will need this signer-token to be downloaded from Dapp - bytes token_for_free_call = 2; - //Token expiration date in Block number - uint64 token_expiry_date_block = 3 ; - //Signature is made up of the below, user signs with the private key corresponding with the public key used to generate the authorized token - //free-call-metadata = ("__prefix_free_trial",user_id,organization_id,service_id,group_id,current_block,authorized_token) - bytes signature = 4; - //current block number (signature will be valid only for short time around this block number) - uint64 current_block = 5; - -} - -message FreeCallStateReply { - //Has the user email id - string user_id = 1; - //Balance number of free calls available - uint64 free_calls_available = 2; -} +syntax = "proto3"; + +package escrow; + +option java_package = "io.singularitynet.daemon.escrow"; +option go_package = "../escrow"; + +// 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. +service PaymentChannelStateService { + // GetChannelState method returns a channel state by channel id. + rpc GetChannelState(ChannelStateRequest) returns (ChannelStateReply) {} +} + +// ChanelStateRequest is a request for channel state. +message ChannelStateRequest { + // channel_id contains id of the channel which state is requested. + bytes channel_id = 1; + + // signature is a client signature of the message which contains + // channel_id. It is used for client authorization. + bytes signature = 2; + + //current block number (signature will be valid only for short time around this block number) + uint64 current_block = 3; +} + +// ChannelStateReply message contains a latest channel state. current_nonce and +// current_value fields can be different from ones stored in the blockchain if +// server started withdrawing funds froms channel but transaction is still not +// finished. +message ChannelStateReply { + // current_nonce is a latest nonce of the payment channel. + bytes current_nonce = 1; + + // current_signed_amount is a last amount which were signed by client with current_nonce + //it could be absent if none message was signed with current_nonce + bytes current_signed_amount = 2; + + // current_signature is a last signature sent by client with current_nonce + // it could be absent if none message was signed with current nonce + bytes current_signature = 3; + + // last amount which was signed by client with nonce=current_nonce - 1 + bytes old_nonce_signed_amount = 4; + + // last signature sent by client with nonce = current_nonce - 1 + bytes old_nonce_signature = 5; + + //If the client / user chooses to sign upfront , the planned amount in cogs will be indicative of this. + //For pay per use, this will be zero + uint64 planned_amount = 6; + + //If the client / user chooses to sign upfront , the usage amount in cogs will be indicative of how much of the + //planned amount has actually been used. + //For pay per use, this will be zero + uint64 used_amount = 7; +} + +//Used to determine free calls available for a given user. +service FreeCallStateService { + rpc GetFreeCallsAvailable(FreeCallStateRequest) returns (FreeCallStateReply) {} + rpc GetFreeCallToken(GetFreeCallTokenRequest) returns (FreeCallToken) {} +} + +message GetFreeCallTokenRequest{ + string address = 1; +} + +message FreeCallToken{ + // token_hex == token but just in another format + string token_hex = 1; + bytes token = 2; + uint64 token_expiration_block = 3; +} + +message FreeCallStateRequest { + string user_address = 1; + bytes token_for_free_call = 2; + //Token expiration date in Block number + uint64 token_expiry_date_block = 3; + //Signature is made up of the below, user signs with the private key corresponding with the public key used to generate the authorized token + //free-call-metadata = ("__prefix_free_trial",user_address ,organization_id,service_id,group_id,current_block,authorized_token) + bytes signature = 4; + //current block number (signature will be valid only for short time around this block number) + uint64 current_block = 5; +} + +message FreeCallStateReply { + // number of free calls available + uint64 free_calls_available = 1; +} diff --git a/snet/sdk/resources/proto/state_service_pb2.py b/snet/sdk/resources/proto/state_service_pb2.py index d298f8a..8d2530d 100644 --- a/snet/sdk/resources/proto/state_service_pb2.py +++ b/snet/sdk/resources/proto/state_service_pb2.py @@ -13,24 +13,28 @@ -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\"\xa2\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\"\x8f\x01\n\x14\x46reeCallStateRequest\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x1b\n\x13token_for_free_call\x18\x02 \x01(\x0c\x12\x1f\n\x17token_expiry_date_block\x18\x03 \x01(\x04\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x15\n\rcurrent_block\x18\x05 \x01(\x04\"C\n\x12\x46reeCallStateReply\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x1c\n\x14\x66ree_calls_available\x18\x02 \x01(\x04\x32i\n\x1aPaymentChannelStateService\x12K\n\x0fGetChannelState\x12\x1b.escrow.ChannelStateRequest\x1a\x19.escrow.ChannelStateReply\"\x00\x32k\n\x14\x46reeCallStateService\x12S\n\x15GetFreeCallsAvailable\x12\x1c.escrow.FreeCallStateRequest\x1a\x1a.escrow.FreeCallStateReply\"\x00\x42!\n\x1fio.singularitynet.daemon.escrowb\x06proto3') +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\"*\n\x17GetFreeCallTokenRequest\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\"Q\n\rFreeCallToken\x12\x11\n\ttoken_hex\x18\x01 \x01(\t\x12\r\n\x05token\x18\x02 \x01(\x0c\x12\x1e\n\x16token_expiration_block\x18\x03 \x01(\x04\"\x94\x01\n\x14\x46reeCallStateRequest\x12\x14\n\x0cuser_address\x18\x01 \x01(\t\x12\x1b\n\x13token_for_free_call\x18\x02 \x01(\x0c\x12\x1f\n\x17token_expiry_date_block\x18\x03 \x01(\x04\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x15\n\rcurrent_block\x18\x05 \x01(\x04\"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.escrow' + 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=279 - _globals['_FREECALLSTATEREQUEST']._serialized_start=282 - _globals['_FREECALLSTATEREQUEST']._serialized_end=425 - _globals['_FREECALLSTATEREPLY']._serialized_start=427 - _globals['_FREECALLSTATEREPLY']._serialized_end=494 - _globals['_PAYMENTCHANNELSTATESERVICE']._serialized_start=496 - _globals['_PAYMENTCHANNELSTATESERVICE']._serialized_end=601 - _globals['_FREECALLSTATESERVICE']._serialized_start=603 - _globals['_FREECALLSTATESERVICE']._serialized_end=710 + _globals['_CHANNELSTATEREPLY']._serialized_end=324 + _globals['_GETFREECALLTOKENREQUEST']._serialized_start=326 + _globals['_GETFREECALLTOKENREQUEST']._serialized_end=368 + _globals['_FREECALLTOKEN']._serialized_start=370 + _globals['_FREECALLTOKEN']._serialized_end=451 + _globals['_FREECALLSTATEREQUEST']._serialized_start=454 + _globals['_FREECALLSTATEREQUEST']._serialized_end=602 + _globals['_FREECALLSTATEREPLY']._serialized_start=604 + _globals['_FREECALLSTATEREPLY']._serialized_end=654 + _globals['_PAYMENTCHANNELSTATESERVICE']._serialized_start=656 + _globals['_PAYMENTCHANNELSTATESERVICE']._serialized_end=761 + _globals['_FREECALLSTATESERVICE']._serialized_start=764 + _globals['_FREECALLSTATESERVICE']._serialized_end=949 # @@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 index 977dbd7..e29ae1d 100644 --- a/snet/sdk/resources/proto/state_service_pb2_grpc.py +++ b/snet/sdk/resources/proto/state_service_pb2_grpc.py @@ -6,13 +6,13 @@ 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. + """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): @@ -29,17 +29,17 @@ def __init__(self, channel): 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. + """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. + """GetChannelState method returns a channel state by channel id. """ context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_details('Method not implemented!') @@ -61,13 +61,13 @@ def add_PaymentChannelStateServiceServicer_to_server(servicer, server): # 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. + """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 @@ -89,7 +89,7 @@ def GetChannelState(request, class FreeCallStateServiceStub(object): - """Used to determine free calls available for a given user. + """Used to determine free calls available for a given user. """ def __init__(self, channel): @@ -103,10 +103,15 @@ def __init__(self, channel): 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. + """Used to determine free calls available for a given user. """ def GetFreeCallsAvailable(self, request, context): @@ -115,6 +120,12 @@ def GetFreeCallsAvailable(self, request, context): 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 = { @@ -123,6 +134,11 @@ def add_FreeCallStateServiceServicer_to_server(servicer, server): 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) @@ -131,7 +147,7 @@ def add_FreeCallStateServiceServicer_to_server(servicer, server): # This class is part of an EXPERIMENTAL API. class FreeCallStateService(object): - """Used to determine free calls available for a given user. + """Used to determine free calls available for a given user. """ @staticmethod @@ -150,3 +166,20 @@ def GetFreeCallsAvailable(request, 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/service_client.py b/snet/sdk/service_client.py index 9294e59..ffc35b6 100644 --- a/snet/sdk/service_client.py +++ b/snet/sdk/service_client.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import Any -from eth_typing import BlockNumber, ChecksumAddress +from eth_typing import BlockNumber import grpc from hexbytes import HexBytes import web3