@agoric/cosmos 0.34.1 → 0.34.2-calypso-dev-dabccdc.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 (193) hide show
  1. package/MAINTAINERS.md +3 -0
  2. package/Makefile +67 -41
  3. package/agoric/config.go +35 -0
  4. package/ante/ante.go +65 -0
  5. package/ante/expected_keepers.go +26 -0
  6. package/ante/inbound.go +137 -0
  7. package/ante/inbound_test.go +228 -0
  8. package/ante/vm_admission.go +65 -0
  9. package/app/app.go +396 -211
  10. package/app/export.go +13 -9
  11. package/app/sim_test.go +4 -4
  12. package/app/upgrade.go +215 -0
  13. package/binding.gyp.in +29 -4
  14. package/buf.work.yaml +4 -0
  15. package/cmd/agd/agvm.go +42 -0
  16. package/cmd/agd/find_binary.go +22 -7
  17. package/cmd/agd/main.go +133 -10
  18. package/cmd/libdaemon/main.go +67 -53
  19. package/cmd/libdaemon/main_test.go +37 -0
  20. package/daemon/cmd/genaccounts.go +22 -18
  21. package/daemon/cmd/root.go +253 -52
  22. package/daemon/cmd/root_test.go +190 -2
  23. package/daemon/cmd/testnet.go +17 -6
  24. package/daemon/main.go +6 -3
  25. package/e2e_test/Makefile +29 -0
  26. package/e2e_test/README.md +100 -0
  27. package/e2e_test/go.mod +217 -0
  28. package/e2e_test/go.sum +1323 -0
  29. package/e2e_test/ibc_conformance_test.go +56 -0
  30. package/e2e_test/pfm_test.go +613 -0
  31. package/e2e_test/util.go +271 -0
  32. package/git-revision.txt +1 -0
  33. package/go.mod +207 -0
  34. package/go.sum +1877 -0
  35. package/package.json +13 -21
  36. package/proto/agoric/swingset/genesis.proto +14 -0
  37. package/proto/agoric/swingset/swingset.proto +6 -3
  38. package/proto/agoric/vlocalchain/.clang-format +7 -0
  39. package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
  40. package/proto/agoric/vstorage/query.proto +53 -1
  41. package/proto/agoric/vtransfer/genesis.proto +18 -0
  42. package/scripts/protocgen.sh +16 -6
  43. package/third_party/proto/buf.yaml +1 -0
  44. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  45. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  46. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  47. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  48. package/third_party/proto/google/api/annotations.proto +1 -1
  49. package/third_party/proto/google/api/http.proto +181 -120
  50. package/third_party/proto/google/api/httpbody.proto +9 -6
  51. package/third_party/proto/google/protobuf/any.proto +1 -7
  52. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  53. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  54. package/tools/tools.go +11 -0
  55. package/types/events.go +41 -0
  56. package/types/kv_entry.go +114 -0
  57. package/types/kv_entry_helpers.go +276 -0
  58. package/types/kv_entry_helpers_test.go +237 -0
  59. package/types/kv_entry_test.go +143 -0
  60. package/upgradegaia.sh +75 -0
  61. package/vm/action.go +134 -0
  62. package/vm/action_test.go +149 -0
  63. package/vm/client.go +113 -0
  64. package/vm/client_test.go +182 -0
  65. package/vm/controller.go +49 -0
  66. package/vm/core_proposals.go +51 -0
  67. package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
  68. package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
  69. package/vm/proto_json.go +38 -0
  70. package/vm/proto_json_test.go +103 -0
  71. package/vm/server.go +124 -0
  72. package/x/swingset/abci.go +26 -37
  73. package/x/swingset/alias.go +9 -6
  74. package/x/swingset/client/cli/query.go +2 -2
  75. package/x/swingset/client/cli/tx.go +52 -33
  76. package/x/swingset/client/proposal_handler.go +2 -17
  77. package/x/swingset/genesis.go +163 -37
  78. package/x/swingset/handler.go +2 -1
  79. package/x/swingset/keeper/extension_snapshotter.go +309 -0
  80. package/x/swingset/keeper/extension_snapshotter_test.go +104 -0
  81. package/x/swingset/keeper/keeper.go +95 -48
  82. package/x/swingset/keeper/keeper_test.go +77 -0
  83. package/x/swingset/keeper/migrations.go +7 -2
  84. package/x/swingset/keeper/msg_server.go +71 -56
  85. package/x/swingset/keeper/proposal.go +15 -9
  86. package/x/swingset/keeper/querier.go +24 -15
  87. package/x/swingset/keeper/swing_store_exports_handler.go +872 -0
  88. package/x/swingset/keeper/swing_store_exports_handler_test.go +247 -0
  89. package/x/swingset/keeper/test_utils.go +16 -0
  90. package/x/swingset/module.go +33 -11
  91. package/x/swingset/proposal_handler.go +5 -4
  92. package/x/swingset/swingset.go +73 -0
  93. package/x/swingset/testing/queue.go +17 -0
  94. package/x/swingset/types/codec.go +2 -2
  95. package/x/swingset/types/default-params.go +23 -17
  96. package/x/swingset/types/expected_keepers.go +14 -2
  97. package/x/swingset/types/genesis.pb.go +361 -18
  98. package/x/swingset/types/msgs.go +87 -26
  99. package/x/swingset/types/msgs.pb.go +16 -16
  100. package/x/swingset/types/params.go +76 -1
  101. package/x/swingset/types/params_test.go +116 -0
  102. package/x/swingset/types/proposal.go +10 -9
  103. package/x/swingset/types/swingset.pb.go +83 -81
  104. package/x/swingset/types/types.go +30 -28
  105. package/x/vbank/genesis.go +0 -2
  106. package/x/vbank/handler.go +2 -1
  107. package/x/vbank/keeper/keeper.go +3 -2
  108. package/x/vbank/keeper/querier.go +9 -4
  109. package/x/vbank/keeper/rewards.go +1 -1
  110. package/x/vbank/module.go +0 -5
  111. package/x/vbank/types/msgs.go +0 -12
  112. package/x/vbank/vbank.go +34 -32
  113. package/x/vbank/vbank_test.go +20 -20
  114. package/x/vibc/alias.go +3 -0
  115. package/x/vibc/handler.go +17 -15
  116. package/x/vibc/keeper/keeper.go +113 -89
  117. package/x/vibc/keeper/triggers.go +101 -0
  118. package/x/vibc/module.go +5 -8
  119. package/x/vibc/types/expected_keepers.go +28 -6
  120. package/x/vibc/types/ibc_module.go +336 -0
  121. package/x/vibc/types/msgs.go +1 -1
  122. package/x/vibc/types/msgs.pb.go +1 -1
  123. package/x/vibc/types/receiver.go +170 -0
  124. package/x/vlocalchain/alias.go +19 -0
  125. package/x/vlocalchain/handler.go +21 -0
  126. package/x/vlocalchain/keeper/keeper.go +279 -0
  127. package/x/vlocalchain/keeper/keeper_test.go +97 -0
  128. package/x/vlocalchain/types/codec.go +34 -0
  129. package/x/vlocalchain/types/key.go +27 -0
  130. package/x/vlocalchain/types/msgs.go +16 -0
  131. package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
  132. package/x/vlocalchain/vlocalchain.go +114 -0
  133. package/x/vlocalchain/vlocalchain_test.go +434 -0
  134. package/x/vstorage/README.md +138 -0
  135. package/x/vstorage/capdata/capdata.go +298 -0
  136. package/x/vstorage/capdata/capdata_test.go +352 -0
  137. package/x/vstorage/client/cli/query.go +51 -4
  138. package/x/vstorage/genesis.go +0 -3
  139. package/x/vstorage/handler.go +2 -1
  140. package/x/vstorage/keeper/grpc_query.go +220 -0
  141. package/x/vstorage/keeper/keeper.go +75 -57
  142. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  143. package/x/vstorage/keeper/keeper_test.go +40 -62
  144. package/x/vstorage/keeper/querier.go +39 -14
  145. package/x/vstorage/keeper/querier_test.go +113 -0
  146. package/x/vstorage/module.go +0 -5
  147. package/x/vstorage/testing/queue.go +27 -0
  148. package/x/vstorage/types/path_keys.go +22 -10
  149. package/x/vstorage/types/path_keys_test.go +84 -18
  150. package/x/vstorage/types/query.pb.go +646 -36
  151. package/x/vstorage/types/query.pb.gw.go +119 -0
  152. package/x/vstorage/types/types.go +0 -66
  153. package/x/vstorage/vstorage.go +33 -35
  154. package/x/vstorage/vstorage_test.go +19 -19
  155. package/x/vtransfer/alias.go +13 -0
  156. package/x/vtransfer/genesis.go +39 -0
  157. package/x/vtransfer/genesis_test.go +12 -0
  158. package/x/vtransfer/handler.go +20 -0
  159. package/x/vtransfer/ibc_middleware.go +186 -0
  160. package/x/vtransfer/ibc_middleware_test.go +448 -0
  161. package/x/vtransfer/keeper/keeper.go +281 -0
  162. package/x/vtransfer/module.go +124 -0
  163. package/x/vtransfer/types/expected_keepers.go +38 -0
  164. package/x/vtransfer/types/genesis.pb.go +327 -0
  165. package/x/vtransfer/types/key.go +9 -0
  166. package/x/vtransfer/types/msgs.go +9 -0
  167. package/app/const.go +0 -6
  168. package/cmd/helper/main.go +0 -21
  169. package/proto/agoric/lien/genesis.proto +0 -25
  170. package/proto/agoric/lien/lien.proto +0 -25
  171. package/x/lien/alias.go +0 -17
  172. package/x/lien/genesis.go +0 -58
  173. package/x/lien/genesis_test.go +0 -101
  174. package/x/lien/keeper/account.go +0 -285
  175. package/x/lien/keeper/keeper.go +0 -254
  176. package/x/lien/keeper/keeper_test.go +0 -623
  177. package/x/lien/lien.go +0 -203
  178. package/x/lien/lien_test.go +0 -529
  179. package/x/lien/module.go +0 -115
  180. package/x/lien/spec/01_concepts.md +0 -146
  181. package/x/lien/spec/02_messages.md +0 -96
  182. package/x/lien/types/accountkeeper.go +0 -81
  183. package/x/lien/types/accountstate.go +0 -27
  184. package/x/lien/types/expected_keepers.go +0 -18
  185. package/x/lien/types/genesis.pb.go +0 -567
  186. package/x/lien/types/key.go +0 -25
  187. package/x/lien/types/lien.pb.go +0 -403
  188. package/x/swingset/keeper/snapshotter.go +0 -491
  189. package/x/swingset/keeper/snapshotter_test.go +0 -185
  190. package/x/swingset/legacy/v32/params.go +0 -37
  191. package/x/swingset/legacy/v32/params_test.go +0 -133
  192. package/x/vibc/ibc.go +0 -442
  193. /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/v3/modules/core/04-channel/types"
13
- porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
14
- host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
15
- ibcexported "github.com/cosmos/ibc-go/v3/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,
@@ -92,112 +105,123 @@ func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connecti
92
105
  return err
93
106
  }
94
107
 
95
- // We need to emit a channel event to notify the relayer.
96
- ctx.EventManager().EmitEvents(sdk.Events{
97
- sdk.NewEvent(
98
- sdk.EventTypeMessage,
99
- sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory),
100
- ),
101
- })
108
+ k.channelKeeper.WriteOpenInitChannel(ctx, portID, channelID, order, connectionHops, counterparty, version)
102
109
  return nil
103
110
  }
104
111
 
105
- // SendPacket defines a wrapper function for the channel Keeper's function
106
- // in order to expose it to the vibc IBC handler.
107
- func (k Keeper) SendPacket(ctx sdk.Context, packet ibcexported.PacketI) error {
108
- portID := packet.GetSourcePort()
109
- channelID := packet.GetSourceChannel()
110
- 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)
111
124
  chanCap, ok := k.GetCapability(ctx, capName)
112
125
  if !ok {
113
- 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)
114
127
  }
115
- return k.channelKeeper.SendPacket(ctx, chanCap, packet)
116
- }
117
-
118
- var _ ibcexported.Acknowledgement = (*rawAcknowledgement)(nil)
119
-
120
- type rawAcknowledgement struct {
121
- data []byte
122
- }
123
-
124
- func (r rawAcknowledgement) Acknowledgement() []byte {
125
- return r.data
128
+ return k.SendPacket(ctx, chanCap, sourcePort, sourceChannel, clientTimeoutHeight, timeoutTimestamp, data)
126
129
  }
127
130
 
128
- func (r rawAcknowledgement) Success() bool {
129
- return true
130
- }
131
-
132
- // WriteAcknowledgement defines a wrapper function for the channel Keeper's function
131
+ // SendPacket defines a wrapper function for the channel Keeper's function
133
132
  // in order to expose it to the vibc IBC handler.
134
- 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 {
135
147
  portID := packet.GetDestPort()
136
148
  channelID := packet.GetDestChannel()
137
149
  capName := host.ChannelCapabilityPath(portID, channelID)
138
150
  chanCap, ok := k.GetCapability(ctx, capName)
139
151
  if !ok {
140
- return sdkerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
141
- }
142
- ack := rawAcknowledgement{
143
- data: acknowledgement,
152
+ return sdkioerrors.Wrapf(channeltypes.ErrChannelCapabilityNotFound, "could not retrieve channel capability at: %s", capName)
144
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 {
145
160
  return k.channelKeeper.WriteAcknowledgement(ctx, chanCap, packet, ack)
146
161
  }
147
162
 
148
- // 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
149
179
  // in order to expose it to the vibc IBC handler.
150
- func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
180
+ func (k Keeper) ReceiveChanCloseInit(ctx sdk.Context, portID, channelID string) error {
151
181
  capName := host.ChannelCapabilityPath(portID, channelID)
152
182
  chanCap, ok := k.GetCapability(ctx, capName)
153
183
  if !ok {
154
- 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)
155
185
  }
156
186
  err := k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap)
157
187
  if err != nil {
158
188
  return err
159
189
  }
160
-
161
- // We need to emit a channel event to notify the relayer.
162
- ctx.EventManager().EmitEvents(sdk.Events{
163
- sdk.NewEvent(
164
- sdk.EventTypeMessage,
165
- sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory),
166
- ),
167
- })
168
190
  return nil
169
191
  }
170
192
 
171
- // BindPort defines a wrapper function for the port Keeper's function in
172
- // order to expose it to the vibc IBC handler.
173
- func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
174
- _, 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)
175
198
  if ok {
176
199
  return fmt.Errorf("port %s is already bound", portID)
177
200
  }
178
201
  cap := k.portKeeper.BindPort(ctx, portID)
179
- return k.ClaimCapability(ctx, cap, host.PortPath(portID))
202
+ return k.ClaimCapability(ctx, cap, portPath)
180
203
  }
181
204
 
182
- // TimeoutExecuted defines a wrapper function for the channel Keeper's function
183
- // in order to expose it to the vibc IBC handler.
184
- 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 {
185
208
  portID := packet.GetSourcePort()
186
209
  channelID := packet.GetSourceChannel()
187
210
  capName := host.ChannelCapabilityPath(portID, channelID)
188
211
  chanCap, ok := k.GetCapability(ctx, capName)
189
212
  if !ok {
190
- 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)
191
214
  }
192
215
  return k.channelKeeper.TimeoutExecuted(ctx, chanCap, packet)
193
216
  }
194
217
 
195
218
  // ClaimCapability allows the vibc module to claim a capability that IBC module
196
- // passes to it
219
+ // passes to it.
197
220
  func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capability.Capability, name string) error {
198
221
  return k.scopedKeeper.ClaimCapability(ctx, cap, name)
199
222
  }
200
223
 
224
+ // GetCapability allows the vibc module to retrieve a capability.
201
225
  func (k Keeper) GetCapability(ctx sdk.Context, name string) (*capability.Capability, bool) {
202
226
  return k.scopedKeeper.GetCapability(ctx, name)
203
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,20 +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/v3/modules/core/03-connection/types"
7
- channel "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
8
- ibcexported "github.com/cosmos/ibc-go/v3/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,
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)
20
36
  ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capability.Capability) error
21
37
  TimeoutExecuted(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI) error
22
38
  }
@@ -35,3 +51,9 @@ type ConnectionKeeper interface {
35
51
  type PortKeeper interface {
36
52
  BindPort(ctx sdk.Context, portID string) *capability.Capability
37
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
+ }