diff --git a/docs/main/service_client.md b/docs/main/service_client.md index 11df1b9..4b44fdb 100644 --- a/docs/main/service_client.md +++ b/docs/main/service_client.md @@ -57,6 +57,7 @@ the `PaymentStrategy` inheritor classes. - `grpc_channel` (grpc.Channel): The gRPC channel with interceptor. - `payment_channel_provider` (PaymentChannelProvider): An instance of the `PaymentChannelProvider` class for working with channels and interacting with MPE. +- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC. - `service` (Any): The gRPC service stub instance. - `pb2_module` (ModuleType): The imported protobuf module. - `payment_channels` (list[PaymentChannel]): The list of payment channels. @@ -85,6 +86,7 @@ Initializes a new instance of the class. - `account` (Account): An instance of the `Account` class. - `sdk_web3` (Web3): The `Web3` instance. - `pb2_module` (str | ModuleType): The module containing the gRPC message definitions. +- `payment_channel_provider` (PaymentChannelProvider): The payment channel provider instance. ###### returns: diff --git a/docs/mpe/mpe_contract.md b/docs/mpe/mpe_contract.md index 461b795..bffafb0 100644 --- a/docs/mpe/mpe_contract.md +++ b/docs/mpe/mpe_contract.md @@ -31,8 +31,6 @@ funds into the contract, opening a channel, adding funds to a channel, extending - `web3` (Web3): An instance of the Web3 class for interacting with the Ethereum blockchain. - `contract` (Contract): An instance of the `Contract` class from the `web3` library for interacting with the MultiPartyEscrow contract. -- `event_topics` (list): A list of event topics for the MultiPartyEscrow contract. -- `deployment_block` (int | BlockNumber): The block number at which the MultiPartyEscrow contract was deployed. #### methods @@ -44,7 +42,7 @@ If no contract address is provided, it uses the default MultiPartyEscrow contrac ###### args: - `w3` (Web3): An instance of the `Web3` class. -- `address` (str): The address of the MultiPartyEscrow contract. Defaults to None. +- `address` (str): The address of the MultiPartyEscrow contract. Defaults to _None_. ###### returns: diff --git a/docs/mpe/payment_channel_provider.md b/docs/mpe/payment_channel_provider.md index 803f3b6..b1bbb57 100644 --- a/docs/mpe/payment_channel_provider.md +++ b/docs/mpe/payment_channel_provider.md @@ -5,6 +5,10 @@ Entities: 1. [PaymentChannelProvider](#class-paymentchannelprovider) - [\_\_init\_\_](#__init__) + - [update_cache](#update_cache) + - [_event_data_args_to_dict](#_event_data_args_to_dict) + - [_get_all_channels_from_blockchain_logs_to_dicts](#_get_all_channels_from_blockchain_logs_to_dicts) + - [_get_channels_from_cache](#_get_channels_from_cache) - [get_past_open_channels](#get_past_open_channels) - [open_channel](#open_channel) - [deposit_and_open_channel](#deposit_and_open_channel) @@ -27,7 +31,9 @@ A class for managing payment channels. with the MultiPartyEscrow contract. - `event_topics` (list): A list of event topics for the MultiPartyEscrow contract. - `deployment_block` (int | BlockNumber): The block number at which the MultiPartyEscrow contract was deployed. -- `payment_channel_state_service_client` (ServiceStub): A stub for interacting with PaymentChannelStateService via gRPC. +- `mpe_address` (ChecksumAddress): The address of the MultiPartyEscrow contract. +- `channels_file` (Path): The path to the cache file for payment channels. +Equals to `~/.snet/cache/mpe/MPE_ADDRESS/channels.pickle`. #### methods @@ -45,9 +51,53 @@ Initializes a new instance of the class. - _None_ +#### `update_cache` + +Updates the cache with channels from blockchain logs for the MPE contract. Cache is stored as a pickle file. +It stores the list of payment channels and last read block number. If there is no cache, logs are retrieved starting +from the deployment block up to the current block, and the following times, starting from the last read block. + +###### returns: + +- _None_ + +#### `_event_data_args_to_dict` + +Converts event data into a dictionary, keeping only the required fields. + +###### args: + +- `event_data` (dict[str, Any]): The event to convert to a dictionary. + +###### returns: + +- A dictionary containing the event data. (dict[str, Any]) + +#### `_get_all_channels_from_blockchain_logs_to_dicts` + +Retrieves all payment channels from the blockchain logs with a given block range and returns them as a list +of dictionaries. + +###### args: + +- `starting_block_number` (int): The starting block number of the block range. +- `to_block_number` (int): The ending block number of the block range. + +###### returns: + +- A list of payment channel dictionaries. (list[dict[str, Any]]) + +#### `_get_channels_from_cache` + +Updates cache with using `update_cache` and retrieves all payment channels from the cache. + +###### returns: + +- A list of payment channel dictionaries. (list[dict[str, Any]]) + #### `get_past_open_channels` -Extracts a list of all past open payment channels from the blockchain, filters it by account and payment group, +Extracts a list of all past open payment channels from the cache, filters it by account and payment group, and returns it. ###### args: @@ -55,8 +105,8 @@ and returns it. - `account` (Account): The account object to filter the channels by its address and signer address. - `payment_address` (str): The payment address to filter the channels by. - `group_id` (str): The group ID to filter the channels by. -- `starting_block_number` (int): The starting block number of the block range. Defaults to 0. -- `to_block_number` (int): The ending block number of the block range. Defauls to _None_. +- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to +pass it to PaymentChannel instances. ###### returns: @@ -74,6 +124,8 @@ And then returns it. - `expiration` (int): The expiration time of the payment channel in blocks. - `payment_address` (str): The address of the payment recipient. - `group_id` (str): The ID of the payment group. +- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to +pass it to PaymentChannel instances. ###### returns: @@ -91,6 +143,8 @@ and expiration time. And then returns it. - `expiration` (int): The expiration time of the payment channel in blocks. - `payment_address` (str): The address of the payment recipient. - `group_id` (str): The ID of the payment group. +- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to +pass it to PaymentChannel instances. ###### returns: @@ -98,7 +152,7 @@ and expiration time. And then returns it. #### `_get_newly_opened_channel` -Retrieves the newly opened payment channel from blockchain based on the given data. +Retrieves the newly opened payment channel from cache (which is previously updated) based on the given data. ###### args: @@ -106,6 +160,8 @@ Retrieves the newly opened payment channel from blockchain based on the given da - `account` (Account): The account object associated with the payment channel. - `payment_address` (str): The payment address of the payment channel. - `group_id` (str): The ID of the payment group. +- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to +pass it to PaymentChannel instances. ###### returns: diff --git a/examples/examples_docs/calculator.md b/examples/examples_docs/calculator.md index 87fec3e..aa88dd6 100644 --- a/examples/examples_docs/calculator.md +++ b/examples/examples_docs/calculator.md @@ -10,7 +10,7 @@ transactions and service calls. So, the application must have the next console interface: -```commandline +``` Welcome to the calculator powered by SingularityNET platform! Please type the expression you want to calculate, e.g. 2 + 3. Type 'exit' to exit the program. @@ -29,7 +29,7 @@ Calculator> exit Before the beginning we need to install `snet.sdk` package: -```commandline +```sh pip install snet.sdk ``` @@ -130,5 +130,5 @@ created instance of the ServiceClient class - `calc_client`, using `call_rpc` me on the screen. The entire application code can be viewed at the -[link](https://github.com/Arondondon/snet-sdk-python/blob/depelopment-app-example/examples/calculator.py) to GitHub. +[link](https://github.com/singnet/snet-sdk-python/blob/master/examples/calculator.py) to GitHub. diff --git a/examples/examples_docs/console_app.md b/examples/examples_docs/console_app.md index 01970d5..7c2bb28 100644 --- a/examples/examples_docs/console_app.md +++ b/examples/examples_docs/console_app.md @@ -13,7 +13,7 @@ The application should request additional parameters for a specific command afte So, the application must have the next console interface: -```commandline +``` Hello, welcome to the Snet SDK console application! To use the application, type the name of the command you want to execute. Available commands: @@ -61,7 +61,7 @@ Services: Before the beginning we need to install `snet.sdk` package: -```commandline +```sh pip install snet.sdk ``` @@ -376,5 +376,5 @@ def open_channel(): ``` The entire application code can be viewed at the -[link](https://github.com/Arondondon/snet-sdk-python/blob/depelopment-app-example/examples/console_app.py) to GitHub. +[link](https://github.com/singnet/snet-sdk-python/blob/master/examples/console_app.py) to GitHub.