@@ -28,10 +28,10 @@ extension web3.web3contract {
28
28
*Parses the block for events matching the EventParser settings.*
29
29
30
30
- parameters:
31
- - blockNumber: Ethereum network block number
31
+ - blockNumber: Ethereum network block number
32
32
33
33
- returns:
34
- - Result object
34
+ - Result object
35
35
36
36
- important: This call is synchronous
37
37
@@ -45,10 +45,10 @@ extension web3.web3contract {
45
45
*Parses the block for events matching the EventParser settings.*
46
46
47
47
- parameters:
48
- - block: Native web3swift block object
48
+ - block: Native web3swift block object
49
49
50
50
- returns:
51
- - Result object
51
+ - Result object
52
52
53
53
- important: This call is synchronous
54
54
@@ -62,10 +62,10 @@ extension web3.web3contract {
62
62
*Parses the transaction for events matching the EventParser settings.*
63
63
64
64
- parameters:
65
- - hash: Transaction hash
65
+ - hash: Transaction hash
66
66
67
67
- returns:
68
- - Result object
68
+ - Result object
69
69
70
70
- important: This call is synchronous
71
71
@@ -79,10 +79,10 @@ extension web3.web3contract {
79
79
*Parses the transaction for events matching the EventParser settings.*
80
80
81
81
- parameters:
82
- - transaction: web3swift native EthereumTransaction object
82
+ - transaction: web3swift native EthereumTransaction object
83
83
84
84
- returns:
85
- - Result object
85
+ - Result object
86
86
87
87
- important: This call is synchronous
88
88
@@ -174,65 +174,49 @@ extension web3.web3contract.EventParser {
174
174
}
175
175
176
176
extension web3 . web3contract {
177
-
178
177
/**
179
178
*Fetches events by doing a lookup on "indexed" parameters of the event. Smart-contract developer can make some of event values "indexed" for such fast queries.*
180
179
181
180
- parameters:
182
- - eventName: Event name, should be present in ABI interface of the contract
183
- - filter: EventFilter object setting the block limits for query
184
- - joinWithReceipts: Bool indicating whether TransactionReceipt should be fetched separately for every matched transaction
181
+ - eventName: Event name, should be present in ABI interface of the contract
182
+ - filter: EventFilter object setting the block limits for query
183
+ - joinWithReceipts: Bool indicating whether TransactionReceipt should be fetched separately for every matched transaction
185
184
186
185
- returns:
187
- - Result object
186
+ - Result object
188
187
189
188
- important: This call is synchronous
190
189
191
190
*/
192
191
public func getIndexedEvents( eventName: String ? , filter: EventFilter , joinWithReceipts: Bool = false ) async throws -> [ EventParserResultProtocol ] {
193
- let result = try await self . getIndexedEventsPromise ( eventName: eventName, filter: filter, joinWithReceipts: joinWithReceipts)
194
- return result
195
- }
196
- }
197
-
198
- extension web3 . web3contract {
199
- public func getIndexedEventsPromise( eventName: String ? , filter: EventFilter , joinWithReceipts: Bool = false ) async throws -> [ EventParserResultProtocol ] {
200
-
201
- let rawContract = self . contract
202
- guard let preEncoding = encodeTopicToGetLogs ( contract: rawContract, eventName: eventName, filter: filter) else {
203
- throw Web3Error . processingError ( desc: " Failed to encode topic for request " )
204
- }
205
-
206
- if eventName != nil {
207
- guard let _ = rawContract. events [ eventName!] else {
208
- throw Web3Error . processingError ( desc: " No such event in a contract " )
209
- }
210
- }
211
- let request = JSONRPCRequestFabric . prepareRequest ( . getLogs, parameters: [ preEncoding] )
212
- let response = try await self . web3. dispatch ( request)
192
+ let rawContract = self . contract
193
+ guard let preEncoding = encodeTopicToGetLogs ( contract: rawContract, eventName: eventName, filter: filter) else {
194
+ throw Web3Error . processingError ( desc: " Failed to encode topic for request " )
195
+ }
213
196
214
- guard let allLogs: [ EventLog ] = response. getValue ( ) else {
215
- if response. error != nil {
216
- throw Web3Error . nodeError ( desc: response. error!. message)
217
- }
218
- throw Web3Error . nodeError ( desc: " Empty or malformed response " )
197
+ if eventName != nil {
198
+ guard let _ = rawContract. events [ eventName!] else {
199
+ throw Web3Error . processingError ( desc: " No such event in a contract " )
219
200
}
201
+ }
220
202
203
+ // FIXME: This could not worked at all.
204
+ let request : APIRequest = . getLogs( preEncoding)
205
+ let response : APIResponse < [ EventLog ] > = try await APIRequest . sendRequest ( with: self . web3. provider, for: request)
221
206
222
- let decodedLogs = allLogs . compactMap { ( log) -> EventParserResult ? in
223
- let ( n, d) = self . contract. parseEvent ( log)
224
- guard let evName = n, let evData = d else { return nil }
225
- var res = EventParserResult ( eventName: evName, transactionReceipt: nil , contractAddress: log. address, decodedResult: evData)
226
- res. eventLog = log
227
- return res
228
- }
207
+ let decodedLogs = response . result . compactMap { ( log) -> EventParserResult ? in
208
+ let ( n, d) = self . contract. parseEvent ( log)
209
+ guard let evName = n, let evData = d else { return nil }
210
+ var res = EventParserResult ( eventName: evName, transactionReceipt: nil , contractAddress: log. address, decodedResult: evData)
211
+ res. eventLog = log
212
+ return res
213
+ }
229
214
. filter { res in res. eventLog != nil || ( res. eventName == eventName && eventName != nil ) }
230
215
231
216
232
- if ( !joinWithReceipts) {
233
- return decodedLogs as [ EventParserResultProtocol ]
234
- }
235
-
217
+ if ( !joinWithReceipts) {
218
+ return decodedLogs as [ EventParserResultProtocol ]
219
+ }
236
220
237
221
return await withTaskGroup ( of: EventParserResultProtocol . self, returning: [ EventParserResultProtocol ] . self) { group -> [ EventParserResultProtocol ] in
238
222
@@ -252,7 +236,6 @@ extension web3.web3contract {
252
236
}
253
237
254
238
return collected
255
-
256
239
}
257
240
}
258
241
}
0 commit comments