@agoric/cosmos 0.35.0-u15.0 → 0.35.0-u16.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 -149
- package/MAINTAINERS.md +3 -0
- package/Makefile +36 -26
- package/ante/ante.go +6 -5
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +206 -147
- 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 +164 -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 +12 -7
- package/go.sum +13 -9
- package/package.json +8 -4
- 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 +16 -5
- 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/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/x/swingset/types/msgs.go
CHANGED
|
@@ -7,6 +7,7 @@ import (
|
|
|
7
7
|
"io"
|
|
8
8
|
"strings"
|
|
9
9
|
|
|
10
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
10
11
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
11
12
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
12
13
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
@@ -28,6 +29,25 @@ var (
|
|
|
28
29
|
_ vm.ControllerAdmissionMsg = &MsgWalletSpendAction{}
|
|
29
30
|
)
|
|
30
31
|
|
|
32
|
+
// Contextual information about the message source of an action on an inbound queue.
|
|
33
|
+
// This context should be unique per inboundQueueRecord.
|
|
34
|
+
type ActionContext struct {
|
|
35
|
+
// The block height in which the corresponding action was enqueued
|
|
36
|
+
BlockHeight int64 `json:"blockHeight"`
|
|
37
|
+
// The hash of the cosmos transaction that included the message
|
|
38
|
+
// If the action didn't result from a transaction message, a substitute value
|
|
39
|
+
// may be used. For example the VBANK_BALANCE_UPDATE actions use `x/vbank`.
|
|
40
|
+
TxHash string `json:"txHash"`
|
|
41
|
+
// The index of the message within the transaction. If the action didn't
|
|
42
|
+
// result from a cosmos transaction, a number should be chosen to make the
|
|
43
|
+
// actionContext unique. (for example a counter per block and source module).
|
|
44
|
+
MsgIdx int `json:"msgIdx"`
|
|
45
|
+
}
|
|
46
|
+
type InboundQueueRecord struct {
|
|
47
|
+
Action vm.Jsonable `json:"action"`
|
|
48
|
+
Context ActionContext `json:"context"`
|
|
49
|
+
}
|
|
50
|
+
|
|
31
51
|
const (
|
|
32
52
|
// bundleUncompressedSizeLimit is the (exclusive) limit on uncompressed bundle size.
|
|
33
53
|
// We must ensure there is an exclusive int64 limit in order to detect an underflow.
|
|
@@ -88,7 +108,7 @@ func NewMsgDeliverInbound(msgs *Messages, submitter sdk.AccAddress) *MsgDeliverI
|
|
|
88
108
|
func (msg MsgDeliverInbound) CheckAdmissibility(ctx sdk.Context, data interface{}) error {
|
|
89
109
|
keeper, ok := data.(SwingSetKeeper)
|
|
90
110
|
if !ok {
|
|
91
|
-
return
|
|
111
|
+
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
/*
|
|
@@ -120,14 +140,14 @@ func (msg MsgDeliverInbound) Type() string { return "eventualSend" }
|
|
|
120
140
|
// ValidateBasic runs stateless checks on the message
|
|
121
141
|
func (msg MsgDeliverInbound) ValidateBasic() error {
|
|
122
142
|
if msg.Submitter.Empty() {
|
|
123
|
-
return
|
|
143
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Submitter address cannot be empty")
|
|
124
144
|
}
|
|
125
145
|
if len(msg.Messages) != len(msg.Nums) {
|
|
126
|
-
return
|
|
146
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Messages and Nums must be the same length")
|
|
127
147
|
}
|
|
128
148
|
for _, m := range msg.Messages {
|
|
129
149
|
if len(m) == 0 {
|
|
130
|
-
return
|
|
150
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Messages cannot be empty")
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
153
|
return nil
|
|
@@ -161,7 +181,7 @@ func NewMsgWalletAction(owner sdk.AccAddress, action string) *MsgWalletAction {
|
|
|
161
181
|
func (msg MsgWalletAction) CheckAdmissibility(ctx sdk.Context, data interface{}) error {
|
|
162
182
|
keeper, ok := data.(SwingSetKeeper)
|
|
163
183
|
if !ok {
|
|
164
|
-
return
|
|
184
|
+
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
165
185
|
}
|
|
166
186
|
|
|
167
187
|
err := checkSmartWalletProvisioned(ctx, keeper, msg.Owner)
|
|
@@ -211,13 +231,13 @@ func (msg MsgWalletSpendAction) GetSignBytes() []byte {
|
|
|
211
231
|
// ValidateBasic runs stateless checks on the message
|
|
212
232
|
func (msg MsgWalletAction) ValidateBasic() error {
|
|
213
233
|
if msg.Owner.Empty() {
|
|
214
|
-
return
|
|
234
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Owner address cannot be empty")
|
|
215
235
|
}
|
|
216
236
|
if len(strings.TrimSpace(msg.Action)) == 0 {
|
|
217
|
-
return
|
|
237
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Action cannot be empty")
|
|
218
238
|
}
|
|
219
239
|
if !json.Valid([]byte(msg.Action)) {
|
|
220
|
-
return
|
|
240
|
+
return sdkioerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "Wallet action must be valid JSON")
|
|
221
241
|
}
|
|
222
242
|
return nil
|
|
223
243
|
}
|
|
@@ -233,7 +253,7 @@ func NewMsgWalletSpendAction(owner sdk.AccAddress, spendAction string) *MsgWalle
|
|
|
233
253
|
func (msg MsgWalletSpendAction) CheckAdmissibility(ctx sdk.Context, data interface{}) error {
|
|
234
254
|
keeper, ok := data.(SwingSetKeeper)
|
|
235
255
|
if !ok {
|
|
236
|
-
return
|
|
256
|
+
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
237
257
|
}
|
|
238
258
|
|
|
239
259
|
err := checkSmartWalletProvisioned(ctx, keeper, msg.Owner)
|
|
@@ -253,7 +273,7 @@ func (msg MsgWalletSpendAction) GetInboundMsgCount() int32 {
|
|
|
253
273
|
func (msg MsgWalletSpendAction) IsHighPriority(ctx sdk.Context, data interface{}) (bool, error) {
|
|
254
274
|
keeper, ok := data.(SwingSetKeeper)
|
|
255
275
|
if !ok {
|
|
256
|
-
return false,
|
|
276
|
+
return false, sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
257
277
|
}
|
|
258
278
|
|
|
259
279
|
return keeper.IsHighPriorityAddress(ctx, msg.Owner)
|
|
@@ -266,13 +286,13 @@ func (msg MsgWalletSpendAction) GetSigners() []sdk.AccAddress {
|
|
|
266
286
|
// ValidateBasic runs stateless checks on the message
|
|
267
287
|
func (msg MsgWalletSpendAction) ValidateBasic() error {
|
|
268
288
|
if msg.Owner.Empty() {
|
|
269
|
-
return
|
|
289
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Owner address cannot be empty")
|
|
270
290
|
}
|
|
271
291
|
if len(strings.TrimSpace(msg.SpendAction)) == 0 {
|
|
272
|
-
return
|
|
292
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Spend action cannot be empty")
|
|
273
293
|
}
|
|
274
294
|
if !json.Valid([]byte(msg.SpendAction)) {
|
|
275
|
-
return
|
|
295
|
+
return sdkioerrors.Wrap(sdkerrors.ErrJSONUnmarshal, "Wallet spend action must be valid JSON")
|
|
276
296
|
}
|
|
277
297
|
return nil
|
|
278
298
|
}
|
|
@@ -295,13 +315,13 @@ func (msg MsgProvision) Type() string { return "provision" }
|
|
|
295
315
|
// ValidateBasic runs stateless checks on the message
|
|
296
316
|
func (msg MsgProvision) ValidateBasic() error {
|
|
297
317
|
if msg.Submitter.Empty() {
|
|
298
|
-
return
|
|
318
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Submitter address cannot be empty")
|
|
299
319
|
}
|
|
300
320
|
if msg.Address.Empty() {
|
|
301
|
-
return
|
|
321
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Peer address cannot be empty")
|
|
302
322
|
}
|
|
303
323
|
if len(msg.Nickname) == 0 {
|
|
304
|
-
return
|
|
324
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Nickname cannot be empty")
|
|
305
325
|
}
|
|
306
326
|
return nil
|
|
307
327
|
}
|
|
@@ -351,7 +371,7 @@ func NewMsgInstallBundle(bundleJson string, submitter sdk.AccAddress) *MsgInstal
|
|
|
351
371
|
func (msg MsgInstallBundle) CheckAdmissibility(ctx sdk.Context, data interface{}) error {
|
|
352
372
|
keeper, ok := data.(SwingSetKeeper)
|
|
353
373
|
if !ok {
|
|
354
|
-
return
|
|
374
|
+
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "data must be a SwingSetKeeper, not a %T", data)
|
|
355
375
|
}
|
|
356
376
|
return chargeAdmission(ctx, keeper, msg.Submitter, []string{msg.Bundle}, msg.ExpectedUncompressedSize())
|
|
357
377
|
}
|
|
@@ -375,23 +395,23 @@ func (msg MsgInstallBundle) Type() string { return "installBundle" }
|
|
|
375
395
|
// ValidateBasic runs stateless checks on the message
|
|
376
396
|
func (msg MsgInstallBundle) ValidateBasic() error {
|
|
377
397
|
if msg.Submitter.Empty() {
|
|
378
|
-
return
|
|
398
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidAddress, "Submitter address cannot be empty")
|
|
379
399
|
}
|
|
380
400
|
if len(msg.Bundle) == 0 && len(msg.CompressedBundle) == 0 {
|
|
381
|
-
return
|
|
401
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Bundle cannot be empty")
|
|
382
402
|
}
|
|
383
403
|
if len(msg.Bundle) != 0 && len(msg.CompressedBundle) != 0 {
|
|
384
|
-
return
|
|
404
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Cannot submit both a compressed and an uncompressed bundle at the same time")
|
|
385
405
|
}
|
|
386
406
|
if len(msg.Bundle) > 0 && msg.UncompressedSize != 0 {
|
|
387
|
-
return
|
|
407
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Uncompressed size cannot be set without a compressed bundle")
|
|
388
408
|
}
|
|
389
409
|
if len(msg.CompressedBundle) > 0 && !(msg.UncompressedSize > 0) {
|
|
390
|
-
return
|
|
410
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Uncompressed size must be positive")
|
|
391
411
|
}
|
|
392
412
|
if msg.UncompressedSize >= bundleUncompressedSizeLimit {
|
|
393
413
|
// must enforce a limit to avoid overflow when computing its successor in Uncompress()
|
|
394
|
-
return
|
|
414
|
+
return sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, "Uncompressed size out of range")
|
|
395
415
|
}
|
|
396
416
|
// We don't check the accuracy of the uncompressed size here, since it could comsume significant CPU.
|
|
397
417
|
return nil
|
|
@@ -454,7 +474,7 @@ func (msg *MsgInstallBundle) Uncompress() error {
|
|
|
454
474
|
return err
|
|
455
475
|
}
|
|
456
476
|
if n != msg.UncompressedSize {
|
|
457
|
-
return
|
|
477
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "Uncompressed size does not match expected value")
|
|
458
478
|
}
|
|
459
479
|
msg.Bundle = buf.String()
|
|
460
480
|
msg.CompressedBundle = []byte{}
|
|
@@ -5,6 +5,7 @@ import (
|
|
|
5
5
|
|
|
6
6
|
yaml "gopkg.in/yaml.v2"
|
|
7
7
|
|
|
8
|
+
sdkmath "cosmossdk.io/math"
|
|
8
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
10
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
10
11
|
)
|
|
@@ -18,7 +19,7 @@ var (
|
|
|
18
19
|
ParamStoreKeyQueueMax = []byte("queue_max")
|
|
19
20
|
)
|
|
20
21
|
|
|
21
|
-
func NewStringBeans(key string, beans
|
|
22
|
+
func NewStringBeans(key string, beans sdkmath.Uint) StringBeans {
|
|
22
23
|
return StringBeans{
|
|
23
24
|
Key: key,
|
|
24
25
|
Beans: beans,
|
|
@@ -4,6 +4,7 @@ import (
|
|
|
4
4
|
"encoding/json"
|
|
5
5
|
"strings"
|
|
6
6
|
|
|
7
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
7
8
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
8
9
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
|
9
10
|
)
|
|
@@ -50,11 +51,11 @@ func (cep *CoreEvalProposal) ValidateBasic() error {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
if len(cep.Evals) == 0 {
|
|
53
|
-
return
|
|
54
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "no core evals provided")
|
|
54
55
|
}
|
|
55
56
|
for i, eval := range cep.Evals {
|
|
56
57
|
if err := eval.ValidateBasic(); err != nil {
|
|
57
|
-
return
|
|
58
|
+
return sdkioerrors.Wrapf(err, "invalid core eval %d", i)
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -67,12 +68,12 @@ func (ce CoreEval) ValidateBasic() error {
|
|
|
67
68
|
var rm json.RawMessage
|
|
68
69
|
err := json.Unmarshal([]byte(ce.JsonPermits), &rm)
|
|
69
70
|
if err != nil {
|
|
70
|
-
return
|
|
71
|
+
return sdkioerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid permit.json: %s", err.Error())
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// Ensure jscode is not empty.
|
|
74
75
|
if len(strings.TrimSpace(ce.JsCode)) == 0 {
|
|
75
|
-
return
|
|
76
|
+
return sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "no code.js provided")
|
|
76
77
|
}
|
|
77
78
|
return nil
|
|
78
79
|
}
|
|
@@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
|
|
27
27
|
|
|
28
28
|
// CoreEvalProposal is a gov Content type for evaluating code in the SwingSet
|
|
29
29
|
// core.
|
|
30
|
-
// See `agoric-sdk
|
|
30
|
+
// See `bridgeCoreEval` in agoric-sdk packages/vats/src/core/chain-behaviors.js.
|
|
31
31
|
type CoreEvalProposal struct {
|
|
32
32
|
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
|
|
33
33
|
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
|
package/x/vbank/genesis.go
CHANGED
package/x/vbank/handler.go
CHANGED
|
@@ -3,6 +3,7 @@ package vbank
|
|
|
3
3
|
import (
|
|
4
4
|
"fmt"
|
|
5
5
|
|
|
6
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
6
7
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
7
8
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
8
9
|
)
|
|
@@ -13,7 +14,7 @@ func NewHandler(keeper Keeper) sdk.Handler {
|
|
|
13
14
|
switch msg := msg.(type) {
|
|
14
15
|
default:
|
|
15
16
|
errMsg := fmt.Sprintf("Unrecognized vbank Msg type: %T", msg)
|
|
16
|
-
return nil,
|
|
17
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -3,6 +3,7 @@ package keeper
|
|
|
3
3
|
import (
|
|
4
4
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
5
5
|
|
|
6
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
6
7
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
|
|
7
8
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
8
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
@@ -23,7 +24,7 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
|
|
|
23
24
|
return queryState(ctx, path[1:], req, k, legacyQuerierCdc)
|
|
24
25
|
|
|
25
26
|
default:
|
|
26
|
-
return nil,
|
|
27
|
+
return nil, sdkioerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown vbank query path")
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -33,7 +34,7 @@ func queryParams(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, leg
|
|
|
33
34
|
|
|
34
35
|
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params)
|
|
35
36
|
if err != nil {
|
|
36
|
-
return nil,
|
|
37
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
return res, nil
|
|
@@ -44,7 +45,7 @@ func queryState(ctx sdk.Context, _ []string, _ abci.RequestQuery, k Keeper, lega
|
|
|
44
45
|
|
|
45
46
|
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, state)
|
|
46
47
|
if err != nil {
|
|
47
|
-
return nil,
|
|
48
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
return res, nil
|
package/x/vbank/module.go
CHANGED
|
@@ -5,7 +5,6 @@ import (
|
|
|
5
5
|
"encoding/json"
|
|
6
6
|
stdlog "log"
|
|
7
7
|
|
|
8
|
-
"github.com/gorilla/mux"
|
|
9
8
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
10
9
|
"github.com/spf13/cobra"
|
|
11
10
|
|
|
@@ -60,10 +59,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
60
59
|
return ValidateGenesis(&data)
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
// Register rest routes
|
|
64
|
-
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
|
|
65
|
-
}
|
|
66
|
-
|
|
67
62
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
68
63
|
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
69
64
|
}
|
package/x/vbank/types/msgs.go
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
1
|
package types
|
|
2
2
|
|
|
3
3
|
const RouterKey = ModuleName // this was defined in your key.go file
|
|
4
|
-
|
|
5
|
-
type VbankSingleBalanceUpdate struct {
|
|
6
|
-
Address string `json:"address"`
|
|
7
|
-
Denom string `json:"denom"`
|
|
8
|
-
Amount string `json:"amount"`
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type VbankBalanceUpdate struct {
|
|
12
|
-
Nonce uint64 `json:"nonce"`
|
|
13
|
-
Type string `json:"type"`
|
|
14
|
-
Updated []VbankSingleBalanceUpdate `json:"updated"`
|
|
15
|
-
}
|
package/x/vbank/vbank.go
CHANGED
|
@@ -34,14 +34,14 @@ func NewPortHandler(am AppModule, keeper Keeper) portHandler {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
type
|
|
37
|
+
type VbankSingleBalanceUpdate struct {
|
|
38
38
|
Address string `json:"address"`
|
|
39
39
|
Denom string `json:"denom"`
|
|
40
40
|
Amount string `json:"amount"`
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Make vbankManyBalanceUpdates sortable
|
|
44
|
-
type vbankManyBalanceUpdates []
|
|
44
|
+
type vbankManyBalanceUpdates []VbankSingleBalanceUpdate
|
|
45
45
|
|
|
46
46
|
var _ sort.Interface = vbankManyBalanceUpdates{}
|
|
47
47
|
|
|
@@ -67,10 +67,10 @@ func (vbu vbankManyBalanceUpdates) Swap(i int, j int) {
|
|
|
67
67
|
vbu[i], vbu[j] = vbu[j], vbu[i]
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
type
|
|
71
|
-
vm.ActionHeader `actionType:"VBANK_BALANCE_UPDATE"`
|
|
72
|
-
Nonce
|
|
73
|
-
Updated
|
|
70
|
+
type VbankBalanceUpdate struct {
|
|
71
|
+
*vm.ActionHeader `actionType:"VBANK_BALANCE_UPDATE"`
|
|
72
|
+
Nonce uint64 `json:"nonce"`
|
|
73
|
+
Updated vbankManyBalanceUpdates `json:"updated"`
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// getBalanceUpdate returns a bridge message containing the current bank balance
|
|
@@ -83,9 +83,9 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
nonce := keeper.GetNextSequence(ctx)
|
|
86
|
-
event :=
|
|
86
|
+
event := VbankBalanceUpdate{
|
|
87
87
|
Nonce: nonce,
|
|
88
|
-
Updated: make([]
|
|
88
|
+
Updated: make([]VbankSingleBalanceUpdate, 0, nentries),
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
// Note that Golang randomises the order of iteration, so we have to sort
|
|
@@ -99,7 +99,7 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
|
|
|
99
99
|
for _, coin := range coins {
|
|
100
100
|
// generate an update even when the current balance is zero
|
|
101
101
|
balance := keeper.GetBalance(ctx, account, coin.Denom)
|
|
102
|
-
update :=
|
|
102
|
+
update := VbankSingleBalanceUpdate{
|
|
103
103
|
Address: address,
|
|
104
104
|
Denom: coin.Denom,
|
|
105
105
|
Amount: balance.Amount.String(),
|
package/x/vbank/vbank_test.go
CHANGED
|
@@ -71,7 +71,7 @@ func newBalances(opts ...balancesOption) balances {
|
|
|
71
71
|
return bal
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
func validateBalanceUpdate(vbu
|
|
74
|
+
func validateBalanceUpdate(vbu VbankBalanceUpdate) error {
|
|
75
75
|
if vbu.Type != "VBANK_BALANCE_UPDATE" {
|
|
76
76
|
return fmt.Errorf("bad balance update type: %s", vbu.Type)
|
|
77
77
|
}
|
|
@@ -89,7 +89,7 @@ func decodeBalances(encoded []byte) (balances, uint64, error) {
|
|
|
89
89
|
if encoded == nil {
|
|
90
90
|
return nil, 0, nil
|
|
91
91
|
}
|
|
92
|
-
balanceUpdate :=
|
|
92
|
+
balanceUpdate := VbankBalanceUpdate{}
|
|
93
93
|
err := json.Unmarshal(encoded, &balanceUpdate)
|
|
94
94
|
if err != nil {
|
|
95
95
|
return nil, 0, err
|
package/x/vibc/alias.go
CHANGED
|
@@ -14,11 +14,14 @@ const (
|
|
|
14
14
|
var (
|
|
15
15
|
NewKeeper = keeper.NewKeeper
|
|
16
16
|
NewMsgSendPacket = types.NewMsgSendPacket
|
|
17
|
+
NewReceiver = types.NewReceiver
|
|
18
|
+
NewIBCModule = types.NewIBCModule
|
|
17
19
|
ModuleCdc = types.ModuleCdc
|
|
18
20
|
RegisterCodec = types.RegisterCodec
|
|
19
21
|
)
|
|
20
22
|
|
|
21
23
|
type (
|
|
22
24
|
Keeper = keeper.Keeper
|
|
25
|
+
ScopedKeeper = types.ScopedKeeper
|
|
23
26
|
MsgSendPacket = types.MsgSendPacket
|
|
24
27
|
)
|
package/x/vibc/handler.go
CHANGED
|
@@ -3,42 +3,49 @@ package vibc
|
|
|
3
3
|
import (
|
|
4
4
|
"fmt"
|
|
5
5
|
|
|
6
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
6
7
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
8
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vibc/types"
|
|
7
9
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
10
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
9
11
|
)
|
|
10
12
|
|
|
11
13
|
// NewHandler returns a handler for "vibc" type messages.
|
|
12
|
-
func NewHandler(keeper Keeper) sdk.Handler {
|
|
14
|
+
func NewHandler(keeper Keeper, bankKeeper types.BankKeeper) sdk.Handler {
|
|
13
15
|
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
|
|
14
16
|
switch msg := msg.(type) {
|
|
15
17
|
case *MsgSendPacket:
|
|
16
|
-
return handleMsgSendPacket(ctx, keeper, msg)
|
|
18
|
+
return handleMsgSendPacket(ctx, keeper, bankKeeper, msg)
|
|
17
19
|
|
|
18
20
|
default:
|
|
19
21
|
errMsg := fmt.Sprintf("Unrecognized vibc Msg type: %T", msg)
|
|
20
|
-
return nil,
|
|
22
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
type sendPacketAction struct {
|
|
28
|
+
*vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
29
|
+
Event string `json:"event" default:"sendPacket"`
|
|
26
30
|
*MsgSendPacket
|
|
27
|
-
vm.ActionHeader `actionType:"IBC_EVENT"`
|
|
28
|
-
Event string `json:"event" default:"sendPacket"`
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
func handleMsgSendPacket(
|
|
33
|
+
func handleMsgSendPacket(
|
|
34
|
+
ctx sdk.Context,
|
|
35
|
+
keeper Keeper,
|
|
36
|
+
bankKeeper types.BankKeeper,
|
|
37
|
+
msg *MsgSendPacket,
|
|
38
|
+
) (*sdk.Result, error) {
|
|
32
39
|
onePass := sdk.NewInt64Coin("sendpacketpass", 1)
|
|
33
|
-
balance :=
|
|
40
|
+
balance := bankKeeper.GetBalance(ctx, msg.Sender, onePass.Denom)
|
|
34
41
|
if balance.IsLT(onePass) {
|
|
35
|
-
return nil,
|
|
42
|
+
return nil, sdkioerrors.Wrap(
|
|
36
43
|
sdkerrors.ErrInsufficientFee,
|
|
37
44
|
fmt.Sprintf("sender %s needs at least %s", msg.Sender, onePass.String()),
|
|
38
45
|
)
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
action :=
|
|
48
|
+
action := sendPacketAction{
|
|
42
49
|
MsgSendPacket: msg,
|
|
43
50
|
}
|
|
44
51
|
// fmt.Fprintf(os.Stderr, "Context is %+v\n", ctx)
|