@agoric/cosmos 0.35.0-u13.0 → 0.35.0-u14.1

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 (81) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/Makefile +25 -12
  3. package/ante/ante.go +5 -6
  4. package/app/app.go +142 -96
  5. package/app/export.go +13 -6
  6. package/cmd/agd/main.go +5 -3
  7. package/cmd/libdaemon/main.go +5 -2
  8. package/daemon/cmd/genaccounts.go +13 -9
  9. package/daemon/cmd/root.go +38 -15
  10. package/daemon/cmd/root_test.go +1 -1
  11. package/daemon/cmd/testnet.go +17 -6
  12. package/daemon/main.go +3 -2
  13. package/git-revision.txt +1 -1
  14. package/go.mod +95 -64
  15. package/go.sum +592 -243
  16. package/package.json +3 -3
  17. package/proto/agoric/vstorage/query.proto +53 -1
  18. package/scripts/protocgen.sh +12 -1
  19. package/third_party/proto/buf.yaml +1 -0
  20. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  21. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  22. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  23. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  24. package/third_party/proto/google/api/annotations.proto +1 -1
  25. package/third_party/proto/google/api/http.proto +181 -120
  26. package/third_party/proto/google/api/httpbody.proto +9 -6
  27. package/third_party/proto/google/protobuf/any.proto +1 -7
  28. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  29. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  30. package/upgradegaia.sh +13 -4
  31. package/vm/action.go +133 -0
  32. package/vm/action_test.go +129 -0
  33. package/vm/controller.go +9 -16
  34. package/vm/core_proposals.go +31 -0
  35. package/x/lien/keeper/account.go +3 -3
  36. package/x/lien/keeper/keeper.go +5 -4
  37. package/x/lien/keeper/keeper_test.go +9 -9
  38. package/x/lien/lien.go +6 -4
  39. package/x/lien/lien_test.go +20 -16
  40. package/x/swingset/abci.go +25 -33
  41. package/x/swingset/client/cli/query.go +2 -2
  42. package/x/swingset/client/cli/tx.go +48 -33
  43. package/x/swingset/client/proposal_handler.go +2 -17
  44. package/x/swingset/keeper/keeper.go +30 -15
  45. package/x/swingset/keeper/keeper_test.go +1 -1
  46. package/x/swingset/keeper/msg_server.go +21 -51
  47. package/x/swingset/keeper/proposal.go +14 -8
  48. package/x/swingset/keeper/querier.go +14 -6
  49. package/x/swingset/keeper/swing_store_exports_handler.go +5 -1
  50. package/x/swingset/proposal_handler.go +3 -3
  51. package/x/swingset/swingset.go +4 -2
  52. package/x/swingset/types/codec.go +2 -2
  53. package/x/swingset/types/msgs.pb.go +16 -16
  54. package/x/swingset/types/proposal.go +5 -5
  55. package/x/swingset/types/types.go +30 -28
  56. package/x/vbank/keeper/keeper.go +3 -2
  57. package/x/vbank/keeper/querier.go +6 -2
  58. package/x/vbank/keeper/rewards.go +1 -1
  59. package/x/vbank/vbank.go +19 -17
  60. package/x/vbank/vbank_test.go +18 -18
  61. package/x/vibc/handler.go +3 -8
  62. package/x/vibc/ibc.go +66 -113
  63. package/x/vibc/keeper/keeper.go +19 -18
  64. package/x/vibc/types/expected_keepers.go +13 -5
  65. package/x/vibc/types/msgs.go +1 -1
  66. package/x/vibc/types/msgs.pb.go +1 -1
  67. package/x/vstorage/README.md +138 -0
  68. package/x/vstorage/capdata/capdata.go +298 -0
  69. package/x/vstorage/capdata/capdata_test.go +352 -0
  70. package/x/vstorage/client/cli/query.go +51 -4
  71. package/x/vstorage/keeper/grpc_query.go +221 -0
  72. package/x/vstorage/keeper/keeper.go +3 -2
  73. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  74. package/x/vstorage/keeper/keeper_test.go +1 -1
  75. package/x/vstorage/keeper/querier.go +6 -2
  76. package/x/vstorage/types/query.pb.go +646 -36
  77. package/x/vstorage/types/query.pb.gw.go +119 -0
  78. package/x/vstorage/vstorage.go +16 -15
  79. package/x/vstorage/vstorage_test.go +5 -5
  80. package/ante/fee.go +0 -96
  81. /package/{src/index.cjs → index.cjs} +0 -0
@@ -24,17 +24,27 @@ const (
24
24
  // NewQuerier is the module level router for state queries
25
25
  func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
26
26
  return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) {
27
- switch path[0] {
27
+ var queryType string
28
+ if len(path) > 0 {
29
+ queryType = path[0]
30
+ }
31
+ switch queryType {
28
32
  case QueryEgress:
33
+ if len(path) < 2 || path[1] == "" {
34
+ return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "missing egress address")
35
+ }
29
36
  return queryEgress(ctx, path[1], req, keeper, legacyQuerierCdc)
30
37
  case QueryMailbox:
31
- return queryMailbox(ctx, path[1:], req, keeper, legacyQuerierCdc)
38
+ if len(path) < 2 || path[1] == "" {
39
+ return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "missing mailbox peer")
40
+ }
41
+ return queryMailbox(ctx, path[1], req, keeper, legacyQuerierCdc)
32
42
  case LegacyQueryStorage:
33
43
  return legacyQueryStorage(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
34
44
  case LegacyQueryKeys:
35
45
  return legacyQueryKeys(ctx, strings.Join(path[1:], "/"), req, keeper, legacyQuerierCdc)
36
46
  default:
37
- return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown swingset query endpoint")
47
+ return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown swingset query path")
38
48
  }
39
49
  }
40
50
  }
@@ -60,9 +70,7 @@ func queryEgress(ctx sdk.Context, bech32 string, req abci.RequestQuery, keeper K
60
70
  }
61
71
 
62
72
  // nolint: unparam
63
- func queryMailbox(ctx sdk.Context, path []string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
64
- peer := path[0]
65
-
73
+ func queryMailbox(ctx sdk.Context, peer string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
66
74
  value := keeper.GetMailbox(ctx, peer)
67
75
 
68
76
  if value == "" {
@@ -751,11 +751,15 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
751
751
  }
752
752
  defer os.RemoveAll(exportDir)
753
753
 
754
+ exportsHandler.logger.Info("creating swing-store restore", "exportDir", exportDir, "height", blockHeight)
755
+
754
756
  err = WriteSwingStoreExportToDirectory(provider, exportDir)
755
757
  if err != nil {
756
758
  return err
757
759
  }
758
760
 
761
+ exportsHandler.logger.Info("restoring swing-store", "exportDir", exportDir, "height", blockHeight)
762
+
759
763
  action := &swingStoreRestoreExportAction{
760
764
  Type: swingStoreExportActionType,
761
765
  BlockHeight: blockHeight,
@@ -772,7 +776,7 @@ func (exportsHandler SwingStoreExportsHandler) RestoreExport(provider SwingStore
772
776
  return err
773
777
  }
774
778
 
775
- exportsHandler.logger.Info("restored swing-store export", "exportDir", exportDir, "height", blockHeight)
779
+ exportsHandler.logger.Info("restored swing-store", "exportDir", exportDir, "height", blockHeight)
776
780
 
777
781
  return nil
778
782
  }
@@ -3,15 +3,15 @@ package swingset
3
3
  import (
4
4
  sdk "github.com/cosmos/cosmos-sdk/types"
5
5
  sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
6
- govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
6
+ govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
7
7
 
8
8
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/keeper"
9
9
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
10
10
  )
11
11
 
12
12
  // NewSwingSetProposalHandler defines the SwingSet proposal handler
13
- func NewSwingSetProposalHandler(k keeper.Keeper) govtypes.Handler {
14
- return func(ctx sdk.Context, content govtypes.Content) error {
13
+ func NewSwingSetProposalHandler(k keeper.Keeper) govv1beta1.Handler {
14
+ return func(ctx sdk.Context, content govv1beta1.Content) error {
15
15
  switch c := content.(type) {
16
16
  case *types.CoreEvalProposal:
17
17
  return k.CoreEvalProposal(ctx, c)
@@ -1,6 +1,7 @@
1
1
  package swingset
2
2
 
3
3
  import (
4
+ "context"
4
5
  "encoding/json"
5
6
  "fmt"
6
7
  "io"
@@ -33,7 +34,8 @@ func NewPortHandler(k Keeper) vm.PortHandler {
33
34
  // Receive implements the vm.PortHandler method.
34
35
  // It receives and processes an inbound message, returning the
35
36
  // JSON-serialized response or an error.
36
- func (ph portHandler) Receive(ctx *vm.ControllerContext, str string) (string, error) {
37
+ func (ph portHandler) Receive(cctx context.Context, str string) (string, error) {
38
+ ctx := sdk.UnwrapSDKContext(cctx)
37
39
  var msg swingsetMessage
38
40
  err := json.Unmarshal([]byte(str), &msg)
39
41
  if err != nil {
@@ -42,7 +44,7 @@ func (ph portHandler) Receive(ctx *vm.ControllerContext, str string) (string, er
42
44
 
43
45
  switch msg.Method {
44
46
  case SwingStoreUpdateExportData:
45
- return ph.handleSwingStoreUpdateExportData(ctx.Context, msg.Args)
47
+ return ph.handleSwingStoreUpdateExportData(ctx, msg.Args)
46
48
 
47
49
  default:
48
50
  return "", fmt.Errorf("unrecognized swingset method %s", msg.Method)
@@ -6,7 +6,7 @@ import (
6
6
  cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
7
7
  sdk "github.com/cosmos/cosmos-sdk/types"
8
8
  "github.com/cosmos/cosmos-sdk/types/msgservice"
9
- govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
9
+ govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
10
10
  )
11
11
 
12
12
  var (
@@ -44,7 +44,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
44
44
  &MsgWalletSpendAction{},
45
45
  )
46
46
  registry.RegisterImplementations(
47
- (*govtypes.Content)(nil),
47
+ (*govv1beta1.Content)(nil),
48
48
  &CoreEvalProposal{},
49
49
  )
50
50
  msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
@@ -433,7 +433,7 @@ type MsgInstallBundle struct {
433
433
  Submitter github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,2,opt,name=submitter,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"submitter" yaml:"submitter"`
434
434
  // Either bundle or compressed_bundle will be set.
435
435
  // Default compression algorithm is gzip.
436
- CompressedBundle []byte `protobuf:"bytes,3,opt,name=compressed_bundle,json=compressedBundle,proto3" json:"compressedBundle" yaml:"bcompressedBndle"`
436
+ CompressedBundle []byte `protobuf:"bytes,3,opt,name=compressed_bundle,json=compressedBundle,proto3" json:"compressedBundle" yaml:"compressedBundle"`
437
437
  // Size in bytes of uncompression of compressed_bundle.
438
438
  UncompressedSize int64 `protobuf:"varint,4,opt,name=uncompressed_size,json=uncompressedSize,proto3" json:"uncompressedSize"`
439
439
  }
@@ -553,7 +553,7 @@ func init() {
553
553
  func init() { proto.RegisterFile("agoric/swingset/msgs.proto", fileDescriptor_788baa062b181a57) }
554
554
 
555
555
  var fileDescriptor_788baa062b181a57 = []byte{
556
- // 789 bytes of a gzipped FileDescriptorProto
556
+ // 788 bytes of a gzipped FileDescriptorProto
557
557
  0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcf, 0x6f, 0xe3, 0x44,
558
558
  0x14, 0x8e, 0xe3, 0x50, 0x36, 0xaf, 0xd9, 0x6d, 0x63, 0x95, 0xad, 0xd7, 0x0b, 0x99, 0xac, 0xa5,
559
559
  0x15, 0x01, 0xd4, 0x44, 0xb0, 0xb7, 0xed, 0x29, 0x16, 0x42, 0x5a, 0xa4, 0xa0, 0xc5, 0x2b, 0x84,
@@ -590,20 +590,20 @@ var fileDescriptor_788baa062b181a57 = []byte{
590
590
  0x01, 0x8d, 0x2d, 0xcf, 0x33, 0x66, 0xc1, 0xc4, 0xc3, 0xca, 0x0b, 0xd8, 0x1a, 0xf3, 0x7f, 0xf9,
591
591
  0xe9, 0x3c, 0x4d, 0x18, 0xca, 0x91, 0x94, 0xa1, 0x87, 0xc2, 0x9e, 0x88, 0x75, 0x33, 0x27, 0x96,
592
592
  0x57, 0x56, 0xbf, 0x87, 0x95, 0x29, 0xdf, 0x40, 0xdb, 0x26, 0x7e, 0x98, 0xc1, 0x78, 0x72, 0x9c,
593
- 0x3b, 0x96, 0x79, 0xe7, 0x41, 0xc2, 0xd0, 0x6e, 0x45, 0x1a, 0x85, 0xf7, 0xfd, 0xdc, 0xfb, 0x02,
594
- 0x25, 0x56, 0xb1, 0x26, 0x56, 0x86, 0xd0, 0x9e, 0x05, 0x0b, 0xf5, 0xa9, 0x7b, 0x89, 0xf9, 0x89,
595
- 0xc9, 0xc6, 0x5e, 0x56, 0x7d, 0x91, 0x7c, 0xe3, 0x5e, 0x62, 0x73, 0x0d, 0xd1, 0x35, 0x50, 0x57,
596
- 0xf7, 0xb6, 0xd8, 0xf8, 0x4f, 0xae, 0x65, 0x90, 0x47, 0xd4, 0x51, 0xbe, 0x85, 0x87, 0xcb, 0x9b,
597
- 0xff, 0xac, 0xbf, 0xf2, 0x1a, 0xe8, 0xaf, 0xd6, 0xd0, 0x3e, 0xb8, 0x55, 0x52, 0xb4, 0x51, 0x4e,
598
- 0xe0, 0xd1, 0xca, 0x8b, 0x42, 0xdf, 0x94, 0xbc, 0xac, 0xd1, 0x3e, 0xbc, 0x5d, 0x53, 0x76, 0x38,
599
- 0x82, 0xd6, 0xd2, 0xc3, 0xb4, 0xbb, 0x29, 0x77, 0x51, 0xa1, 0xf5, 0x6e, 0x53, 0x94, 0xb5, 0x5d,
600
- 0x68, 0xaf, 0x3f, 0xf9, 0x9e, 0xff, 0x73, 0xfa, 0x82, 0x4c, 0x3b, 0xf8, 0x4f, 0xb2, 0xb2, 0xd5,
601
- 0x97, 0xd0, 0xac, 0x1e, 0x50, 0xef, 0x6d, 0xca, 0x2d, 0x69, 0xed, 0xf9, 0xbf, 0xd2, 0x45, 0x49,
602
- 0xe3, 0xab, 0xdf, 0xe6, 0x1d, 0xe9, 0x6a, 0xde, 0x91, 0xae, 0xe7, 0x1d, 0xe9, 0xc7, 0x9b, 0x4e,
603
- 0xed, 0xea, 0xa6, 0x53, 0xfb, 0xfd, 0xa6, 0x53, 0x3b, 0x3a, 0x5c, 0x98, 0xf9, 0xa1, 0xf8, 0x20,
604
- 0x10, 0x15, 0xf9, 0xcc, 0x3b, 0xc4, 0xb3, 0x02, 0xa7, 0xb8, 0x0c, 0xdf, 0x57, 0xdf, 0x0a, 0xfc,
605
- 0x32, 0x8c, 0xb7, 0xf8, 0x67, 0xc0, 0x8b, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x99, 0x11, 0x18,
606
- 0xbe, 0x4b, 0x08, 0x00, 0x00,
593
+ 0x3b, 0x96, 0x79, 0xe7, 0x41, 0xc2, 0xd0, 0x6e, 0x45, 0x1a, 0x85, 0xf7, 0x7d, 0x61, 0x60, 0x95,
594
+ 0xd1, 0xcd, 0x35, 0xb1, 0x32, 0x84, 0xf6, 0x2c, 0x58, 0xa8, 0x4f, 0xdd, 0x4b, 0xcc, 0x4f, 0x4c,
595
+ 0x36, 0xf6, 0xb2, 0xea, 0x8b, 0xe4, 0x1b, 0xf7, 0x12, 0x9b, 0x6b, 0x88, 0xae, 0x81, 0xba, 0xba,
596
+ 0xb7, 0xc5, 0xc6, 0x7f, 0x72, 0x2d, 0x83, 0x3c, 0xa2, 0x8e, 0xf2, 0x2d, 0x3c, 0x5c, 0xde, 0xfc,
597
+ 0x67, 0xfd, 0x95, 0xd7, 0x40, 0x7f, 0xb5, 0x86, 0xf6, 0xc1, 0xad, 0x92, 0xa2, 0x8d, 0x72, 0x02,
598
+ 0x8f, 0x56, 0x5e, 0x14, 0xfa, 0xa6, 0xe4, 0x65, 0x8d, 0xf6, 0xe1, 0xed, 0x9a, 0xb2, 0xc3, 0x11,
599
+ 0xb4, 0x96, 0x1e, 0xa6, 0xdd, 0x4d, 0xb9, 0x8b, 0x0a, 0xad, 0x77, 0x9b, 0xa2, 0xac, 0xed, 0x42,
600
+ 0x7b, 0xfd, 0xc9, 0xf7, 0xfc, 0x9f, 0xd3, 0x17, 0x64, 0xda, 0xc1, 0x7f, 0x92, 0x95, 0xad, 0xbe,
601
+ 0x84, 0x66, 0xf5, 0x80, 0x7a, 0x6f, 0x53, 0x6e, 0x49, 0x6b, 0xcf, 0xff, 0x95, 0x2e, 0x4a, 0x1a,
602
+ 0x5f, 0xfd, 0x36, 0xef, 0x48, 0x57, 0xf3, 0x8e, 0x74, 0x3d, 0xef, 0x48, 0x3f, 0xde, 0x74, 0x6a,
603
+ 0x57, 0x37, 0x9d, 0xda, 0xef, 0x37, 0x9d, 0xda, 0xd1, 0xe1, 0xc2, 0xcc, 0x0f, 0xc5, 0x07, 0x81,
604
+ 0xa8, 0xc8, 0x67, 0xde, 0x21, 0x9e, 0x15, 0x38, 0xc5, 0x65, 0xf8, 0xbe, 0xfa, 0x56, 0xe0, 0x97,
605
+ 0x61, 0xbc, 0xc5, 0x3f, 0x03, 0x5e, 0xfc, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x51, 0x66, 0x1b, 0xd5,
606
+ 0x4b, 0x08, 0x00, 0x00,
607
607
  }
608
608
 
609
609
  // Reference imports to suppress errors if they are not otherwise used.
@@ -5,7 +5,7 @@ import (
5
5
  "strings"
6
6
 
7
7
  sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8
- govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
8
+ govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
9
9
  )
10
10
 
11
11
  const (
@@ -14,15 +14,15 @@ const (
14
14
  )
15
15
 
16
16
  var (
17
- _ govtypes.Content = &CoreEvalProposal{}
17
+ _ govv1beta1.Content = &CoreEvalProposal{}
18
18
  )
19
19
 
20
20
  func init() {
21
- govtypes.RegisterProposalType(ProposalTypeCoreEval)
21
+ govv1beta1.RegisterProposalType(ProposalTypeCoreEval)
22
22
  }
23
23
 
24
24
  // NewCoreEvalProposal creates a new core eval proposal.
25
- func NewCoreEvalProposal(title, description string, evals []CoreEval) govtypes.Content {
25
+ func NewCoreEvalProposal(title, description string, evals []CoreEval) govv1beta1.Content {
26
26
  return &CoreEvalProposal{
27
27
  Title: title,
28
28
  Description: description,
@@ -44,7 +44,7 @@ func (cep *CoreEvalProposal) ProposalType() string { return ProposalTypeCoreEval
44
44
 
45
45
  // ValidateBasic runs basic stateless validity checks
46
46
  func (cep *CoreEvalProposal) ValidateBasic() error {
47
- err := govtypes.ValidateAbstract(cep)
47
+ err := govv1beta1.ValidateAbstract(cep)
48
48
  if err != nil {
49
49
  return err
50
50
  }
@@ -3,6 +3,7 @@ package types
3
3
  import (
4
4
  "encoding/json"
5
5
  "errors"
6
+ "fmt"
6
7
 
7
8
  vstoragetypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
8
9
  sdk "github.com/cosmos/cosmos-sdk/types"
@@ -25,18 +26,16 @@ func NewEgress(nickname string, peer sdk.AccAddress, powerFlags []string) *Egres
25
26
  }
26
27
  }
27
28
 
28
- // FIXME: Should have @endo/nat
29
+ // Nat is analogous to @endo/nat
30
+ // https://github.com/endojs/endo/blob/master/packages/nat
29
31
  func Nat(num float64) (uint64, error) {
30
- if num < 0 {
31
- return 0, errors.New("Not a natural")
32
- }
33
-
34
- nat := uint64(num)
35
- if float64(nat) != num {
36
- return 0, errors.New("Not a precise integer")
32
+ if 0 <= num && num < (1<<53) {
33
+ nat := uint64(num)
34
+ if float64(nat) == num {
35
+ return nat, nil
36
+ }
37
37
  }
38
-
39
- return nat, nil
38
+ return 0, errors.New("Not a Nat")
40
39
  }
41
40
 
42
41
  type Messages struct {
@@ -45,24 +44,26 @@ type Messages struct {
45
44
  Ack uint64
46
45
  }
47
46
 
48
- func UnmarshalMessagesJSON(jsonString string) (*Messages, error) {
49
- // [message[], ack]
50
- // message [num, body]
51
- packet := make([]interface{}, 2)
52
- err := json.Unmarshal([]byte(jsonString), &packet)
47
+ // UnmarshalMessagesJSON decodes Messages from JSON text.
48
+ // Input must represent an array in which the first element is an array of
49
+ // [messageNum: integer, messageBody: string] pairs and the second element is
50
+ // an "Ack" integer.
51
+ func UnmarshalMessagesJSON(jsonString string) (ret *Messages, err error) {
52
+ packet := [2]interface{}{}
53
+ err = json.Unmarshal([]byte(jsonString), &packet)
53
54
  if err != nil {
54
55
  return nil, err
55
56
  }
56
57
 
57
- ret := &Messages{}
58
+ ret = &Messages{}
58
59
 
59
60
  ackFloat, ok := packet[1].(float64)
60
61
  if !ok {
61
- return nil, errors.New("Ack is not an integer")
62
+ return nil, errors.New("Ack is not a number")
62
63
  }
63
64
  ret.Ack, err = Nat(ackFloat)
64
65
  if err != nil {
65
- return nil, err
66
+ return nil, errors.New("Ack is not a Nat")
66
67
  }
67
68
 
68
69
  msgs, ok := packet[0].([]interface{})
@@ -72,24 +73,25 @@ func UnmarshalMessagesJSON(jsonString string) (*Messages, error) {
72
73
 
73
74
  ret.Messages = make([]string, len(msgs))
74
75
  ret.Nums = make([]uint64, len(msgs))
75
- for i, nummsgi := range msgs {
76
- nummsg, ok := nummsgi.([]interface{})
77
- if !ok || len(nummsg) != 2 {
78
- return nil, errors.New("Message is not a pair")
76
+ for i, rawMsg := range msgs {
77
+ arrMsg, ok := rawMsg.([]interface{})
78
+ if !ok || len(arrMsg) != 2 {
79
+ return nil, fmt.Errorf("Messages[%d] is not a pair", i)
79
80
  }
80
- numFloat, ok := nummsg[0].(float64)
81
+
82
+ numFloat, ok := arrMsg[0].(float64)
81
83
  if !ok {
82
- return nil, errors.New("Message Num is not an integer")
84
+ return nil, fmt.Errorf("Messages[%d] Num is not a number", i)
83
85
  }
84
86
  ret.Nums[i], err = Nat(numFloat)
85
87
  if err != nil {
86
- return nil, errors.New("Message num is not a Nat")
88
+ return nil, fmt.Errorf("Messages[%d] Num is not a Nat", i)
87
89
  }
88
- msg, ok := nummsg[1].(string)
90
+
91
+ ret.Messages[i], ok = arrMsg[1].(string)
89
92
  if !ok {
90
- return nil, errors.New("Message is not a string")
93
+ return nil, fmt.Errorf("Messages[%d] body is not a string", i)
91
94
  }
92
- ret.Messages[i] = msg
93
95
  }
94
96
 
95
97
  return ret, nil
@@ -2,6 +2,7 @@ package keeper
2
2
 
3
3
  import (
4
4
  "github.com/cosmos/cosmos-sdk/codec"
5
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
5
6
  sdk "github.com/cosmos/cosmos-sdk/types"
6
7
 
7
8
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/vbank/types"
@@ -15,7 +16,7 @@ const stateKey string = "state"
15
16
 
16
17
  // Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
17
18
  type Keeper struct {
18
- storeKey sdk.StoreKey
19
+ storeKey storetypes.StoreKey
19
20
  cdc codec.Codec
20
21
  paramSpace paramtypes.Subspace
21
22
 
@@ -27,7 +28,7 @@ type Keeper struct {
27
28
 
28
29
  // NewKeeper creates a new vbank Keeper instance
29
30
  func NewKeeper(
30
- cdc codec.Codec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
31
+ cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
31
32
  accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper,
32
33
  rewardDistributorName string,
33
34
  pushAction vm.ActionPusher,
@@ -11,7 +11,11 @@ import (
11
11
 
12
12
  func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
13
13
  return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) {
14
- switch path[0] {
14
+ var queryType string
15
+ if len(path) > 0 {
16
+ queryType = path[0]
17
+ }
18
+ switch queryType {
15
19
  case types.QueryParams:
16
20
  return queryParams(ctx, path[1:], req, k, legacyQuerierCdc)
17
21
 
@@ -19,7 +23,7 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
19
23
  return queryState(ctx, path[1:], req, k, legacyQuerierCdc)
20
24
 
21
25
  default:
22
- return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0])
26
+ return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown vbank query path")
23
27
  }
24
28
  }
25
29
  }
@@ -75,7 +75,7 @@ func (k Keeper) DistributeRewards(ctx sdk.Context) error {
75
75
  }
76
76
  }
77
77
 
78
- state.RewardPool = state.RewardPool.Sub(xfer)
78
+ state.RewardPool = state.RewardPool.Sub(xfer...)
79
79
  k.SetState(ctx, state)
80
80
  return nil
81
81
  }
package/x/vbank/vbank.go CHANGED
@@ -68,15 +68,15 @@ func (vbu vbankManyBalanceUpdates) Swap(i int, j int) {
68
68
  }
69
69
 
70
70
  type vbankBalanceUpdate struct {
71
- Nonce uint64 `json:"nonce"`
72
- Type string `json:"type"`
73
- Updated vbankManyBalanceUpdates `json:"updated"`
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
77
77
  // for the given addresses each for the specified denominations. Coins are used
78
78
  // only to track the set of denoms, not for the particular nonzero amounts.
79
- func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Jsonable {
79
+ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string]sdk.Coins) vm.Action {
80
80
  nentries := len(addressToUpdate)
81
81
  if nentries == 0 {
82
82
  return nil
@@ -84,7 +84,6 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
84
84
 
85
85
  nonce := keeper.GetNextSequence(ctx)
86
86
  event := vbankBalanceUpdate{
87
- Type: "VBANK_BALANCE_UPDATE",
88
87
  Nonce: nonce,
89
88
  Updated: make([]vbankSingleBalanceUpdate, 0, nentries),
90
89
  }
@@ -111,7 +110,9 @@ func getBalanceUpdate(ctx sdk.Context, keeper Keeper, addressToUpdate map[string
111
110
 
112
111
  // Ensure we have a deterministic order of updates.
113
112
  sort.Sort(event.Updated)
114
- return event
113
+
114
+ // Populate the event default fields (even though event does not embed vm.ActionHeader)
115
+ return vm.PopulateAction(ctx, event)
115
116
  }
116
117
 
117
118
  func marshal(event vm.Jsonable) ([]byte, error) {
@@ -121,8 +122,9 @@ func marshal(event vm.Jsonable) ([]byte, error) {
121
122
  return json.Marshal(event)
122
123
  }
123
124
 
124
- func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string, err error) {
125
+ func (ch portHandler) Receive(cctx context.Context, str string) (ret string, err error) {
125
126
  // fmt.Println("vbank.go downcall", str)
127
+ ctx := sdk.UnwrapSDKContext(cctx)
126
128
  keeper := ch.keeper
127
129
 
128
130
  var msg portMessage
@@ -140,7 +142,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
140
142
  if err = sdk.ValidateDenom(msg.Denom); err != nil {
141
143
  return "", fmt.Errorf("invalid denom %s: %s", msg.Denom, err)
142
144
  }
143
- coin := keeper.GetBalance(ctx.Context, addr, msg.Denom)
145
+ coin := keeper.GetBalance(ctx, addr, msg.Denom)
144
146
  packet := coin.Amount.String()
145
147
  if err == nil {
146
148
  bytes, err := json.Marshal(&packet)
@@ -162,12 +164,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
162
164
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
163
165
  }
164
166
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
165
- if err := keeper.GrabCoins(ctx.Context, addr, coins); err != nil {
167
+ if err := keeper.GrabCoins(ctx, addr, coins); err != nil {
166
168
  return "", fmt.Errorf("cannot grab %s coins: %s", coins.Sort().String(), err)
167
169
  }
168
170
  addressToBalances := make(map[string]sdk.Coins, 1)
169
171
  addressToBalances[msg.Sender] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
170
- bz, err := marshal(getBalanceUpdate(ctx.Context, keeper, addressToBalances))
172
+ bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
171
173
  if err != nil {
172
174
  return "", err
173
175
  }
@@ -190,12 +192,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
190
192
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
191
193
  }
192
194
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
193
- if err := keeper.SendCoins(ctx.Context, addr, coins); err != nil {
195
+ if err := keeper.SendCoins(ctx, addr, coins); err != nil {
194
196
  return "", fmt.Errorf("cannot give %s coins: %s", coins.Sort().String(), err)
195
197
  }
196
198
  addressToBalances := make(map[string]sdk.Coins, 1)
197
199
  addressToBalances[msg.Recipient] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
198
- bz, err := marshal(getBalanceUpdate(ctx.Context, keeper, addressToBalances))
200
+ bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
199
201
  if err != nil {
200
202
  return "", err
201
203
  }
@@ -211,20 +213,20 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
211
213
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
212
214
  }
213
215
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
214
- if err := keeper.StoreRewardCoins(ctx.Context, coins); err != nil {
216
+ if err := keeper.StoreRewardCoins(ctx, coins); err != nil {
215
217
  return "", fmt.Errorf("cannot store reward %s coins: %s", coins.Sort().String(), err)
216
218
  }
217
219
  if err != nil {
218
220
  return "", err
219
221
  }
220
- state := keeper.GetState(ctx.Context)
222
+ state := keeper.GetState(ctx)
221
223
  state.RewardPool = state.RewardPool.Add(coins...)
222
- keeper.SetState(ctx.Context, state)
224
+ keeper.SetState(ctx, state)
223
225
  // We don't supply the module balance, since the controller shouldn't know.
224
226
  ret = "true"
225
227
 
226
228
  case "VBANK_GET_MODULE_ACCOUNT_ADDRESS":
227
- addr := keeper.GetModuleAccountAddress(ctx.Context, msg.ModuleName).String()
229
+ addr := keeper.GetModuleAccountAddress(ctx, msg.ModuleName).String()
228
230
  if len(addr) == 0 {
229
231
  return "", fmt.Errorf("module account %s not found", msg.ModuleName)
230
232
  }
@@ -242,7 +244,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
242
244
  return
243
245
  }
244
246
 
245
- func (am AppModule) PushAction(ctx sdk.Context, action vm.Jsonable) error {
247
+ func (am AppModule) PushAction(ctx sdk.Context, action vm.Action) error {
246
248
  // vbank actions are not triggered by a swingset message in a transaction, so we need to
247
249
  // synthesize unique context information.
248
250
  // We use a fixed placeholder value for the txHash context, and can simply use `0` for the
@@ -250,7 +250,7 @@ func (b *mockBank) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, re
250
250
  func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sdk.Context) {
251
251
  encodingConfig := params.MakeEncodingConfig()
252
252
  cdc := encodingConfig.Marshaler
253
- pushAction := func(ctx sdk.Context, action vm.Jsonable) error {
253
+ pushAction := func(ctx sdk.Context, action vm.Action) error {
254
254
  return nil
255
255
  }
256
256
 
@@ -263,9 +263,9 @@ func makeTestKit(account types.AccountKeeper, bank types.BankKeeper) (Keeper, sd
263
263
 
264
264
  db := dbm.NewMemDB()
265
265
  ms := store.NewCommitMultiStore(db)
266
- ms.MountStoreWithDB(vbankStoreKey, sdk.StoreTypeIAVL, db)
267
- ms.MountStoreWithDB(paramsStoreKey, sdk.StoreTypeIAVL, db)
268
- ms.MountStoreWithDB(paramsTStoreKey, sdk.StoreTypeTransient, db)
266
+ ms.MountStoreWithDB(vbankStoreKey, storetypes.StoreTypeIAVL, db)
267
+ ms.MountStoreWithDB(paramsStoreKey, storetypes.StoreTypeIAVL, db)
268
+ ms.MountStoreWithDB(paramsTStoreKey, storetypes.StoreTypeTransient, db)
269
269
  err := ms.LoadLatestVersion()
270
270
  if err != nil {
271
271
  panic(err)
@@ -284,7 +284,7 @@ func Test_Receive_GetBalance(t *testing.T) {
284
284
  }}
285
285
  keeper, ctx := makeTestKit(nil, bank)
286
286
  ch := NewPortHandler(AppModule{}, keeper)
287
- ctlCtx := &vm.ControllerContext{Context: ctx}
287
+ ctlCtx := sdk.WrapSDKContext(ctx)
288
288
 
289
289
  ret, err := ch.Receive(ctlCtx, `{
290
290
  "type": "VBANK_GET_BALANCE",
@@ -312,7 +312,7 @@ func Test_Receive_Give(t *testing.T) {
312
312
  }}
313
313
  keeper, ctx := makeTestKit(nil, bank)
314
314
  ch := NewPortHandler(AppModule{}, keeper)
315
- ctlCtx := &vm.ControllerContext{Context: ctx}
315
+ ctlCtx := sdk.WrapSDKContext(ctx)
316
316
 
317
317
  ret, err := ch.Receive(ctlCtx, `{
318
318
  "type": "VBANK_GIVE",
@@ -349,7 +349,7 @@ func Test_Receive_GiveToRewardDistributor(t *testing.T) {
349
349
  bank := &mockBank{}
350
350
  keeper, ctx := makeTestKit(nil, bank)
351
351
  ch := NewPortHandler(AppModule{}, keeper)
352
- ctlCtx := &vm.ControllerContext{Context: ctx}
352
+ ctlCtx := sdk.WrapSDKContext(ctx)
353
353
 
354
354
  tests := []struct {
355
355
  name string
@@ -474,7 +474,7 @@ func Test_Receive_Grab(t *testing.T) {
474
474
  }}
475
475
  keeper, ctx := makeTestKit(nil, bank)
476
476
  ch := NewPortHandler(AppModule{}, keeper)
477
- ctlCtx := &vm.ControllerContext{Context: ctx}
477
+ ctlCtx := sdk.WrapSDKContext(ctx)
478
478
 
479
479
  ret, err := ch.Receive(ctlCtx, `{
480
480
  "type": "VBANK_GRAB",
@@ -517,16 +517,16 @@ func Test_EndBlock_Events(t *testing.T) {
517
517
  }}
518
518
  acct := &mockAuthKeeper{
519
519
  accounts: map[string]authtypes.AccountI{
520
- addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{ Address: addr1 }},
521
- addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{ Address: addr2 }},
522
- addr3: &authtypes.BaseAccount{ Address: addr3 },
520
+ addr1: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr1}},
521
+ addr2: &authtypes.ModuleAccount{BaseAccount: &authtypes.BaseAccount{Address: addr2}},
522
+ addr3: &authtypes.BaseAccount{Address: addr3},
523
523
  },
524
524
  }
525
525
  keeper, ctx := makeTestKit(acct, bank)
526
526
  // Turn off rewards.
527
527
  keeper.SetParams(ctx, types.Params{PerEpochRewardFraction: sdk.ZeroDec()})
528
528
  msgsSent := []string{}
529
- keeper.PushAction = func(ctx sdk.Context, action vm.Jsonable) error {
529
+ keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
530
530
  bz, err := json.Marshal(action)
531
531
  if err != nil {
532
532
  return err
@@ -630,7 +630,7 @@ func Test_EndBlock_Rewards(t *testing.T) {
630
630
  }
631
631
  keeper, ctx := makeTestKit(nil, bank)
632
632
  msgsSent := []string{}
633
- keeper.PushAction = func(ctx sdk.Context, action vm.Jsonable) error {
633
+ keeper.PushAction = func(ctx sdk.Context, action vm.Action) error {
634
634
  bz, err := json.Marshal(action)
635
635
  if err != nil {
636
636
  return err
@@ -746,7 +746,7 @@ func Test_EndBlock_Rewards(t *testing.T) {
746
746
  }
747
747
  }
748
748
 
749
- type mockAuthKeeper struct{
749
+ type mockAuthKeeper struct {
750
750
  accounts map[string]authtypes.AccountI
751
751
  modAddrs map[string]string
752
752
  }
@@ -754,11 +754,11 @@ type mockAuthKeeper struct{
754
754
  func (ma mockAuthKeeper) GetModuleAccount(ctx sdk.Context, name string) authtypes.ModuleAccountI {
755
755
  addr, ok := ma.modAddrs[name]
756
756
  if !ok {
757
- return nil
757
+ return nil
758
758
  }
759
759
  acct, ok := ma.accounts[addr]
760
760
  if !ok {
761
- panic("missing module account")
761
+ panic("missing module account")
762
762
  }
763
763
  return acct.(authtypes.ModuleAccountI)
764
764
  }
@@ -778,7 +778,7 @@ func Test_Module_Account(t *testing.T) {
778
778
  acct := &mockAuthKeeper{
779
779
  accounts: map[string]authtypes.AccountI{
780
780
  moduleBech32: authtypes.NewEmptyModuleAccount("vbank/reserve"),
781
- addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)),
781
+ addr1: authtypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(addr1)),
782
782
  },
783
783
  modAddrs: map[string]string{
784
784
  "vbank/reserve": moduleBech32,
@@ -787,7 +787,7 @@ func Test_Module_Account(t *testing.T) {
787
787
  keeper, ctx := makeTestKit(acct, nil)
788
788
  am := AppModule{keeper: keeper}
789
789
  ch := NewPortHandler(am, keeper)
790
- ctlCtx := &vm.ControllerContext{Context: ctx}
790
+ ctlCtx := sdk.WrapSDKContext(ctx)
791
791
 
792
792
  mod1 := "vbank/reserve"
793
793
  ret, err := ch.Receive(ctlCtx, `{