Skip to content

Commit

Permalink
Merge pull request #73 from singnet/docs-update
Browse files Browse the repository at this point in the history
Updated docs for version 3.5.1.
  • Loading branch information
Arondondon authored Oct 14, 2024
2 parents 7d1e1f5 + a36afc0 commit bee87ce
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 14 deletions.
2 changes: 2 additions & 0 deletions docs/main/service_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:

Expand Down
4 changes: 1 addition & 3 deletions docs/mpe/mpe_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:

Expand Down
66 changes: 61 additions & 5 deletions docs/mpe/payment_channel_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -45,18 +51,62 @@ 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:

- `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:

Expand All @@ -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:

Expand All @@ -91,21 +143,25 @@ 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:

- The newly opened payment channel. (PaymentChannel)

#### `_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:

- `receipt` (dict): The receipt of the transaction that opened the payment channel.
- `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:

Expand Down
6 changes: 3 additions & 3 deletions examples/examples_docs/calculator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,7 +29,7 @@ Calculator> exit

Before the beginning we need to install `snet.sdk` package:

```commandline
```sh
pip install snet.sdk
```

Expand Down Expand Up @@ -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.

6 changes: 3 additions & 3 deletions examples/examples_docs/console_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -61,7 +61,7 @@ Services:

Before the beginning we need to install `snet.sdk` package:

```commandline
```sh
pip install snet.sdk
```

Expand Down Expand Up @@ -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.

0 comments on commit bee87ce

Please sign in to comment.