-
Notifications
You must be signed in to change notification settings - Fork 0
/
logFetcher.ts
86 lines (76 loc) · 2.57 KB
/
logFetcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
BaseIndexerEntityFetcher,
Blockchain,
FetcherMsClient,
NonceTimestamp,
EntityRequest,
EntityRequestIncomingEntityStorage,
EntityRequestPendingEntityStorage,
EntityRequestResponseStorage,
EntityRequestStorage,
EntityRequestType,
IndexableEntityType,
} from '@aleph-indexer/framework'
import { EthereumParsedLog } from '../../parser/src/types.js'
export class EthereumIndexerLogFetcher extends BaseIndexerEntityFetcher<EthereumParsedLog> {
constructor(
protected fetcherMsClient: FetcherMsClient,
protected logRequestDAL: EntityRequestStorage,
protected logRequestIncomingLogDAL: EntityRequestIncomingEntityStorage<EthereumParsedLog>,
protected logRequestPendingSignatureDAL: EntityRequestPendingEntityStorage,
protected logRequestResponseDAL: EntityRequestResponseStorage<EthereumParsedLog>,
protected blockchainId: Blockchain = Blockchain.Ethereum,
protected nonce: NonceTimestamp = new NonceTimestamp(),
) {
super(
IndexableEntityType.Log,
blockchainId,
fetcherMsClient,
logRequestDAL,
logRequestIncomingLogDAL,
logRequestPendingSignatureDAL,
logRequestResponseDAL,
nonce,
)
}
protected filterIncomingEntitiesByRequest(
entities: EthereumParsedLog[],
request: EntityRequest,
): {
filteredEntities: EthereumParsedLog[]
remainingEntities: EthereumParsedLog[]
} {
const filteredEntities: EthereumParsedLog[] = []
const remainingEntities: EthereumParsedLog[] = []
switch (request.type) {
case EntityRequestType.ByDateRange: {
const { account, startDate, endDate } = request.params
for (const entity of entities) {
if (typeof entity.parsed !== 'object') {
console.log(
'ethereum log | 👺 error incoming log without parsed field',
request.nonce,
entity,
)
continue
}
const timestamp = entity.timestamp
let valid = timestamp >= startDate && timestamp <= endDate
if (valid) {
valid = entity.address.toLowerCase() === account
if (!valid) {
const accountTopic = `0x${account.substring(2).padStart(64, '0')}`
valid = entity.topics.some((topic) => topic === accountTopic)
}
}
valid ? filteredEntities.push(entity) : remainingEntities.push(entity)
}
break
}
default: {
return super.filterIncomingEntitiesByRequest(entities, request)
}
}
return { filteredEntities, remainingEntities }
}
}