@@ -28,10 +28,10 @@ extension web3.web3contract {
2828 *Parses the block for events matching the EventParser settings.*
2929
3030 - parameters:
31- - blockNumber: Ethereum network block number
31+ - blockNumber: Ethereum network block number
3232
3333 - returns:
34- - Result object
34+ - Result object
3535
3636 - important: This call is synchronous
3737
@@ -45,10 +45,10 @@ extension web3.web3contract {
4545 *Parses the block for events matching the EventParser settings.*
4646
4747 - parameters:
48- - block: Native web3swift block object
48+ - block: Native web3swift block object
4949
5050 - returns:
51- - Result object
51+ - Result object
5252
5353 - important: This call is synchronous
5454
@@ -62,10 +62,10 @@ extension web3.web3contract {
6262 *Parses the transaction for events matching the EventParser settings.*
6363
6464 - parameters:
65- - hash: Transaction hash
65+ - hash: Transaction hash
6666
6767 - returns:
68- - Result object
68+ - Result object
6969
7070 - important: This call is synchronous
7171
@@ -79,10 +79,10 @@ extension web3.web3contract {
7979 *Parses the transaction for events matching the EventParser settings.*
8080
8181 - parameters:
82- - transaction: web3swift native EthereumTransaction object
82+ - transaction: web3swift native EthereumTransaction object
8383
8484 - returns:
85- - Result object
85+ - Result object
8686
8787 - important: This call is synchronous
8888
@@ -174,65 +174,49 @@ extension web3.web3contract.EventParser {
174174}
175175
176176extension web3 . web3contract {
177-
178177 /**
179178 *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.*
180179
181180 - 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
185184
186185 - returns:
187- - Result object
186+ - Result object
188187
189188 - important: This call is synchronous
190189
191190 */
192191 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+ }
213196
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 " )
219200 }
201+ }
220202
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)
221206
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+ }
229214 . filter { res in res. eventLog != nil || ( res. eventName == eventName && eventName != nil ) }
230215
231216
232- if ( !joinWithReceipts) {
233- return decodedLogs as [ EventParserResultProtocol ]
234- }
235-
217+ if ( !joinWithReceipts) {
218+ return decodedLogs as [ EventParserResultProtocol ]
219+ }
236220
237221 return await withTaskGroup ( of: EventParserResultProtocol . self, returning: [ EventParserResultProtocol ] . self) { group -> [ EventParserResultProtocol ] in
238222
@@ -252,7 +236,6 @@ extension web3.web3contract {
252236 }
253237
254238 return collected
255-
256239 }
257240 }
258241}
0 commit comments