Skip to content

Commit 9507541

Browse files
authored
Merge pull request #74 from singnet/development
Added FileCoin storage provider for services metadata and files
2 parents 9e69738 + 2877c1e commit 9507541

27 files changed

Lines changed: 389 additions & 416 deletions

docs/main/client_lib_generator.md

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Entities:
66
1. [ClientLibGenerator](#class-clientlibgenerator)
77
- [\_\_init\_\_](#__init__)
88
- [generate_client_library](#generate_client_library)
9-
- [_get_service_metadata_from_registry](#_get_service_metadata_from_registry)
10-
- [_get_service_registration](#_get_service_registration)
119

1210
### Class `ClientLibGenerator`
1311

@@ -21,8 +19,7 @@ This class is used to generate client library files for a given service.
2119

2220
#### attributes
2321

24-
- `sdk_config` (Config): An instance of the `Config` class
25-
- `registry_contract` (web3.contract.Contract): An instance of the `Contract` class (from `snet.cli`) for interacting with the Registry contract.
22+
- `_metadata_provider` (StorageProvider): An instance of the `StorageProvider` class.
2623
- `org_id` (str): The organization ID of the service.
2724
- `service_id` (str): The service ID.
2825
- `language` (str): The language of the client library. Default is `python`.
@@ -36,8 +33,7 @@ Initializes a new instance of the class. Initializes the attributes by arguments
3633

3734
###### args:
3835

39-
- `sdk_config` (Config): An instance of the `Config` class
40-
- `registry_contract` (web3.contract.Contract): An instance of the `Contract` class (from `snet.cli`) for interacting with the Registry contract.
36+
- `metadata_provider` (StorageProvider): An instance of the `StorageProvider` class.
4137
- `org_id` (str): The organization ID of the service.
4238
- `service_id` (str): The service ID.
4339

@@ -49,27 +45,9 @@ Initializes a new instance of the class. Initializes the attributes by arguments
4945

5046
Generates client library stub files based on specified organization and service ids, including:
5147
- getting service metadata from Registry
52-
- getting .proto file from IPFS
48+
- getting archived proto files from IPFS or FileCoin and extracting them
5349
- compiling .proto file to stub file and saving it in a given directory
5450

55-
#### `_get_service_metadata_from_registry`
56-
57-
Retrieves service metadata. Fetches the service registration from the Registry contract, extracts the metadata URI,
58-
downloads the metadata from IPFS, and parses it into a `MPEServiceMetadata` object.
59-
6051
###### returns:
6152

62-
- The service metadata. (MPEServiceMetadata)
63-
64-
#### `_get_service_registration`
65-
66-
Retrieves the service registration from the Registry contract using the `getServiceRegistrationById` function of it.
67-
68-
###### returns:
69-
70-
- Dictionary containing the service registration. (dict[str, Any])
71-
72-
###### raises:
73-
74-
- `Exception`: If the service with the specified ID is not found in the organization.
75-
53+
- _None_

docs/main/config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ and regenerating them every time.
3535
- `registry_contract_address` (str): The address of the Registry smart contract.
3636
- `signer_private_key` (str): The private key of the signer. Used to sign the service call. Equals to `private_key`
3737
by default.
38+
- `lighthouse_token` (str): The Lighthouse token used to access the Lighthouse storage provider. Defaults to " ".
39+
Currently, it can't be changed.
3840

3941
#### methods
4042

docs/main/init.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ It provides methods for creating service clients, managing identities, and confi
3030
#### attributes
3131

3232
- `_sdk_config` (Config): An instance of the `Config` class.
33-
- `_metadata_provider` (MetadataProvider): An instance of the `MetadataProvider` class. _Note_: There is currently only
34-
one implementation of `MetadataProvider` which is `IPFSMetadataProvider`, so this attribute can only be initialized to
35-
`IPFSMetadataProvider` at this time.
33+
- `_metadata_provider` (StorageProvider): An instance of the `StorageProvider` class for fetching metadata and .proto files.
3634
- `web3` (Web3): An instance of the `Web3` class for interacting with the Ethereum blockchain.
3735
- `mpe_contract` (MPEContract): An instance of the `MPEContract` class for interacting with the MultiPartyEscrow contract.
38-
- `ipfs_client` (ipfshttpclient.Client): An instance of the `ipfshttpclient.Client` class for interacting with the
39-
InterPlanetary File System.
40-
- `registry_contract` (Contract): An instance of the `Contract` class (from `snet.cli`) for interacting with the Registry contract.
36+
- `registry_contract` (Contract): An instance of the `Contract` class for interacting with the Registry contract.
4137
- `account` (Account): An instance of the `Account` class for interacting with the MultiPartyEscrow and
4238
SingularityNetToken contracts.
39+
- `payment_channel_provider` (PaymentChannelProvider): An instance of the `PaymentChannelProvider` class for managing
40+
payment channels.
4341

4442
#### methods
4543

docs/main/service_client.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ the `PaymentStrategy` inheritor classes.
5757
- `grpc_channel` (grpc.Channel): The gRPC channel with interceptor.
5858
- `payment_channel_provider` (PaymentChannelProvider): An instance of the `PaymentChannelProvider` class for
5959
working with channels and interacting with MPE.
60+
- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC.
6061
- `service` (Any): The gRPC service stub instance.
6162
- `pb2_module` (ModuleType): The imported protobuf module.
6263
- `payment_channels` (list[PaymentChannel]): The list of payment channels.
@@ -85,6 +86,7 @@ Initializes a new instance of the class.
8586
- `account` (Account): An instance of the `Account` class.
8687
- `sdk_web3` (Web3): The `Web3` instance.
8788
- `pb2_module` (str | ModuleType): The module containing the gRPC message definitions.
89+
- `payment_channel_provider` (PaymentChannelProvider): The payment channel provider instance.
8890

8991
###### returns:
9092

docs/metadata_provider/ipfs_metadata_provider.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

docs/metadata_provider/metadata_provider.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

docs/mpe/mpe_contract.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ funds into the contract, opening a channel, adding funds to a channel, extending
3131
- `web3` (Web3): An instance of the Web3 class for interacting with the Ethereum blockchain.
3232
- `contract` (Contract): An instance of the `Contract` class from the `web3` library for interacting
3333
with the MultiPartyEscrow contract.
34-
- `event_topics` (list): A list of event topics for the MultiPartyEscrow contract.
35-
- `deployment_block` (int | BlockNumber): The block number at which the MultiPartyEscrow contract was deployed.
3634

3735
#### methods
3836

@@ -44,7 +42,7 @@ If no contract address is provided, it uses the default MultiPartyEscrow contrac
4442
###### args:
4543

4644
- `w3` (Web3): An instance of the `Web3` class.
47-
- `address` (str): The address of the MultiPartyEscrow contract. Defaults to None.
45+
- `address` (str): The address of the MultiPartyEscrow contract. Defaults to _None_.
4846

4947
###### returns:
5048

docs/mpe/payment_channel_provider.md

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
Entities:
66
1. [PaymentChannelProvider](#class-paymentchannelprovider)
77
- [\_\_init\_\_](#__init__)
8+
- [update_cache](#update_cache)
9+
- [_event_data_args_to_dict](#_event_data_args_to_dict)
10+
- [_get_all_channels_from_blockchain_logs_to_dicts](#_get_all_channels_from_blockchain_logs_to_dicts)
11+
- [_get_channels_from_cache](#_get_channels_from_cache)
812
- [get_past_open_channels](#get_past_open_channels)
913
- [open_channel](#open_channel)
1014
- [deposit_and_open_channel](#deposit_and_open_channel)
@@ -27,7 +31,9 @@ A class for managing payment channels.
2731
with the MultiPartyEscrow contract.
2832
- `event_topics` (list): A list of event topics for the MultiPartyEscrow contract.
2933
- `deployment_block` (int | BlockNumber): The block number at which the MultiPartyEscrow contract was deployed.
30-
- `payment_channel_state_service_client` (ServiceStub): A stub for interacting with PaymentChannelStateService via gRPC.
34+
- `mpe_address` (ChecksumAddress): The address of the MultiPartyEscrow contract.
35+
- `channels_file` (Path): The path to the cache file for payment channels.
36+
Equals to `~/.snet/cache/mpe/MPE_ADDRESS/channels.pickle`.
3137

3238
#### methods
3339

@@ -45,18 +51,62 @@ Initializes a new instance of the class.
4551

4652
- _None_
4753

54+
#### `update_cache`
55+
56+
Updates the cache with channels from blockchain logs for the MPE contract. Cache is stored as a pickle file.
57+
It stores the list of payment channels and last read block number. If there is no cache, logs are retrieved starting
58+
from the deployment block up to the current block, and the following times, starting from the last read block.
59+
60+
###### returns:
61+
62+
- _None_
63+
64+
#### `_event_data_args_to_dict`
65+
66+
Converts event data into a dictionary, keeping only the required fields.
67+
68+
###### args:
69+
70+
- `event_data` (dict[str, Any]): The event to convert to a dictionary.
71+
72+
###### returns:
73+
74+
- A dictionary containing the event data. (dict[str, Any])
75+
76+
#### `_get_all_channels_from_blockchain_logs_to_dicts`
77+
78+
Retrieves all payment channels from the blockchain logs with a given block range and returns them as a list
79+
of dictionaries.
80+
81+
###### args:
82+
83+
- `starting_block_number` (int): The starting block number of the block range.
84+
- `to_block_number` (int): The ending block number of the block range.
85+
86+
###### returns:
87+
88+
- A list of payment channel dictionaries. (list[dict[str, Any]])
89+
90+
#### `_get_channels_from_cache`
91+
92+
Updates cache with using `update_cache` and retrieves all payment channels from the cache.
93+
94+
###### returns:
95+
96+
- A list of payment channel dictionaries. (list[dict[str, Any]])
97+
4898
#### `get_past_open_channels`
4999

50-
Extracts a list of all past open payment channels from the blockchain, filters it by account and payment group,
100+
Extracts a list of all past open payment channels from the cache, filters it by account and payment group,
51101
and returns it.
52102

53103
###### args:
54104

55105
- `account` (Account): The account object to filter the channels by its address and signer address.
56106
- `payment_address` (str): The payment address to filter the channels by.
57107
- `group_id` (str): The group ID to filter the channels by.
58-
- `starting_block_number` (int): The starting block number of the block range. Defaults to 0.
59-
- `to_block_number` (int): The ending block number of the block range. Defauls to _None_.
108+
- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to
109+
pass it to PaymentChannel instances.
60110

61111
###### returns:
62112

@@ -74,6 +124,8 @@ And then returns it.
74124
- `expiration` (int): The expiration time of the payment channel in blocks.
75125
- `payment_address` (str): The address of the payment recipient.
76126
- `group_id` (str): The ID of the payment group.
127+
- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to
128+
pass it to PaymentChannel instances.
77129

78130
###### returns:
79131

@@ -91,21 +143,25 @@ and expiration time. And then returns it.
91143
- `expiration` (int): The expiration time of the payment channel in blocks.
92144
- `payment_address` (str): The address of the payment recipient.
93145
- `group_id` (str): The ID of the payment group.
146+
- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to
147+
pass it to PaymentChannel instances.
94148

95149
###### returns:
96150

97151
- The newly opened payment channel. (PaymentChannel)
98152

99153
#### `_get_newly_opened_channel`
100154

101-
Retrieves the newly opened payment channel from blockchain based on the given data.
155+
Retrieves the newly opened payment channel from cache (which is previously updated) based on the given data.
102156

103157
###### args:
104158

105159
- `receipt` (dict): The receipt of the transaction that opened the payment channel.
106160
- `account` (Account): The account object associated with the payment channel.
107161
- `payment_address` (str): The payment address of the payment channel.
108162
- `group_id` (str): The ID of the payment group.
163+
- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC to
164+
pass it to PaymentChannel instances.
109165

110166
###### returns:
111167

0 commit comments

Comments
 (0)