@agoric/cosmos 0.35.0-upgrade-14-dev-c8f9e7b.0 → 0.35.0-upgrade-16a-dev-fb592e4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -77
- package/MAINTAINERS.md +3 -0
- package/Makefile +36 -26
- package/ante/ante.go +7 -9
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +212 -140
- package/app/upgrade.go +76 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +130 -11
- package/cmd/libdaemon/main.go +64 -53
- package/cmd/libdaemon/main_test.go +2 -1
- package/daemon/cmd/root.go +171 -74
- package/daemon/cmd/root_test.go +189 -1
- package/daemon/main.go +4 -2
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -1
- package/go.mod +22 -11
- package/go.sum +17 -13
- package/package.json +9 -5
- package/proto/agoric/swingset/genesis.proto +4 -0
- package/proto/agoric/swingset/swingset.proto +1 -1
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +7 -8
- package/types/kv_entry_helpers.go +42 -0
- package/upgradegaia.sh +8 -8
- package/vm/action.go +5 -4
- package/vm/action_test.go +31 -11
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +17 -40
- package/vm/core_proposals.go +22 -2
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +10 -10
- package/x/swingset/alias.go +2 -0
- package/x/swingset/client/cli/tx.go +4 -0
- package/x/swingset/genesis.go +84 -24
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +2 -2
- package/x/swingset/keeper/keeper.go +13 -25
- package/x/swingset/keeper/msg_server.go +18 -18
- package/x/swingset/keeper/proposal.go +3 -3
- package/x/swingset/keeper/querier.go +12 -11
- package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +7 -7
- package/x/swingset/proposal_handler.go +2 -1
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/expected_keepers.go +3 -2
- package/x/swingset/types/genesis.pb.go +78 -25
- package/x/swingset/types/msgs.go +44 -24
- package/x/swingset/types/params.go +2 -1
- package/x/swingset/types/proposal.go +5 -4
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/querier.go +4 -3
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +9 -9
- package/x/vbank/vbank_test.go +2 -2
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +16 -9
- package/x/vibc/keeper/keeper.go +102 -65
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +13 -0
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +0 -1
- package/x/vstorage/keeper/keeper.go +13 -20
- package/x/vstorage/keeper/querier.go +6 -5
- package/x/vstorage/keeper/querier_test.go +4 -3
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/ante/fee.go +0 -96
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -290
- package/x/lien/keeper/keeper.go +0 -255
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -205
- package/x/lien/lien_test.go +0 -533
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/vibc/ibc.go +0 -394
- /package/{src/index.cjs → index.cjs} +0 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
package types
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
5
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
6
|
+
capability "github.com/cosmos/cosmos-sdk/x/capability/types"
|
|
7
|
+
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
|
|
8
|
+
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
|
|
9
|
+
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
|
|
10
|
+
|
|
11
|
+
"github.com/cosmos/ibc-go/v6/modules/core/exported"
|
|
12
|
+
|
|
13
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
const (
|
|
17
|
+
// AsyncVersions is a flag that indicates whether the IBC module supports
|
|
18
|
+
// asynchronous versions. If it does, then the VM must supply an empty
|
|
19
|
+
// version string to indicate that the VM explicitly (possibly async)
|
|
20
|
+
// performs the Write* method.
|
|
21
|
+
// This flag is created in anticipation of ibc-go implementing async versions,
|
|
22
|
+
// see https://github.com/Agoric/agoric-sdk/issues/9358 for more details.
|
|
23
|
+
AsyncVersions = false
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
var (
|
|
27
|
+
_ porttypes.IBCModule = (*IBCModule)(nil)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
type IBCModuleImpl interface {
|
|
31
|
+
ClaimCapability(ctx sdk.Context, channelCap *capability.Capability, path string) error
|
|
32
|
+
GetChannel(ctx sdk.Context, portID, channelID string) (channeltypes.Channel, bool)
|
|
33
|
+
PushAction(ctx sdk.Context, action vm.Action) error
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type IBCModule struct {
|
|
37
|
+
impl IBCModuleImpl
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func NewIBCModule(impl IBCModuleImpl) IBCModule {
|
|
41
|
+
return IBCModule{
|
|
42
|
+
impl: impl,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type ChannelOpenInitEvent struct {
|
|
47
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
48
|
+
Event string `json:"event" default:"channelOpenInit"`
|
|
49
|
+
Target string `json:"target,omitempty"`
|
|
50
|
+
Order string `json:"order"`
|
|
51
|
+
ConnectionHops []string `json:"connectionHops"`
|
|
52
|
+
PortID string `json:"portID"`
|
|
53
|
+
ChannelID string `json:"channelID"`
|
|
54
|
+
Counterparty channeltypes.Counterparty `json:"counterparty"`
|
|
55
|
+
Version string `json:"version"`
|
|
56
|
+
AsyncVersions bool `json:"asyncVersions"`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Implement IBCModule callbacks
|
|
60
|
+
func (im IBCModule) OnChanOpenInit(
|
|
61
|
+
ctx sdk.Context,
|
|
62
|
+
order channeltypes.Order,
|
|
63
|
+
connectionHops []string,
|
|
64
|
+
portID string,
|
|
65
|
+
channelID string,
|
|
66
|
+
channelCap *capability.Capability,
|
|
67
|
+
counterparty channeltypes.Counterparty,
|
|
68
|
+
version string,
|
|
69
|
+
) (string, error) {
|
|
70
|
+
event := ChannelOpenInitEvent{
|
|
71
|
+
Order: orderToString(order),
|
|
72
|
+
ConnectionHops: connectionHops,
|
|
73
|
+
PortID: portID,
|
|
74
|
+
ChannelID: channelID,
|
|
75
|
+
Counterparty: counterparty,
|
|
76
|
+
Version: version,
|
|
77
|
+
AsyncVersions: AsyncVersions,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
err := im.impl.PushAction(ctx, event)
|
|
81
|
+
if err != nil {
|
|
82
|
+
return "", err
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Claim channel capability passed back by IBC module
|
|
86
|
+
if err := im.impl.ClaimCapability(ctx, channelCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
|
|
87
|
+
return "", err
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if !event.AsyncVersions {
|
|
91
|
+
// We have to supply a synchronous version, so just echo back the one they sent.
|
|
92
|
+
return event.Version, nil
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return "", nil
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type ChannelOpenTryEvent struct {
|
|
99
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
100
|
+
Event string `json:"event" default:"channelOpenTry"`
|
|
101
|
+
Target string `json:"target,omitempty"`
|
|
102
|
+
Order string `json:"order"`
|
|
103
|
+
ConnectionHops []string `json:"connectionHops"`
|
|
104
|
+
PortID string `json:"portID"`
|
|
105
|
+
ChannelID string `json:"channelID"`
|
|
106
|
+
Counterparty channeltypes.Counterparty `json:"counterparty"`
|
|
107
|
+
Version string `json:"version"`
|
|
108
|
+
AsyncVersions bool `json:"asyncVersions"`
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
func (im IBCModule) OnChanOpenTry(
|
|
112
|
+
ctx sdk.Context,
|
|
113
|
+
order channeltypes.Order,
|
|
114
|
+
connectionHops []string,
|
|
115
|
+
portID,
|
|
116
|
+
channelID string,
|
|
117
|
+
channelCap *capability.Capability,
|
|
118
|
+
counterparty channeltypes.Counterparty,
|
|
119
|
+
counterpartyVersion string,
|
|
120
|
+
) (string, error) {
|
|
121
|
+
event := ChannelOpenTryEvent{
|
|
122
|
+
Order: orderToString(order),
|
|
123
|
+
ConnectionHops: connectionHops,
|
|
124
|
+
PortID: portID,
|
|
125
|
+
ChannelID: channelID,
|
|
126
|
+
Counterparty: counterparty,
|
|
127
|
+
Version: counterpartyVersion,
|
|
128
|
+
AsyncVersions: AsyncVersions,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
err := im.impl.PushAction(ctx, event)
|
|
132
|
+
if err != nil {
|
|
133
|
+
return "", err
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Claim channel capability passed back by IBC module
|
|
137
|
+
if err = im.impl.ClaimCapability(ctx, channelCap, host.ChannelCapabilityPath(portID, channelID)); err != nil {
|
|
138
|
+
return "", sdkioerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, err.Error())
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if !event.AsyncVersions {
|
|
142
|
+
// We have to supply a synchronous version, so just echo back the one they sent.
|
|
143
|
+
return event.Version, nil
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Use an empty version string to indicate that the VM explicitly (possibly
|
|
147
|
+
// async) performs the WriteOpenTryChannel.
|
|
148
|
+
return "", nil
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type ChannelOpenAckEvent struct {
|
|
152
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
153
|
+
Event string `json:"event" default:"channelOpenAck"`
|
|
154
|
+
PortID string `json:"portID"`
|
|
155
|
+
ChannelID string `json:"channelID"`
|
|
156
|
+
CounterpartyVersion string `json:"counterpartyVersion"`
|
|
157
|
+
Counterparty channeltypes.Counterparty `json:"counterparty"`
|
|
158
|
+
ConnectionHops []string `json:"connectionHops"`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
func (im IBCModule) OnChanOpenAck(
|
|
162
|
+
ctx sdk.Context,
|
|
163
|
+
portID,
|
|
164
|
+
channelID string,
|
|
165
|
+
counterpartyChannelID string,
|
|
166
|
+
counterpartyVersion string,
|
|
167
|
+
) error {
|
|
168
|
+
// We don't care if the channel was found. If it wasn't then GetChannel
|
|
169
|
+
// returns an empty channel object that we can still use without crashing.
|
|
170
|
+
channel, _ := im.impl.GetChannel(ctx, portID, channelID)
|
|
171
|
+
|
|
172
|
+
channel.Counterparty.ChannelId = counterpartyChannelID
|
|
173
|
+
event := ChannelOpenAckEvent{
|
|
174
|
+
PortID: portID,
|
|
175
|
+
ChannelID: channelID,
|
|
176
|
+
CounterpartyVersion: counterpartyVersion,
|
|
177
|
+
Counterparty: channel.Counterparty,
|
|
178
|
+
ConnectionHops: channel.ConnectionHops,
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return im.impl.PushAction(ctx, event)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
type ChannelOpenConfirmEvent struct {
|
|
185
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
186
|
+
Event string `json:"event" default:"channelOpenConfirm"`
|
|
187
|
+
Target string `json:"target,omitempty"`
|
|
188
|
+
PortID string `json:"portID"`
|
|
189
|
+
ChannelID string `json:"channelID"`
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
func (im IBCModule) OnChanOpenConfirm(
|
|
193
|
+
ctx sdk.Context,
|
|
194
|
+
portID,
|
|
195
|
+
channelID string,
|
|
196
|
+
) error {
|
|
197
|
+
event := ChannelOpenConfirmEvent{
|
|
198
|
+
PortID: portID,
|
|
199
|
+
ChannelID: channelID,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return im.impl.PushAction(ctx, event)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
type ChannelCloseInitEvent struct {
|
|
206
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
207
|
+
Event string `json:"event" default:"channelCloseInit"`
|
|
208
|
+
Target string `json:"target,omitempty"`
|
|
209
|
+
PortID string `json:"portID"`
|
|
210
|
+
ChannelID string `json:"channelID"`
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
func (im IBCModule) OnChanCloseInit(
|
|
214
|
+
ctx sdk.Context,
|
|
215
|
+
portID,
|
|
216
|
+
channelID string,
|
|
217
|
+
) error {
|
|
218
|
+
event := ChannelCloseInitEvent{
|
|
219
|
+
PortID: portID,
|
|
220
|
+
ChannelID: channelID,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
err := im.impl.PushAction(ctx, event)
|
|
224
|
+
return err
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
type ChannelCloseConfirmEvent struct {
|
|
228
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
229
|
+
Event string `json:"event" default:"channelCloseConfirm"`
|
|
230
|
+
Target string `json:"target,omitempty"`
|
|
231
|
+
PortID string `json:"portID"`
|
|
232
|
+
ChannelID string `json:"channelID"`
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
func (im IBCModule) OnChanCloseConfirm(
|
|
236
|
+
ctx sdk.Context,
|
|
237
|
+
portID,
|
|
238
|
+
channelID string,
|
|
239
|
+
) error {
|
|
240
|
+
event := ChannelCloseConfirmEvent{
|
|
241
|
+
PortID: portID,
|
|
242
|
+
ChannelID: channelID,
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
err := im.impl.PushAction(ctx, event)
|
|
246
|
+
return err
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
type ReceivePacketEvent struct {
|
|
250
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
251
|
+
Event string `json:"event" default:"receivePacket"`
|
|
252
|
+
Target string `json:"target,omitempty"`
|
|
253
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
254
|
+
Relayer sdk.AccAddress `json:"relayer"`
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
func (im IBCModule) OnRecvPacket(
|
|
258
|
+
ctx sdk.Context,
|
|
259
|
+
packet channeltypes.Packet,
|
|
260
|
+
relayer sdk.AccAddress,
|
|
261
|
+
) exported.Acknowledgement {
|
|
262
|
+
// Sometimes we receive duplicate packets, just with a
|
|
263
|
+
// missing packet.TimeoutTimestamp. This causes duplicate
|
|
264
|
+
// acks, with one of them being rejected.
|
|
265
|
+
//
|
|
266
|
+
// This turns out to happen when you run both "rly start"
|
|
267
|
+
// and also "rly tx xfer"-- they both are trying to relay
|
|
268
|
+
// the same packets.
|
|
269
|
+
|
|
270
|
+
event := ReceivePacketEvent{
|
|
271
|
+
Packet: packet,
|
|
272
|
+
Relayer: relayer,
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
err := im.impl.PushAction(ctx, event)
|
|
276
|
+
if err != nil {
|
|
277
|
+
return channeltypes.NewErrorAcknowledgement(err)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return nil
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type AcknowledgementPacketEvent struct {
|
|
284
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
285
|
+
Event string `json:"event" default:"acknowledgementPacket"`
|
|
286
|
+
Target string `json:"target,omitempty"`
|
|
287
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
288
|
+
Acknowledgement []byte `json:"acknowledgement"`
|
|
289
|
+
Relayer sdk.AccAddress `json:"relayer"`
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
func (im IBCModule) OnAcknowledgementPacket(
|
|
293
|
+
ctx sdk.Context,
|
|
294
|
+
packet channeltypes.Packet,
|
|
295
|
+
acknowledgement []byte,
|
|
296
|
+
relayer sdk.AccAddress,
|
|
297
|
+
) error {
|
|
298
|
+
event := AcknowledgementPacketEvent{
|
|
299
|
+
Packet: packet,
|
|
300
|
+
Acknowledgement: acknowledgement,
|
|
301
|
+
Relayer: relayer,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
err := im.impl.PushAction(ctx, event)
|
|
305
|
+
if err != nil {
|
|
306
|
+
return err
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return nil
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
type TimeoutPacketEvent struct {
|
|
313
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
314
|
+
Event string `json:"event" default:"timeoutPacket"`
|
|
315
|
+
Target string `json:"target,omitempty"`
|
|
316
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
317
|
+
Relayer sdk.AccAddress `json:"relayer"`
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
func (im IBCModule) OnTimeoutPacket(
|
|
321
|
+
ctx sdk.Context,
|
|
322
|
+
packet channeltypes.Packet,
|
|
323
|
+
relayer sdk.AccAddress,
|
|
324
|
+
) error {
|
|
325
|
+
event := TimeoutPacketEvent{
|
|
326
|
+
Packet: packet,
|
|
327
|
+
Relayer: relayer,
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
err := im.impl.PushAction(ctx, event)
|
|
331
|
+
if err != nil {
|
|
332
|
+
return err
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return nil
|
|
336
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
package types
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"fmt"
|
|
7
|
+
|
|
8
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
9
|
+
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
|
|
10
|
+
|
|
11
|
+
"github.com/cosmos/ibc-go/v6/modules/core/exported"
|
|
12
|
+
|
|
13
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
var (
|
|
17
|
+
_ vm.PortHandler = (*Receiver)(nil)
|
|
18
|
+
_ exported.Acknowledgement = (*rawAcknowledgement)(nil)
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
type ReceiverImpl interface {
|
|
22
|
+
ReceiveSendPacket(ctx sdk.Context, packet exported.PacketI) (uint64, error)
|
|
23
|
+
ReceiveWriteAcknowledgement(ctx sdk.Context, packet exported.PacketI, ack exported.Acknowledgement) error
|
|
24
|
+
ReceiveChanOpenInit(ctx sdk.Context, order channeltypes.Order, hops []string, sourcePort, destinationPort, version string) error
|
|
25
|
+
ReceiveWriteOpenTryChannel(ctx sdk.Context, packet exported.PacketI, order channeltypes.Order, connectionHops []string, version string) error
|
|
26
|
+
ReceiveChanCloseInit(ctx sdk.Context, sourcePort, sourceChannel string) error
|
|
27
|
+
ReceiveBindPort(ctx sdk.Context, sourcePort string) error
|
|
28
|
+
ReceiveTimeoutExecuted(ctx sdk.Context, packet exported.PacketI) error
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Receiver struct {
|
|
32
|
+
impl ReceiverImpl
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func NewReceiver(impl ReceiverImpl) Receiver {
|
|
36
|
+
return Receiver{
|
|
37
|
+
impl: impl,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type portMessage struct { // comes from swingset's IBC handler
|
|
42
|
+
Type string `json:"type"` // IBC_METHOD
|
|
43
|
+
Method string `json:"method"`
|
|
44
|
+
Packet channeltypes.Packet `json:"packet"`
|
|
45
|
+
RelativeTimeoutNs uint64 `json:"relativeTimeoutNs,string"`
|
|
46
|
+
Order string `json:"order"`
|
|
47
|
+
Hops []string `json:"hops"`
|
|
48
|
+
Version string `json:"version"`
|
|
49
|
+
Ack []byte `json:"ack"`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func stringToOrder(order string) channeltypes.Order {
|
|
53
|
+
switch order {
|
|
54
|
+
case "ORDERED":
|
|
55
|
+
return channeltypes.ORDERED
|
|
56
|
+
case "UNORDERED":
|
|
57
|
+
return channeltypes.UNORDERED
|
|
58
|
+
default:
|
|
59
|
+
return channeltypes.NONE
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func orderToString(order channeltypes.Order) string {
|
|
64
|
+
switch order {
|
|
65
|
+
case channeltypes.ORDERED:
|
|
66
|
+
return "ORDERED"
|
|
67
|
+
case channeltypes.UNORDERED:
|
|
68
|
+
return "UNORDERED"
|
|
69
|
+
default:
|
|
70
|
+
return "NONE"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type rawAcknowledgement struct {
|
|
75
|
+
data []byte
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func (r rawAcknowledgement) Acknowledgement() []byte {
|
|
79
|
+
return r.data
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func (r rawAcknowledgement) Success() bool {
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Receive implements vm.PortHandler. It unmarshals the string as JSON text
|
|
87
|
+
// representing an IBC portMessage object. If the resulting type is
|
|
88
|
+
// "IBC_METHOD" it dispatches on method ("sendPacket"/"receiveExecuted"/etc.)
|
|
89
|
+
// and calls the corresponding method of the wrapped ReceiverImpl.
|
|
90
|
+
//
|
|
91
|
+
// Otherwise, it requires the wrapped ReceiverImpl to be a vm.PortHandler
|
|
92
|
+
// and delegates to the Receive method of that PortHandler.
|
|
93
|
+
func (ir Receiver) Receive(cctx context.Context, jsonRequest string) (jsonReply string, err error) {
|
|
94
|
+
ctx := sdk.UnwrapSDKContext(cctx)
|
|
95
|
+
impl := ir.impl
|
|
96
|
+
|
|
97
|
+
msg := new(portMessage)
|
|
98
|
+
err = json.Unmarshal([]byte(jsonRequest), &msg)
|
|
99
|
+
if err != nil {
|
|
100
|
+
return "", err
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if msg.Type != "IBC_METHOD" {
|
|
104
|
+
if receiver, ok := impl.(vm.PortHandler); ok {
|
|
105
|
+
return receiver.Receive(cctx, jsonRequest)
|
|
106
|
+
}
|
|
107
|
+
return "", fmt.Errorf(`channel handler only accepts messages of "type": "IBC_METHOD"; got %q`, msg.Type)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
switch msg.Method {
|
|
111
|
+
case "sendPacket":
|
|
112
|
+
timeoutTimestamp := msg.Packet.TimeoutTimestamp
|
|
113
|
+
if msg.Packet.TimeoutHeight.IsZero() && timeoutTimestamp == 0 {
|
|
114
|
+
// Use the relative timeout if no absolute timeout is specifiied.
|
|
115
|
+
timeoutTimestamp = uint64(ctx.BlockTime().UnixNano()) + msg.RelativeTimeoutNs
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
packet := channeltypes.NewPacket(
|
|
119
|
+
msg.Packet.Data, 0,
|
|
120
|
+
msg.Packet.SourcePort, msg.Packet.SourceChannel,
|
|
121
|
+
msg.Packet.DestinationPort, msg.Packet.DestinationChannel,
|
|
122
|
+
msg.Packet.TimeoutHeight, timeoutTimestamp,
|
|
123
|
+
)
|
|
124
|
+
seq, err := impl.ReceiveSendPacket(ctx, packet)
|
|
125
|
+
if err == nil {
|
|
126
|
+
packet.Sequence = seq
|
|
127
|
+
bytes, err := json.Marshal(&packet)
|
|
128
|
+
if err == nil {
|
|
129
|
+
jsonReply = string(bytes)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case "tryOpenExecuted":
|
|
134
|
+
err = impl.ReceiveWriteOpenTryChannel(
|
|
135
|
+
ctx, msg.Packet,
|
|
136
|
+
stringToOrder(msg.Order), msg.Hops, msg.Version,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
case "receiveExecuted":
|
|
140
|
+
ack := rawAcknowledgement{
|
|
141
|
+
data: msg.Ack,
|
|
142
|
+
}
|
|
143
|
+
err = impl.ReceiveWriteAcknowledgement(ctx, msg.Packet, ack)
|
|
144
|
+
|
|
145
|
+
case "startChannelOpenInit":
|
|
146
|
+
err = impl.ReceiveChanOpenInit(
|
|
147
|
+
ctx, stringToOrder(msg.Order), msg.Hops,
|
|
148
|
+
msg.Packet.SourcePort,
|
|
149
|
+
msg.Packet.DestinationPort,
|
|
150
|
+
msg.Version,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
case "startChannelCloseInit":
|
|
154
|
+
err = impl.ReceiveChanCloseInit(ctx, msg.Packet.SourcePort, msg.Packet.SourceChannel)
|
|
155
|
+
|
|
156
|
+
case "bindPort":
|
|
157
|
+
err = impl.ReceiveBindPort(ctx, msg.Packet.SourcePort)
|
|
158
|
+
|
|
159
|
+
case "timeoutExecuted":
|
|
160
|
+
err = impl.ReceiveTimeoutExecuted(ctx, msg.Packet)
|
|
161
|
+
|
|
162
|
+
default:
|
|
163
|
+
err = fmt.Errorf("unrecognized method %s", msg.Method)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if jsonReply == "" && err == nil {
|
|
167
|
+
jsonReply = "true"
|
|
168
|
+
}
|
|
169
|
+
return
|
|
170
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package vlocalchain
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vlocalchain/keeper"
|
|
5
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vlocalchain/types"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
const (
|
|
9
|
+
ModuleName = types.ModuleName
|
|
10
|
+
StoreKey = types.StoreKey
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
var (
|
|
14
|
+
NewKeeper = keeper.NewKeeper
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
type (
|
|
18
|
+
Keeper = keeper.Keeper
|
|
19
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package vlocalchain
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
|
|
6
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
7
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vlocalchain/keeper"
|
|
8
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
|
+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// NewHandler returns a handler for "vlocalchain" type messages.
|
|
13
|
+
func NewHandler(keeper keeper.Keeper) sdk.Handler {
|
|
14
|
+
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
|
15
|
+
switch msg := msg.(type) {
|
|
16
|
+
default:
|
|
17
|
+
errMsg := fmt.Sprintf("Unrecognized vlocalchain Msg type: %T", msg)
|
|
18
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|