-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
70 lines (59 loc) · 1.68 KB
/
index.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
import {createClient, waitForMessageReceived} from '@layerzerolabs/scan-client';
enum Network {
Ethereum = 101,
Bnb = 102,
Avalanche = 106,
Aptos = 108,
Polygon = 109,
Arbitrum = 110,
Optimism = 111,
Fantom = 112,
CoreDAO = 153,
}
const rpcEndpoints = {
[Network.Optimism]: 'https://optimism.llamarpc.com',
[Network.Avalanche]: 'https://avax.meowrpc.com'
}
type Message = {
srcUaAddress: string;
dstUaAddress: string;
srcChainId: number;
dstChainId: number;
dstTxHash?: string;
dstTxError?: string;
srcTxHash: string;
srcBlockHash: string;
srcBlockNumber: string;
srcUaNonce: number;
status: MessageStatus;
};
enum MessageStatus {
INFLIGHT = 'INFLIGHT',
DELIVERED = 'DELIVERED',
FAILED = 'FAILED',
}
const getEventLog = async (rpcEndpoint: string, txHash: string) => {
// TODO
}
const fetchEventLog = async (message: Message | any) => {
// Initialize a client with the desired environment
const {srcChainId, dstChainId, srcTxHash, dstTxHash} = message
const srcRPCEndpoint = rpcEndpoints[srcChainId]
const dstRPCEndpoint = rpcEndpoints[dstChainId]
const srcEventLog = getEventLog(srcRPCEndpoint, srcTxHash)
const dstEventLog = getEventLog(dstRPCEndpoint, dstTxHash)
}
const getMessage = (srcChainId, srcTxHash) => new Promise((resolve, reject) => {
waitForMessageReceived(srcChainId, srcTxHash)
.then((message) => {
resolve(message)
})
.catch((e) => {
reject(e)
})
})
const fetchBySourceTxHash = async (srcChainId, srcTxHash) => {
const message = await getMessage(srcChainId, srcTxHash);
fetchEventLog(message);
}
fetchBySourceTxHash(Network.Avalanche, '0xb0bdab4227305b951950f740858a10f870932787d1a8489f0784383d3a3757b8')