/
utils.ts
51 lines (46 loc) · 1.29 KB
/
utils.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
import {
CHAIN_ID_COSMOSHUB,
CHAIN_ID_EVMOS,
CHAIN_ID_KUJIRA,
CHAIN_ID_OSMOSIS,
CHAIN_ID_WORMCHAIN,
} from '@certusone/wormhole-sdk';
import { logs as cosmosLogs } from '@cosmjs/stargate';
import { ChainId } from '../../types';
/**
* Search for a specific piece of information emitted by the contracts during the transaction
* For example: to retrieve the bridge transfer recipient, we would have to look
* for the "transfer.recipient" under the "wasm" event
*/
export const searchCosmosLogs = (
key: string,
logs: readonly cosmosLogs.Log[],
): string | null => {
const parts = key.split('.');
// if event, search for the first attribute with the given key
const [event, attribute] =
parts.length > 1
? [parts[0], parts.slice(1).join('.')]
: [undefined, parts[0]];
for (const log of logs) {
for (const ev of log.events) {
if (event && ev.type !== event) continue;
for (const attr of ev.attributes) {
if (attr.key === attribute) {
return attr.value;
}
}
}
}
return null;
};
const GATEWAY_CHAINS: ChainId[] = [
CHAIN_ID_COSMOSHUB,
CHAIN_ID_EVMOS,
CHAIN_ID_OSMOSIS,
CHAIN_ID_WORMCHAIN,
CHAIN_ID_KUJIRA,
];
export function isGatewayChain(chainId: ChainId): boolean {
return GATEWAY_CHAINS.includes(chainId);
}