-
Notifications
You must be signed in to change notification settings - Fork 20
/
getTransactions.ts
66 lines (59 loc) · 1.43 KB
/
getTransactions.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
import {_log} from '../configs/utils';
const getPendingTxResponse = async (
hash: string,
providers: Array<any>,
escan: any
) => {
try {
const _txResponse = await getFromBackupProviders(hash, providers, escan);
return _txResponse;
} catch (e: any) {
_log.error('getPendingTxResponse catch ', hash);
}
return null;
};
const getFromBackupProviders = async (
hash: string,
providers: Array<any>,
escan: any
) => {
try {
const txResponse = await goGetIt(hash, providers, escan);
if (txResponse) {
const {to, from} = txResponse;
if (to && from) {
return txResponse;
}
}
} catch (e: any) {
if (e.message === 'noNetwork') {
const txResponse = await goGetIt(hash, providers, escan);
if (txResponse) {
const {to, from} = txResponse;
if (to && from) {
return txResponse;
}
}
}
}
return null;
};
const goGetIt = async (hash: string, providers: Array<any>, escan: any) => {
const l = providers.length - 1;
for (let i = l; i >= 0; i--) {
try {
const _txResponse = await providers[i].getTransaction(hash);
if (_txResponse) return _txResponse;
} catch (e: any) {
_log.info(e.message);
}
}
try {
const _txResponse = await escan.getTransaction(hash);
if (_txResponse) return _txResponse;
} catch (e: any) {
_log.info(e.message);
}
return null;
};
export {getPendingTxResponse};