-
Notifications
You must be signed in to change notification settings - Fork 0
/
transactionHistoryFetcher.ts
88 lines (81 loc) · 2.72 KB
/
transactionHistoryFetcher.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
import {
BaseEntityHistoryFetcher,
Blockchain,
GetAccountEntityStateRequestArgs,
FetcherMsClient,
FetcherStateLevelStorage,
PendingAccountStorage,
IndexableEntityType,
} from '@aleph-indexer/framework'
import {
EthereumAccountTransactionHistoryPaginationCursor,
EthereumAccountTransactionHistoryState,
} from '../types.js'
import { EthereumAccountTransactionHistoryFetcher } from './accountTransactionHistoryFetcher.js'
import { EthereumBlockHistoryFetcher } from '../block/blockHistoryFetcher.js'
import { EthereumClient } from '../../../../sdk/client.js'
import {
EthereumAccountTransactionHistoryEntity,
EthereumAccountTransactionHistoryStorage,
} from './dal/accountTransactionHistory.js'
export class EthereumTransactionHistoryFetcher extends BaseEntityHistoryFetcher<
EthereumAccountTransactionHistoryPaginationCursor,
EthereumAccountTransactionHistoryEntity
> {
/**
* 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 fetcherClient: FetcherMsClient,
protected accountDAL: PendingAccountStorage,
protected accountEntityHistoryDAL: EthereumAccountTransactionHistoryStorage,
protected blockchainId: Blockchain = Blockchain.Ethereum,
) {
super(
IndexableEntityType.Transaction,
blockchainId,
fetcherClient,
accountDAL,
accountEntityHistoryDAL,
)
}
/**
* 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<EthereumAccountTransactionHistoryState | undefined> {
const state: EthereumAccountTransactionHistoryState | undefined =
await this.getPartialAccountState(args)
if (!state) return
const forward = state.cursors?.forward
if (forward) {
state.lastTimestamp = forward.timestamp
state.lastHeight = forward.height
state.lastSignature = forward.signature
}
const backward = state.cursors?.backward
if (backward) {
state.firstTimestamp = backward.timestamp
state.firstHeight = backward.height
state.firstSignature = backward.signature
}
return state
}
protected getAccountFetcher(
account: string,
): EthereumAccountTransactionHistoryFetcher {
return new EthereumAccountTransactionHistoryFetcher(
account,
this.fetcherStateDAL,
this.ethereumClient,
this.blockHistoryFetcher,
)
}
}