-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathcommonWorker.ts
More file actions
62 lines (55 loc) · 1.94 KB
/
commonWorker.ts
File metadata and controls
62 lines (55 loc) · 1.94 KB
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
// SPDX-License-Identifier: Apache-2.0
import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import pino from 'pino';
import { MirrorNodeClient } from '../../../clients/mirrorNodeClient';
import { CacheClientFactory } from '../../../factories/cacheClientFactory';
import { RegistryFactory } from '../../../factories/registryFactory';
import { RequestDetails } from '../../../types';
import { wrapError } from '../../workersService/WorkersErrorUtils';
import { CommonService } from './CommonService';
const logger = pino({ level: ConfigService.get('LOG_LEVEL') || 'trace' });
const register = RegistryFactory.getInstance();
const cacheService = CacheClientFactory.create(logger, register);
const mirrorNodeClient = new MirrorNodeClient(ConfigService.get('MIRROR_NODE_URL'), logger, register, cacheService);
const commonService = new CommonService(mirrorNodeClient, logger, cacheService);
export async function getLogs(
blockHash: string | null,
fromBlock: string | 'latest',
toBlock: string | 'latest',
address: string | string[] | null,
topics: any[] | null,
requestDetails: RequestDetails,
) {
try {
const EMPTY_RESPONSE = [];
const params: any = {};
const sliceCountWrapper = { value: 1 };
if (blockHash) {
if (
!(await commonService.validateBlockHashAndAddTimestampToParams(
params,
blockHash,
requestDetails,
sliceCountWrapper,
))
) {
return EMPTY_RESPONSE;
}
} else if (
!(await commonService.validateBlockRangeAndAddTimestampToParams(
params,
fromBlock,
toBlock,
requestDetails,
address,
sliceCountWrapper,
))
) {
return EMPTY_RESPONSE;
}
commonService.addTopicsToParams(params, topics);
return await commonService.getLogsWithParams(address, params, requestDetails, sliceCountWrapper.value);
} catch (e: unknown) {
throw wrapError(e);
}
}