Refactor EventSourceCoordinatorForActivities #3962

pull/3965/head
Krypto Pank 3 years ago
parent 7208088521
commit 7a9dce11df
  1. 19
      AlphaWallet/TokenScriptClient/Coordinators/EventSourceCoordinatorForActivities.swift

@ -95,11 +95,10 @@ extension EventSourceCoordinatorForActivities.functional {
queue.async {
let eventOrigin = card.eventOrigin
let (filterName, filterValue) = eventOrigin.eventFilter
let filterParam = eventOrigin.parameters.filter {
$0.isIndexed
}.map {
EventSourceCoordinatorForActivities.functional.formFilterFrom(fromParameter: $0, filterName: filterName, filterValue: filterValue, wallet: wallet)
}
typealias functional = EventSourceCoordinatorForActivities.functional
let filterParam = eventOrigin.parameters
.filter { $0.isIndexed }
.map { functional.formFilterFrom(fromParameter: $0, filterName: filterName, filterValue: filterValue, wallet: wallet) }
if filterParam.allSatisfy({ $0 == nil }) {
//TODO log to console as diagnostic
@ -107,14 +106,16 @@ extension EventSourceCoordinatorForActivities.functional {
return
}
eventsDataStore.getMatchingEventsSortedByBlockNumber(forContract: eventOrigin.contract, tokenContract: tokenContract, server: server, eventName: eventOrigin.eventName).map(on: queue, { oldEvent -> (EventFilter.Block, UInt64) in
eventsDataStore
.getMatchingEventsSortedByBlockNumber(forContract: eventOrigin.contract, tokenContract: tokenContract, server: server, eventName: eventOrigin.eventName)
.map(on: queue, { oldEvent -> EventFilter in
let fromBlock: (EventFilter.Block, UInt64)
if let newestEvent = oldEvent {
let value = UInt64(newestEvent.blockNumber + 1)
return (.blockNumber(value), value)
fromBlock = (.blockNumber(value), value)
} else {
return (.blockNumber(0), 0)
fromBlock = (.blockNumber(0), 0)
}
}).map(on: queue, { fromBlock -> EventFilter in
let parameterFilters = filterParam.map { $0?.filter }
let addresses = [EthereumAddress(address: eventOrigin.contract)]
let toBlock = server.makeMaximumToBlockForEvents(fromBlockNumber: fromBlock.1)

Loading…
Cancel
Save