-
Notifications
You must be signed in to change notification settings - Fork 0
/
logHistoryFetcher.ts
90 lines (83 loc) · 2.65 KB
/
logHistoryFetcher.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
87
88
89
90
import {
Blockchain,
GetAccountEntityStateRequestArgs,
FetcherMsClient,
FetcherStateLevelStorage,
PendingAccountStorage,
BaseEntityHistoryFetcher,
IndexableEntityType,
} from '@aleph-indexer/framework'
import { EthereumAccountLogHistoryFetcher } from './accountLogHistoryFetcher.js'
import { EthereumBlockHistoryFetcher } from '../block/blockHistoryFetcher.js'
import { EthereumClient } from '../../../../sdk/client.js'
import {
EthereumAccountLogHistoryEntity,
EthereumAccountLogHistoryStorage,
} from './dal/accountLogHistory.js'
import {
EthereumAccountLogHistoryPaginationCursor,
EthereumAccountLogHistoryState,
} from '../types.js'
import { EthereumRawLogStorage } from './dal/rawLog.js'
export class EthereumLogHistoryFetcher extends BaseEntityHistoryFetcher<
EthereumAccountLogHistoryPaginationCursor,
EthereumAccountLogHistoryEntity
> {
/**
* Initialize the fetcher service.
* @param ethereumClient The ethereum mainnet public RPC client to use.
* @param fetcherStateDAL The fetcher state storage.
*/
constructor(
protected ethereumClient: EthereumClient,
protected fetcherStateDAL: FetcherStateLevelStorage,
protected blockHistoryFetcher: EthereumBlockHistoryFetcher,
protected rawLogDAL: EthereumRawLogStorage,
protected fetcherClient: FetcherMsClient,
protected accountDAL: PendingAccountStorage,
protected accountLogHistoryDAL: EthereumAccountLogHistoryStorage,
protected blockchainId: Blockchain = Blockchain.Ethereum,
) {
super(
IndexableEntityType.Log,
blockchainId,
fetcherClient,
accountDAL,
accountLogHistoryDAL,
)
}
/**
* Returns the state of the transaction fetch process of a given account.
* @param args The account address to get its fetch status.
*/
async getAccountState(
args: GetAccountEntityStateRequestArgs,
): Promise<EthereumAccountLogHistoryState | undefined> {
const state: EthereumAccountLogHistoryState | undefined =
await this.getPartialAccountState(args)
if (!state) return
const forward = state.cursors?.forward
if (forward) {
state.lastTimestamp = forward.timestamp
state.lastHeight = forward.height
}
const backward = state.cursors?.backward
if (backward) {
state.firstTimestamp = backward.timestamp
state.firstHeight = backward.height
}
return state
}
protected getAccountFetcher(
account: string,
): EthereumAccountLogHistoryFetcher {
return new EthereumAccountLogHistoryFetcher(
account,
this.accountLogHistoryDAL,
this.rawLogDAL,
this.fetcherStateDAL,
this.ethereumClient,
this.blockHistoryFetcher,
)
}
}