emit.gno
9.41 Kb · 231 lines
1package core
2
3import (
4 "gno.land/p/onbloc/ibc/union/types"
5)
6
7// EmitRegisterClient emits the RegisterClient host event.
8func EmitRegisterClient(_ int, rlm realm, clientType types.ClientType) {
9 assertIsRlmCurrent(0, rlm)
10 assertIsProxyRealm(0, rlm)
11 emitRegisterClientEvent(clientType)
12}
13
14// EmitCreateClient emits the CreateClient host event.
15func EmitCreateClient(_ int, rlm realm, clientId types.ClientId, clientType types.ClientType, counterpartyChainId string) {
16 assertIsRlmCurrent(0, rlm)
17 assertIsProxyRealm(0, rlm)
18 emitCreateClientEvent(clientId, clientType, counterpartyChainId)
19}
20
21// EmitUpdateClient emits the UpdateClient host event.
22func EmitUpdateClient(_ int, rlm realm, clientId types.ClientId, height types.Height) {
23 assertIsRlmCurrent(0, rlm)
24 assertIsProxyRealm(0, rlm)
25 emitUpdateClientEvent(clientId, height)
26}
27
28// EmitForceUpdateClient emits the ForceUpdateClient host event.
29func EmitForceUpdateClient(_ int, rlm realm, clientId types.ClientId, height types.Height) {
30 assertIsRlmCurrent(0, rlm)
31 assertIsProxyRealm(0, rlm)
32 emitForceUpdateClientEvent(clientId, height)
33}
34
35// EmitMisbehaviour emits the Misbehaviour host event.
36func EmitMisbehaviour(_ int, rlm realm, clientId types.ClientId) {
37 assertIsRlmCurrent(0, rlm)
38 assertIsProxyRealm(0, rlm)
39 emitMisbehaviourEvent(clientId)
40}
41
42// EmitConnectionOpenInit emits the ConnectionOpenInit host event.
43func EmitConnectionOpenInit(_ int, rlm realm, connectionId types.ConnectionId, clientId, counterpartyClientId types.ClientId) {
44 assertIsRlmCurrent(0, rlm)
45 assertIsProxyRealm(0, rlm)
46 emitConnectionOpenInitEvent(connectionId, clientId, counterpartyClientId)
47}
48
49// EmitConnectionOpenTry emits the ConnectionOpenTry host event.
50func EmitConnectionOpenTry(_ int, rlm realm, connectionId types.ConnectionId, clientId, counterpartyClientId types.ClientId, counterpartyConnectionId types.ConnectionId) {
51 assertIsRlmCurrent(0, rlm)
52 assertIsProxyRealm(0, rlm)
53 emitConnectionOpenTryEvent(connectionId, clientId, counterpartyClientId, counterpartyConnectionId)
54}
55
56// EmitConnectionOpenAck emits the ConnectionOpenAck host event.
57func EmitConnectionOpenAck(_ int, rlm realm, connectionId types.ConnectionId, clientId, counterpartyClientId types.ClientId, counterpartyConnectionId types.ConnectionId) {
58 assertIsRlmCurrent(0, rlm)
59 assertIsProxyRealm(0, rlm)
60 emitConnectionOpenAckEvent(connectionId, clientId, counterpartyClientId, counterpartyConnectionId)
61}
62
63// EmitConnectionOpenConfirm emits the ConnectionOpenConfirm host event.
64func EmitConnectionOpenConfirm(_ int, rlm realm, connectionId types.ConnectionId, clientId, counterpartyClientId types.ClientId, counterpartyConnectionId types.ConnectionId) {
65 assertIsRlmCurrent(0, rlm)
66 assertIsProxyRealm(0, rlm)
67 emitConnectionOpenConfirmEvent(connectionId, clientId, counterpartyClientId, counterpartyConnectionId)
68}
69
70// ConnectionValue returns the H256 commitment value of a connection, exposed so
71// the impl can build the expected counterparty value for membership proofs.
72func ConnectionValue(connection types.Connection) types.H256 {
73 return connectionValue(connection)
74}
75
76// ChannelValue returns the H256 commitment value of a channel, exposed so the
77// impl can build the expected counterparty value for membership proofs.
78func ChannelValue(channel types.Channel) types.H256 {
79 return channelValue(channel)
80}
81
82// EmitChannelOpenInit emits the ChannelOpenInit host event.
83func EmitChannelOpenInit(_ int, rlm realm, portId types.Bytes, channelId types.ChannelId, channel types.Channel, connection types.Connection) {
84 assertIsRlmCurrent(0, rlm)
85 assertIsProxyRealm(0, rlm)
86 emitChannelOpenInitEvent(portId, channelId, channel, connection)
87}
88
89// EmitChannelOpenTry emits the ChannelOpenTry host event.
90func EmitChannelOpenTry(_ int, rlm realm, portId types.Bytes, channelId types.ChannelId, channel types.Channel, counterpartyVersion string, connection types.Connection) {
91 assertIsRlmCurrent(0, rlm)
92 assertIsProxyRealm(0, rlm)
93 emitChannelOpenTryEvent(portId, channelId, channel, counterpartyVersion, connection)
94}
95
96// EmitChannelOpenAck emits the ChannelOpenAck host event.
97func EmitChannelOpenAck(_ int, rlm realm, portId types.Bytes, channelId types.ChannelId, channel types.Channel, connection types.Connection) {
98 assertIsRlmCurrent(0, rlm)
99 assertIsProxyRealm(0, rlm)
100 emitChannelOpenAckEvent(portId, channelId, channel, connection)
101}
102
103// EmitChannelOpenConfirm emits the ChannelOpenConfirm host event.
104func EmitChannelOpenConfirm(_ int, rlm realm, portId types.Bytes, channelId types.ChannelId, channel types.Channel, connection types.Connection) {
105 assertIsRlmCurrent(0, rlm)
106 assertIsProxyRealm(0, rlm)
107 emitChannelOpenConfirmEvent(portId, channelId, channel, connection)
108}
109
110// EmitChannelCloseInit emits the ChannelCloseInit host event.
111func EmitChannelCloseInit(_ int, rlm realm, portId types.Bytes, channelId types.ChannelId, channel types.Channel, connection types.Connection) {
112 assertIsRlmCurrent(0, rlm)
113 assertIsProxyRealm(0, rlm)
114 emitChannelCloseInitEvent(portId, channelId, channel, connection)
115}
116
117// EmitChannelCloseConfirm emits the ChannelCloseConfirm host event.
118func EmitChannelCloseConfirm(_ int, rlm realm, portId types.Bytes, channelId types.ChannelId, channel types.Channel, connection types.Connection) {
119 assertIsRlmCurrent(0, rlm)
120 assertIsProxyRealm(0, rlm)
121 emitChannelCloseConfirmEvent(portId, channelId, channel, connection)
122}
123
124// EmitAppRegistered emits the AppRegistered host event.
125func EmitAppRegistered(_ int, rlm realm, portId []byte, registrarPkgPath string, adminOverride bool) {
126 assertIsRlmCurrent(0, rlm)
127 assertIsProxyRealm(0, rlm)
128 emitAppRegisteredEvent(portId, registrarPkgPath, adminOverride)
129}
130
131// --- Packet lifecycle: pure helpers and event emitters exposed to the impl ---
132
133// CommitPacketHash returns the union commitment hash of a single packet.
134func CommitPacketHash(packet types.Packet) types.H256 {
135 return commitPacketHash(packet)
136}
137
138// CommitPacketsHash returns the union commitment hash of a packet batch.
139func CommitPacketsHash(packets []types.Packet) types.H256 {
140 return commitPacketsHash(packets)
141}
142
143// EmitPacketSend emits the PacketSend host event.
144func EmitPacketSend(_ int, rlm realm, packet types.Packet, sourceChannel types.Channel, sourceConnection types.Connection) {
145 assertIsRlmCurrent(0, rlm)
146 assertIsProxyRealm(0, rlm)
147 emitPacketSendEvent(packet, sourceChannel, sourceConnection)
148}
149
150// EmitPacketRecv emits the PacketRecv host event.
151func EmitPacketRecv(_ int, rlm realm, packet types.Packet, destinationChannel types.Channel, connection types.Connection, relayerMsg []byte) {
152 assertIsRlmCurrent(0, rlm)
153 assertIsProxyRealm(0, rlm)
154 if !IsValidEventSize(packet.Data, relayerMsg) {
155 panic(makeError(ErrPacketCombinedDataTooLarge))
156 }
157
158 emitPacketRecvEvent(PacketRecvEvent, packet, destinationChannel, connection, relayerMsg)
159}
160
161// EmitIntentPacketRecv emits the IntentPacketRecv host event.
162func EmitIntentPacketRecv(_ int, rlm realm, packet types.Packet, destinationChannel types.Channel, connection types.Connection, marketMakerMsg []byte) {
163 assertIsRlmCurrent(0, rlm)
164 assertIsProxyRealm(0, rlm)
165 if !IsValidEventSize(packet.Data, marketMakerMsg) {
166 panic(makeError(ErrPacketCombinedDataTooLarge))
167 }
168
169 emitPacketRecvEvent(IntentPacketRecvEvent, packet, destinationChannel, connection, marketMakerMsg)
170}
171
172// EmitPacketAck emits the PacketAck host event.
173func EmitPacketAck(_ int, rlm realm, packet types.Packet, sourceChannel types.Channel, connection types.Connection, acknowledgement []byte) {
174 assertIsRlmCurrent(0, rlm)
175 assertIsProxyRealm(0, rlm)
176 if !IsValidEventSize(packet.Data, acknowledgement) {
177 panic(makeError(ErrPacketCombinedDataTooLarge))
178 }
179
180 emitPacketAckEvent(packet, sourceChannel, connection, acknowledgement)
181}
182
183// EmitPacketTimeout emits the PacketTimeout host event.
184func EmitPacketTimeout(_ int, rlm realm, packet types.Packet, sourceChannel types.Channel, connection types.Connection) {
185 assertIsRlmCurrent(0, rlm)
186 assertIsProxyRealm(0, rlm)
187 if !IsValidEventSize(packet.Data) {
188 panic(makeError(ErrPacketCombinedDataTooLarge))
189 }
190
191 emitPacketTimeoutEvent(packet, sourceChannel, connection)
192}
193
194// EmitWriteAck emits the WriteAck host event.
195func EmitWriteAck(_ int, rlm realm, packet types.Packet, destinationChannel types.Channel, connection types.Connection, acknowledgement []byte) {
196 assertIsRlmCurrent(0, rlm)
197 assertIsProxyRealm(0, rlm)
198 if !IsValidEventSize(packet.Data, acknowledgement) {
199 panic(makeError(ErrPacketCombinedDataTooLarge))
200 }
201
202 emitWriteAckEvent(packet, destinationChannel, connection, acknowledgement)
203}
204
205// EmitBatchSend emits the BatchSend host event.
206func EmitBatchSend(_ int, rlm realm, channelId types.ChannelId, packetHash, batchHash types.H256) {
207 assertIsRlmCurrent(0, rlm)
208 assertIsProxyRealm(0, rlm)
209 emitBatchSendEvent(channelId, packetHash, batchHash)
210}
211
212// EmitBatchAcks emits the BatchAcks host event.
213func EmitBatchAcks(_ int, rlm realm, channelId types.ChannelId, packetHash, batchHash types.H256) {
214 assertIsRlmCurrent(0, rlm)
215 assertIsProxyRealm(0, rlm)
216 emitBatchAcksEvent(channelId, packetHash, batchHash)
217}
218
219// EmitCommitMembershipProof emits the CommitMembershipProof host event.
220func EmitCommitMembershipProof(_ int, rlm realm, msg types.MsgCommitMembershipProof) {
221 assertIsRlmCurrent(0, rlm)
222 assertIsProxyRealm(0, rlm)
223 emitCommitMembershipProofEvent(msg)
224}
225
226// EmitCommitNonMembershipProof emits the CommitNonMembershipProof host event.
227func EmitCommitNonMembershipProof(_ int, rlm realm, msg types.MsgCommitNonMembershipProof) {
228 assertIsRlmCurrent(0, rlm)
229 assertIsProxyRealm(0, rlm)
230 emitCommitNonMembershipProofEvent(msg)
231}