55Entities:
661 . [ 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.
2731with 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,
51101and 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