@agoric/cosmos 0.35.0-upgrade-14-dev-0169c7e.0 → 0.35.0-upgrade-16-dev-07b0130.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.
Files changed (169) hide show
  1. package/CHANGELOG.md +121 -77
  2. package/MAINTAINERS.md +3 -0
  3. package/Makefile +49 -26
  4. package/ante/ante.go +11 -11
  5. package/ante/inbound_test.go +3 -2
  6. package/ante/vm_admission.go +2 -1
  7. package/app/app.go +260 -175
  8. package/app/export.go +13 -6
  9. package/app/upgrade.go +76 -0
  10. package/cmd/agd/agvm.go +42 -0
  11. package/cmd/agd/main.go +132 -11
  12. package/cmd/libdaemon/main.go +67 -53
  13. package/cmd/libdaemon/main_test.go +2 -1
  14. package/daemon/cmd/genaccounts.go +13 -9
  15. package/daemon/cmd/root.go +186 -73
  16. package/daemon/cmd/root_test.go +190 -2
  17. package/daemon/cmd/testnet.go +17 -6
  18. package/daemon/main.go +6 -3
  19. package/e2e_test/Makefile +29 -0
  20. package/e2e_test/README.md +100 -0
  21. package/e2e_test/go.mod +217 -0
  22. package/e2e_test/go.sum +1323 -0
  23. package/e2e_test/ibc_conformance_test.go +56 -0
  24. package/e2e_test/pfm_test.go +613 -0
  25. package/e2e_test/util.go +271 -0
  26. package/git-revision.txt +1 -1
  27. package/go.mod +110 -68
  28. package/go.sum +601 -248
  29. package/package.json +9 -5
  30. package/proto/agoric/swingset/genesis.proto +4 -0
  31. package/proto/agoric/swingset/swingset.proto +1 -1
  32. package/proto/agoric/vlocalchain/.clang-format +7 -0
  33. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  34. package/proto/agoric/vstorage/query.proto +53 -1
  35. package/proto/agoric/vtransfer/genesis.proto +18 -0
  36. package/scripts/protocgen.sh +16 -6
  37. package/third_party/proto/buf.yaml +1 -0
  38. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  39. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  40. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  41. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  42. package/third_party/proto/google/api/annotations.proto +1 -1
  43. package/third_party/proto/google/api/http.proto +181 -120
  44. package/third_party/proto/google/api/httpbody.proto +9 -6
  45. package/third_party/proto/google/protobuf/any.proto +1 -7
  46. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  47. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  48. package/types/kv_entry_helpers.go +42 -0
  49. package/upgradegaia.sh +21 -12
  50. package/vm/action.go +28 -24
  51. package/vm/action_test.go +36 -16
  52. package/vm/client.go +113 -0
  53. package/vm/client_test.go +182 -0
  54. package/vm/controller.go +18 -42
  55. package/vm/core_proposals.go +22 -2
  56. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  57. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  58. package/vm/proto_json.go +38 -0
  59. package/vm/proto_json_test.go +103 -0
  60. package/vm/server.go +124 -0
  61. package/x/swingset/abci.go +10 -10
  62. package/x/swingset/alias.go +2 -0
  63. package/x/swingset/client/cli/query.go +2 -2
  64. package/x/swingset/client/cli/tx.go +52 -33
  65. package/x/swingset/client/proposal_handler.go +2 -17
  66. package/x/swingset/genesis.go +84 -24
  67. package/x/swingset/handler.go +2 -1
  68. package/x/swingset/keeper/extension_snapshotter.go +2 -2
  69. package/x/swingset/keeper/keeper.go +21 -36
  70. package/x/swingset/keeper/keeper_test.go +1 -1
  71. package/x/swingset/keeper/msg_server.go +20 -22
  72. package/x/swingset/keeper/proposal.go +13 -3
  73. package/x/swingset/keeper/querier.go +23 -14
  74. package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
  75. package/x/swingset/keeper/test_utils.go +16 -0
  76. package/x/swingset/module.go +7 -7
  77. package/x/swingset/proposal_handler.go +5 -4
  78. package/x/swingset/swingset.go +4 -2
  79. package/x/swingset/testing/queue.go +17 -0
  80. package/x/swingset/types/codec.go +2 -2
  81. package/x/swingset/types/default-params.go +1 -1
  82. package/x/swingset/types/expected_keepers.go +3 -2
  83. package/x/swingset/types/genesis.pb.go +78 -25
  84. package/x/swingset/types/msgs.go +44 -24
  85. package/x/swingset/types/msgs.pb.go +16 -16
  86. package/x/swingset/types/params.go +2 -1
  87. package/x/swingset/types/proposal.go +10 -9
  88. package/x/swingset/types/swingset.pb.go +1 -1
  89. package/x/swingset/types/types.go +30 -28
  90. package/x/vbank/genesis.go +0 -2
  91. package/x/vbank/handler.go +2 -1
  92. package/x/vbank/keeper/keeper.go +3 -2
  93. package/x/vbank/keeper/querier.go +9 -4
  94. package/x/vbank/keeper/rewards.go +1 -1
  95. package/x/vbank/module.go +0 -5
  96. package/x/vbank/types/msgs.go +0 -12
  97. package/x/vbank/vbank.go +20 -19
  98. package/x/vbank/vbank_test.go +10 -10
  99. package/x/vibc/alias.go +3 -0
  100. package/x/vibc/handler.go +16 -9
  101. package/x/vibc/keeper/keeper.go +112 -74
  102. package/x/vibc/keeper/triggers.go +101 -0
  103. package/x/vibc/module.go +5 -8
  104. package/x/vibc/types/expected_keepers.go +26 -5
  105. package/x/vibc/types/ibc_module.go +336 -0
  106. package/x/vibc/types/msgs.go +1 -1
  107. package/x/vibc/types/msgs.pb.go +1 -1
  108. package/x/vibc/types/receiver.go +170 -0
  109. package/x/vlocalchain/alias.go +19 -0
  110. package/x/vlocalchain/handler.go +21 -0
  111. package/x/vlocalchain/keeper/keeper.go +279 -0
  112. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  113. package/x/vlocalchain/types/codec.go +34 -0
  114. package/x/vlocalchain/types/key.go +27 -0
  115. package/x/vlocalchain/types/msgs.go +16 -0
  116. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  117. package/x/vlocalchain/vlocalchain.go +114 -0
  118. package/x/vlocalchain/vlocalchain_test.go +434 -0
  119. package/x/vstorage/README.md +138 -0
  120. package/x/vstorage/capdata/capdata.go +298 -0
  121. package/x/vstorage/capdata/capdata_test.go +352 -0
  122. package/x/vstorage/client/cli/query.go +51 -4
  123. package/x/vstorage/handler.go +2 -1
  124. package/x/vstorage/keeper/grpc_query.go +220 -0
  125. package/x/vstorage/keeper/keeper.go +16 -22
  126. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  127. package/x/vstorage/keeper/keeper_test.go +1 -1
  128. package/x/vstorage/keeper/querier.go +11 -6
  129. package/x/vstorage/keeper/querier_test.go +4 -3
  130. package/x/vstorage/module.go +0 -5
  131. package/x/vstorage/testing/queue.go +27 -0
  132. package/x/vstorage/types/query.pb.go +646 -36
  133. package/x/vstorage/types/query.pb.gw.go +119 -0
  134. package/x/vstorage/vstorage.go +16 -15
  135. package/x/vstorage/vstorage_test.go +5 -5
  136. package/x/vtransfer/alias.go +13 -0
  137. package/x/vtransfer/genesis.go +39 -0
  138. package/x/vtransfer/genesis_test.go +12 -0
  139. package/x/vtransfer/handler.go +20 -0
  140. package/x/vtransfer/ibc_middleware.go +186 -0
  141. package/x/vtransfer/ibc_middleware_test.go +448 -0
  142. package/x/vtransfer/keeper/keeper.go +281 -0
  143. package/x/vtransfer/module.go +124 -0
  144. package/x/vtransfer/types/expected_keepers.go +38 -0
  145. package/x/vtransfer/types/genesis.pb.go +327 -0
  146. package/x/vtransfer/types/key.go +9 -0
  147. package/x/vtransfer/types/msgs.go +9 -0
  148. package/ante/fee.go +0 -96
  149. package/proto/agoric/lien/genesis.proto +0 -25
  150. package/proto/agoric/lien/lien.proto +0 -25
  151. package/x/lien/alias.go +0 -17
  152. package/x/lien/genesis.go +0 -58
  153. package/x/lien/genesis_test.go +0 -101
  154. package/x/lien/keeper/account.go +0 -290
  155. package/x/lien/keeper/keeper.go +0 -254
  156. package/x/lien/keeper/keeper_test.go +0 -623
  157. package/x/lien/lien.go +0 -203
  158. package/x/lien/lien_test.go +0 -529
  159. package/x/lien/module.go +0 -115
  160. package/x/lien/spec/01_concepts.md +0 -146
  161. package/x/lien/spec/02_messages.md +0 -96
  162. package/x/lien/types/accountkeeper.go +0 -81
  163. package/x/lien/types/accountstate.go +0 -27
  164. package/x/lien/types/expected_keepers.go +0 -18
  165. package/x/lien/types/genesis.pb.go +0 -567
  166. package/x/lien/types/key.go +0 -25
  167. package/x/lien/types/lien.pb.go +0 -403
  168. package/x/vibc/ibc.go +0 -393
  169. /package/{src/index.cjs → index.cjs} +0 -0
@@ -4,63 +4,77 @@ import (
4
4
  "fmt"
5
5
 
6
6
  "github.com/cosmos/cosmos-sdk/codec"
7
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
7
8
  sdk "github.com/cosmos/cosmos-sdk/types"
8
9
 
9
- sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
10
- capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
10
+ sdkioerrors "cosmossdk.io/errors"
11
11
  capability "github.com/cosmos/cosmos-sdk/x/capability/types"
12
- channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
13
- porttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
14
- host "github.com/cosmos/ibc-go/v4/modules/core/24-host"
15
- ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported"
12
+ clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
13
+ channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
14
+ porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
15
+ host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
16
+ ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
16
17
 
17
- bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
18
-
19
- vm "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
18
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
20
19
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
21
20
  )
22
21
 
22
+ var (
23
+ _ porttypes.ICS4Wrapper = Keeper{}
24
+ _ types.IBCModuleImpl = Keeper{}
25
+ _ types.ReceiverImpl = Keeper{}
26
+ )
27
+
23
28
  // Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
24
29
  type Keeper struct {
25
- storeKey sdk.StoreKey
26
- cdc codec.Codec
30
+ cdc codec.Codec
27
31
 
28
32
  channelKeeper types.ChannelKeeper
29
33
  portKeeper types.PortKeeper
30
- scopedKeeper capabilitykeeper.ScopedKeeper
31
- bankKeeper bankkeeper.Keeper
32
34
 
33
- PushAction vm.ActionPusher
35
+ // Filled out by `WithScope`
36
+ scopedKeeper types.ScopedKeeper
37
+ storeKey storetypes.StoreKey
38
+ pushAction vm.ActionPusher
34
39
  }
35
40
 
36
- // NewKeeper creates a new dIBC Keeper instance
41
+ // NewKeeper creates a new vibc Keeper instance
37
42
  func NewKeeper(
38
- cdc codec.Codec, key sdk.StoreKey,
39
- channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper,
40
- bankKeeper bankkeeper.Keeper,
41
- scopedKeeper capabilitykeeper.ScopedKeeper,
42
- pushAction vm.ActionPusher,
43
+ cdc codec.Codec,
44
+ channelKeeper types.ChannelKeeper,
45
+ portKeeper types.PortKeeper,
43
46
  ) Keeper {
44
47
 
45
48
  return Keeper{
46
- storeKey: key,
47
49
  cdc: cdc,
48
- bankKeeper: bankKeeper,
49
50
  channelKeeper: channelKeeper,
50
51
  portKeeper: portKeeper,
51
- scopedKeeper: scopedKeeper,
52
- PushAction: pushAction,
53
52
  }
54
53
  }
55
54
 
56
- func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
57
- return k.bankKeeper.GetBalance(ctx, addr, denom)
55
+ // WithScope returns a new Keeper copied from the receiver, but with the given
56
+ // store key, scoped keeper, and push action.
57
+ func (k Keeper) WithScope(storeKey storetypes.StoreKey, scopedKeeper types.ScopedKeeper, pushAction vm.ActionPusher) Keeper {
58
+ k.storeKey = storeKey
59
+ k.scopedKeeper = scopedKeeper
60
+ k.pushAction = pushAction
61
+ return k
62
+ }
63
+
64
+ // PushAction sends a vm.Action to the VM controller.
65
+ func (k Keeper) PushAction(ctx sdk.Context, action vm.Action) error {
66
+ return k.pushAction(ctx, action)
58
67
  }
59
68
 
60
- // GetNextSequenceSend defines a wrapper function for the channel Keeper's function
69
+ // GetICS4Wrapper returns the ICS4Wrapper interface for the keeper.
70
+ func (k Keeper) GetICS4Wrapper() porttypes.ICS4Wrapper {
71
+ return k
72
+ }
73
+
74
+ // GetAppVersion defines a wrapper function for the channel Keeper's function
61
75
  // in order to expose it to the vibc IBC handler.
62
- func (k Keeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) {
63
- return k.channelKeeper.GetNextSequenceSend(ctx, portID, channelID)
76
+ func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool) {
77
+ return k.channelKeeper.GetAppVersion(ctx, portID, channelID)
64
78
  }
65
79
 
66
80
  // GetChannel defines a wrapper function for the channel Keeper's function
@@ -69,15 +83,14 @@ func (k Keeper) GetChannel(ctx sdk.Context, portID, channelID string) (channelty
69
83
  return k.channelKeeper.GetChannel(ctx, portID, channelID)
70
84
  }
71
85
 
72
- // ChanOpenInit defines a wrapper function for the channel Keeper's function
73
- // in order to expose it to the vibc IBC handler.
74
- func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string,
86
+ // ReceiveChanOpenInit wraps the keeper's ChanOpenInit function.
87
+ func (k Keeper) ReceiveChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string,
75
88
  portID, rPortID, version string,
76
89
  ) error {
77
90
  capName := host.PortPath(portID)
78
91
  portCap, ok := k.GetCapability(ctx, capName)
79
92
  if !ok {
80
- return sdkerrors.Wrapf(porttypes.ErrInvalidPort, "could not retrieve port capability at: %s", capName)
93
+ return sdkioerrors.Wrapf(porttypes.ErrInvalidPort, "could not retrieve port capability at: %s", capName)
81
94
  }
82
95
  counterparty := channeltypes.Counterparty{
83
96
  PortId: rPortID,
@@ -96,56 +109,79 @@ func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connecti
96
109
  return nil
97
110
  }
98
111
 
99
- // SendPacket defines a wrapper function for the channel Keeper's function
100
- // in order to expose it to the vibc IBC handler.
101
- func (k Keeper) SendPacket(ctx sdk.Context, packet ibcexported.PacketI) error {
102
- portID := packet.GetSourcePort()
103
- channelID := packet.GetSourceChannel()
104
- capName := host.ChannelCapabilityPath(portID, channelID)
112
+ // ReceiveSendPacket wraps the keeper's SendPacket function.
113
+ func (k Keeper) ReceiveSendPacket(ctx sdk.Context, packet ibcexported.PacketI) (uint64, error) {
114
+ sourcePort := packet.GetSourcePort()
115
+ sourceChannel := packet.GetSourceChannel()
116
+ timeoutHeight := packet.GetTimeoutHeight()
117
+ timeoutRevisionNumber := timeoutHeight.GetRevisionNumber()
118
+ timeoutRevisionHeight := timeoutHeight.GetRevisionHeight()
119
+ clientTimeoutHeight := clienttypes.NewHeight(timeoutRevisionNumber, timeoutRevisionHeight)
120
+ timeoutTimestamp := packet.GetTimeoutTimestamp()
121
+ data := packet.GetData()
122
+
123
+ capName := host.ChannelCapabilityPath(sourcePort, sourceChannel)
105
124
  chanCap, ok := k.GetCapability(ctx, capName)
106
125
  if !ok {
107
- return sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
126
+ return 0, sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
108
127
  }
109
- return k.channelKeeper.SendPacket(ctx, chanCap, packet)
110
- }
111
-
112
- var _ ibcexported.Acknowledgement = (*rawAcknowledgement)(nil)
113
-
114
- type rawAcknowledgement struct {
115
- data []byte
116
- }
117
-
118
- func (r rawAcknowledgement) Acknowledgement() []byte {
119
- return r.data
120
- }
121
-
122
- func (r rawAcknowledgement) Success() bool {
123
- return true
128
+ return k.SendPacket(ctx, chanCap, sourcePort, sourceChannel, clientTimeoutHeight, timeoutTimestamp, data)
124
129
  }
125
130
 
126
- // WriteAcknowledgement defines a wrapper function for the channel Keeper's function
131
+ // SendPacket defines a wrapper function for the channel Keeper's function
127
132
  // in order to expose it to the vibc IBC handler.
128
- func (k Keeper) WriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, acknowledgement []byte) error {
133
+ func (k Keeper) SendPacket(
134
+ ctx sdk.Context,
135
+ chanCap *capability.Capability,
136
+ sourcePort string,
137
+ sourceChannel string,
138
+ timeoutHeight clienttypes.Height,
139
+ timeoutTimestamp uint64,
140
+ data []byte,
141
+ ) (uint64, error) {
142
+ return k.channelKeeper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
143
+ }
144
+
145
+ // ReceiveWriteAcknowledgement wraps the keeper's WriteAcknowledgment function.
146
+ func (k Keeper) ReceiveWriteAcknowledgement(ctx sdk.Context, packet ibcexported.PacketI, ack ibcexported.Acknowledgement) error {
129
147
  portID := packet.GetDestPort()
130
148
  channelID := packet.GetDestChannel()
131
149
  capName := host.ChannelCapabilityPath(portID, channelID)
132
150
  chanCap, ok := k.GetCapability(ctx, capName)
133
151
  if !ok {
134
- return sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
135
- }
136
- ack := rawAcknowledgement{
137
- data: acknowledgement,
152
+ return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
138
153
  }
154
+ return k.WriteAcknowledgement(ctx, chanCap, packet, ack)
155
+ }
156
+
157
+ // WriteAcknowledgement defines a wrapper function for the channel Keeper's function
158
+ // in order to expose it to the vibc IBC handler.
159
+ func (k Keeper) WriteAcknowledgement(ctx sdk.Context, chanCap *capability.Capability, packet ibcexported.PacketI, ack ibcexported.Acknowledgement) error {
139
160
  return k.channelKeeper.WriteAcknowledgement(ctx, chanCap, packet, ack)
140
161
  }
141
162
 
142
- // ChanCloseInit defines a wrapper function for the channel Keeper's function
163
+ // ReceiveWriteOpenTryChannel wraps the keeper's WriteOpenTryChannel function.
164
+ func (k Keeper) ReceiveWriteOpenTryChannel(ctx sdk.Context, packet ibcexported.PacketI, order channeltypes.Order, connectionHops []string, version string) error {
165
+ portID := packet.GetDestPort()
166
+ channelID := packet.GetDestChannel()
167
+ counterparty := channeltypes.NewCounterparty(packet.GetSourcePort(), packet.GetSourceChannel())
168
+ k.WriteOpenTryChannel(ctx, portID, channelID, order, connectionHops, counterparty, version)
169
+ return nil
170
+ }
171
+
172
+ // WriteOpenTryChannel is a wrapper function for the channel Keeper's function
173
+ func (k Keeper) WriteOpenTryChannel(ctx sdk.Context, portID, channelID string, order channeltypes.Order,
174
+ connectionHops []string, counterparty channeltypes.Counterparty, version string) {
175
+ k.channelKeeper.WriteOpenTryChannel(ctx, portID, channelID, order, connectionHops, counterparty, version)
176
+ }
177
+
178
+ // ReceiveChanCloseInit is a wrapper function for the channel Keeper's function
143
179
  // in order to expose it to the vibc IBC handler.
144
- func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
180
+ func (k Keeper) ReceiveChanCloseInit(ctx sdk.Context, portID, channelID string) error {
145
181
  capName := host.ChannelCapabilityPath(portID, channelID)
146
182
  chanCap, ok := k.GetCapability(ctx, capName)
147
183
  if !ok {
148
- return sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
184
+ return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
149
185
  }
150
186
  err := k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
151
187
  if err != nil {
@@ -154,36 +190,38 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
154
190
  return nil
155
191
  }
156
192
 
157
- // BindPort defines a wrapper function for the port Keeper's function in
158
- // order to expose it to the vibc IBC handler.
159
- func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
160
- _, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
193
+ // ReceiveBindPort is a wrapper function for the port Keeper's function in order
194
+ // to expose it to the vibc IBC handler.
195
+ func (k Keeper) ReceiveBindPort(ctx sdk.Context, portID string) error {
196
+ portPath := host.PortPath(portID)
197
+ _, ok := k.GetCapability(ctx, portPath)
161
198
  if ok {
162
199
  return fmt.Errorf("port %s is already bound", portID)
163
200
  }
164
201
  cap := k.portKeeper.BindPort(ctx, portID)
165
- return k.ClaimCapability(ctx, cap, host.PortPath(portID))
202
+ return k.ClaimCapability(ctx, cap, portPath)
166
203
  }
167
204
 
168
- // TimeoutExecuted defines a wrapper function for the channel Keeper's function
169
- // in order to expose it to the vibc IBC handler.
170
- func (k Keeper) TimeoutExecuted(ctx sdk.Context, packet ibcexported.PacketI) error {
205
+ // ReceiveTimeoutExecuted is a wrapper function for the channel Keeper's
206
+ // function in order to expose it to the vibc IBC handler.
207
+ func (k Keeper) ReceiveTimeoutExecuted(ctx sdk.Context, packet ibcexported.PacketI) error {
171
208
  portID := packet.GetSourcePort()
172
209
  channelID := packet.GetSourceChannel()
173
210
  capName := host.ChannelCapabilityPath(portID, channelID)
174
211
  chanCap, ok := k.GetCapability(ctx, capName)
175
212
  if !ok {
176
- return sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
213
+ return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
177
214
  }
178
215
  return k.channelKeeper.TimeoutExecuted(ctx, chanCap, packet)
179
216
  }
180
217
 
181
218
  // ClaimCapability allows the vibc module to claim a capability that IBC module
182
- // passes to it
219
+ // passes to it.
183
220
  func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capability.Capability, name string) error {
184
221
  return k.scopedKeeper.ClaimCapability(ctx, cap, name)
185
222
  }
186
223
 
224
+ // GetCapability allows the vibc module to retrieve a capability.
187
225
  func (k Keeper) GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool) {
188
226
  return k.scopedKeeper.GetCapability(ctx, name)
189
227
  }
@@ -0,0 +1,101 @@
1
+ package keeper
2
+
3
+ import (
4
+ sdk "github.com/cosmos/cosmos-sdk/types"
5
+
6
+ clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
7
+ channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
8
+ ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
9
+
10
+ "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
11
+ "github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
12
+ )
13
+
14
+ func reifyPacket(packet ibcexported.PacketI) channeltypes.Packet {
15
+ height := packet.GetTimeoutHeight()
16
+ ctHeight := clienttypes.Height{
17
+ RevisionHeight: height.GetRevisionHeight(),
18
+ RevisionNumber: height.GetRevisionNumber(),
19
+ }
20
+ return channeltypes.Packet{
21
+ Sequence: packet.GetSequence(),
22
+ SourcePort: packet.GetSourcePort(),
23
+ SourceChannel: packet.GetSourceChannel(),
24
+ DestinationPort: packet.GetDestPort(),
25
+ DestinationChannel: packet.GetDestChannel(),
26
+ Data: packet.GetData(),
27
+ TimeoutHeight: ctHeight,
28
+ TimeoutTimestamp: packet.GetTimeoutTimestamp(),
29
+ }
30
+ }
31
+
32
+ type WriteAcknowledgementEvent struct {
33
+ *vm.ActionHeader `actionType:"IBC_EVENT"`
34
+ Event string `json:"event" default:"writeAcknowledgement"`
35
+ Target string `json:"target"`
36
+ Packet channeltypes.Packet `json:"packet"`
37
+ Acknowledgement []byte `json:"acknowledgement"`
38
+ Relayer sdk.AccAddress `json:"relayer"`
39
+ }
40
+
41
+ func (k Keeper) TriggerWriteAcknowledgement(
42
+ ctx sdk.Context,
43
+ target string,
44
+ packet ibcexported.PacketI,
45
+ acknowledgement ibcexported.Acknowledgement,
46
+ ) error {
47
+ event := WriteAcknowledgementEvent{
48
+ Target: target,
49
+ Packet: reifyPacket(packet),
50
+ Acknowledgement: acknowledgement.Acknowledgement(),
51
+ }
52
+
53
+ err := k.PushAction(ctx, event)
54
+ if err != nil {
55
+ return err
56
+ }
57
+
58
+ return nil
59
+ }
60
+
61
+ func (k Keeper) TriggerOnAcknowledgementPacket(
62
+ ctx sdk.Context,
63
+ target string,
64
+ packet ibcexported.PacketI,
65
+ acknowledgement []byte,
66
+ relayer sdk.AccAddress,
67
+ ) error {
68
+ event := types.AcknowledgementPacketEvent{
69
+ Target: target,
70
+ Packet: reifyPacket(packet),
71
+ Acknowledgement: acknowledgement,
72
+ Relayer: relayer,
73
+ }
74
+
75
+ err := k.PushAction(ctx, event)
76
+ if err != nil {
77
+ return err
78
+ }
79
+
80
+ return nil
81
+ }
82
+
83
+ func (k Keeper) TriggerOnTimeoutPacket(
84
+ ctx sdk.Context,
85
+ target string,
86
+ packet ibcexported.PacketI,
87
+ relayer sdk.AccAddress,
88
+ ) error {
89
+ event := types.TimeoutPacketEvent{
90
+ Target: target,
91
+ Packet: reifyPacket(packet),
92
+ Relayer: relayer,
93
+ }
94
+
95
+ err := k.PushAction(ctx, event)
96
+ if err != nil {
97
+ return err
98
+ }
99
+
100
+ return nil
101
+ }
package/x/vibc/module.go CHANGED
@@ -3,7 +3,6 @@ package vibc
3
3
  import (
4
4
  "encoding/json"
5
5
 
6
- "github.com/gorilla/mux"
7
6
  "github.com/grpc-ecosystem/grpc-gateway/runtime"
8
7
  "github.com/spf13/cobra"
9
8
 
@@ -51,10 +50,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
51
50
  return nil
52
51
  }
53
52
 
54
- // Register rest routes
55
- func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {
56
- }
57
-
58
53
  func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {
59
54
  }
60
55
 
@@ -70,14 +65,16 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
70
65
 
71
66
  type AppModule struct {
72
67
  AppModuleBasic
73
- keeper Keeper
68
+ keeper Keeper
69
+ bankKeeper types.BankKeeper
74
70
  }
75
71
 
76
72
  // NewAppModule creates a new AppModule Object
77
- func NewAppModule(k Keeper) AppModule {
73
+ func NewAppModule(k Keeper, bankKeeper types.BankKeeper) AppModule {
78
74
  am := AppModule{
79
75
  AppModuleBasic: AppModuleBasic{},
80
76
  keeper: k,
77
+ bankKeeper: bankKeeper,
81
78
  }
82
79
  return am
83
80
  }
@@ -104,7 +101,7 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
104
101
 
105
102
  // Route implements the AppModule interface
106
103
  func (am AppModule) Route() sdk.Route {
107
- return sdk.NewRoute(RouterKey, NewHandler(am.keeper))
104
+ return sdk.NewRoute(RouterKey, NewHandler(am.keeper, am.bankKeeper))
108
105
  }
109
106
 
110
107
  // QuerierRoute implements the AppModule interface
@@ -3,21 +3,36 @@ package types
3
3
  import (
4
4
  sdk "github.com/cosmos/cosmos-sdk/types"
5
5
  capability "github.com/cosmos/cosmos-sdk/x/capability/types"
6
- connection "github.com/cosmos/ibc-go/v4/modules/core/03-connection/types"
7
- channel "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types"
8
- ibcexported "github.com/cosmos/ibc-go/v4/modules/core/exported"
6
+ clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
7
+ connection "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types"
8
+ channel "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
9
+ ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
9
10
  )
10
11
 
12
+ type BankKeeper interface {
13
+ GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
14
+ }
15
+
11
16
  // ChannelKeeper defines the expected IBC channel keeper
12
17
  type ChannelKeeper interface {
18
+ GetAppVersion(ctx sdk.Context, portID, channelID string) (string, bool)
13
19
  GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channel.Channel, found bool)
14
- GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
15
- SendPacket(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI) error
20
+ SendPacket(
21
+ ctx sdk.Context,
22
+ channelCap *capability.Capability,
23
+ sourcePort string,
24
+ sourceChannel string,
25
+ timeoutHeight clienttypes.Height,
26
+ timeoutTimestamp uint64,
27
+ data []byte,
28
+ ) (uint64, error)
16
29
  WriteAcknowledgement(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error
17
30
  ChanOpenInit(ctx sdk.Context, order channel.Order, connectionHops []string, portID string,
18
31
  portCap *capability.Capability, counterparty channel.Counterparty, version string) (string, *capability.Capability, error)
19
32
  WriteOpenInitChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
20
33
  connectionHops []string, counterparty channel.Counterparty, version string)
34
+ WriteOpenTryChannel(ctx sdk.Context, portID, channelID string, order channel.Order,
35
+ connectionHops []string, counterparty channel.Counterparty, version string)
21
36
  ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capability.Capability) error
22
37
  TimeoutExecuted(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI) error
23
38
  }
@@ -36,3 +51,9 @@ type ConnectionKeeper interface {
36
51
  type PortKeeper interface {
37
52
  BindPort(ctx sdk.Context, portID string) *capability.Capability
38
53
  }
54
+
55
+ // ScopedKeeper defines the expected scoped capability keeper
56
+ type ScopedKeeper interface {
57
+ ClaimCapability(ctx sdk.Context, cap *capability.Capability, name string) error
58
+ GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool)
59
+ }