-
Notifications
You must be signed in to change notification settings - Fork 2
/
ibc_helper.js
128 lines (120 loc) · 3.99 KB
/
ibc_helper.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {
MsgRecvPacket,
MsgAcknowledgement,
MsgTimeout,
MsgChannelOpenTry,
MsgChannelOpenInit,
MsgChannelOpenAck,
MsgChannelOpenConfirm,
MsgChannelCloseInit,
MsgChannelCloseConfirm,
MsgTimeoutOnClose
} from 'cosmjs-types/ibc/core/channel/v1/tx.js';
import {
MsgConnectionOpenTry,
MsgConnectionOpenInit,
MsgConnectionOpenAck,
MsgConnectionOpenConfirm
} from 'cosmjs-types/ibc/core/connection/v1/tx.js';
import {
MsgCreateClient,
MsgUpdateClient,
MsgUpgradeClient,
MsgSubmitMisbehaviour
} from 'cosmjs-types/ibc/core/client/v1/tx.js';
import {
MsgTransfer
} from 'cosmjs-types/ibc/applications/transfer/v1/tx.js';
import {
MsgPayPacketFee,
MsgPayPacketFeeAsync,
MsgRegisterCounterpartyPayee,
MsgRegisterPayee
} from 'cosmjs-types/ibc/applications/fee/v1/tx.js';
function decodeMessage(msg) {
msg.result = `Decoded message type: ${msg.typeUrl}`;
msg.relevant = false;
switch (msg.typeUrl) {
// Channel messages
case '/ibc.core.channel.v1.MsgRecvPacket':
msg.value = MsgRecvPacket.decode(msg.value);
msg.relevant = true;
break;
case '/ibc.core.channel.v1.MsgAcknowledgement':
msg.value = MsgAcknowledgement.decode(msg.value);
msg.relevant = true;
break;
case '/ibc.core.channel.v1.MsgTimeout':
msg.value = MsgTimeout.decode(msg.value);
msg.relevant = true;
break;
case '/ibc.core.channel.v1.MsgChannelOpenTry':
msg.value = MsgChannelOpenTry.decode(msg.value);
break;
case '/ibc.core.channel.v1.MsgChannelOpenInit':
msg.value = MsgChannelOpenInit.decode(msg.value);
break;
case '/ibc.core.channel.v1.MsgChannelOpenAck':
msg.value = MsgChannelOpenAck.decode(msg.value);
break;
case '/ibc.core.channel.v1.MsgChannelOpenConfirm':
msg.value = MsgChannelOpenConfirm.decode(msg.value);
break;
case '/ibc.core.channel.v1.MsgChannelCloseInit':
msg.value = MsgChannelCloseInit.decode(msg.value);
break;
case '/ibc.core.channel.v1.MsgChannelCloseConfirm':
msg.value = MsgChannelCloseConfirm.decode(msg.value);
break;
case '/ibc.core.channel.v1.MsgTimeoutOnClose':
msg.value = MsgTimeoutOnClose.decode(msg.value);
break;
// Client messages
case '/ibc.core.client.v1.MsgCreateClient':
msg.value = MsgCreateClient.decode(msg.value);
break;
case '/ibc.core.client.v1.MsgUpdateClient':
msg.value = MsgUpdateClient.decode(msg.value);
break;
case '/ibc.core.client.v1.MsgUpgradeClient':
msg.value = MsgUpgradeClient.decode(msg.value);
break;
case '/ibc.core.client.v1.MsgSubmitMisbehaviour':
msg.value = MsgSubmitMisbehaviour.decode(msg.value);
break;
// Connection messages
case '/ibc.core.connection.v1.MsgConnectionOpenTry':
msg.value = MsgConnectionOpenTry.decode(msg.value);
break;
case '/ibc.core.connection.v1.MsgConnectionOpenInit':
msg.value = MsgConnectionOpenInit.decode(msg.value);
break;
case '/ibc.core.connection.v1.MsgConnectionOpenAck':
msg.value = MsgConnectionOpenAck.decode(msg.value);
break;
case '/ibc.core.connection.v1.MsgConnectionOpenConfirm':
msg.value = MsgConnectionOpenConfirm.decode(msg.value);
break;
// Transfer message
case '/ibc.applications.transfer.v1.MsgTransfer':
msg.value = MsgTransfer.decode(msg.value);
break;
// Fee messages
case '/ibc.applications.fee.v1.MsgPayPacketFee':
msg.value = MsgPayPacketFee.decode(msg.value);
break;
case '/ibc.applications.fee.v1.MsgPayPacketFeeAsync':
msg.value = MsgPayPacketFeeAsync.decode(msg.value);
break;
case '/ibc.applications.fee.v1.MsgRegisterCounterpartyPayee':
msg.value = MsgRegisterCounterpartyPayee.decode(msg.value);
break;
case '/ibc.applications.fee.v1.MsgRegisterPayee':
msg.value = MsgRegisterPayee.decode(msg.value);
break;
default:
msg.result = `Undecoded message type: ${msg.typeUrl}`;
}
return msg;
}
export default decodeMessage;