@agoric/cosmos 0.35.0-upgrade-14-dev-8be87aa.0 → 0.35.0-upgrade-14-dev-c8f9e7b.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 (74) hide show
  1. package/Makefile +25 -12
  2. package/ante/ante.go +7 -5
  3. package/app/app.go +62 -47
  4. package/app/export.go +13 -6
  5. package/cmd/agd/main.go +5 -3
  6. package/cmd/libdaemon/main.go +5 -2
  7. package/daemon/cmd/genaccounts.go +13 -9
  8. package/daemon/cmd/root.go +27 -11
  9. package/daemon/cmd/root_test.go +1 -1
  10. package/daemon/cmd/testnet.go +17 -6
  11. package/daemon/main.go +3 -2
  12. package/git-revision.txt +1 -1
  13. package/go.mod +95 -64
  14. package/go.sum +592 -243
  15. package/package.json +2 -2
  16. package/proto/agoric/vstorage/query.proto +53 -1
  17. package/scripts/protocgen.sh +12 -1
  18. package/third_party/proto/buf.yaml +1 -0
  19. package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
  20. package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
  21. package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
  22. package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
  23. package/third_party/proto/google/api/annotations.proto +1 -1
  24. package/third_party/proto/google/api/http.proto +181 -120
  25. package/third_party/proto/google/api/httpbody.proto +9 -6
  26. package/third_party/proto/google/protobuf/any.proto +1 -7
  27. package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
  28. package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
  29. package/upgradegaia.sh +13 -4
  30. package/vm/action.go +24 -21
  31. package/vm/action_test.go +5 -5
  32. package/vm/controller.go +9 -10
  33. package/x/lien/keeper/account.go +3 -3
  34. package/x/lien/keeper/keeper.go +5 -4
  35. package/x/lien/keeper/keeper_test.go +8 -8
  36. package/x/lien/lien.go +6 -4
  37. package/x/lien/lien_test.go +20 -16
  38. package/x/swingset/client/cli/query.go +2 -2
  39. package/x/swingset/client/cli/tx.go +48 -33
  40. package/x/swingset/client/proposal_handler.go +2 -17
  41. package/x/swingset/keeper/keeper.go +8 -11
  42. package/x/swingset/keeper/keeper_test.go +1 -1
  43. package/x/swingset/keeper/msg_server.go +2 -4
  44. package/x/swingset/keeper/proposal.go +10 -0
  45. package/x/swingset/keeper/querier.go +14 -6
  46. package/x/swingset/proposal_handler.go +3 -3
  47. package/x/swingset/swingset.go +4 -2
  48. package/x/swingset/types/codec.go +2 -2
  49. package/x/swingset/types/msgs.pb.go +16 -16
  50. package/x/swingset/types/proposal.go +5 -5
  51. package/x/swingset/types/types.go +30 -28
  52. package/x/vbank/keeper/keeper.go +3 -2
  53. package/x/vbank/keeper/querier.go +6 -2
  54. package/x/vbank/keeper/rewards.go +1 -1
  55. package/x/vbank/vbank.go +11 -10
  56. package/x/vbank/vbank_test.go +8 -8
  57. package/x/vibc/ibc.go +27 -26
  58. package/x/vibc/keeper/keeper.go +19 -18
  59. package/x/vibc/types/expected_keepers.go +13 -5
  60. package/x/vibc/types/msgs.go +1 -1
  61. package/x/vibc/types/msgs.pb.go +1 -1
  62. package/x/vstorage/README.md +138 -0
  63. package/x/vstorage/capdata/capdata.go +298 -0
  64. package/x/vstorage/capdata/capdata_test.go +352 -0
  65. package/x/vstorage/client/cli/query.go +51 -4
  66. package/x/vstorage/keeper/grpc_query.go +221 -0
  67. package/x/vstorage/keeper/keeper.go +3 -2
  68. package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
  69. package/x/vstorage/keeper/keeper_test.go +1 -1
  70. package/x/vstorage/keeper/querier.go +6 -2
  71. package/x/vstorage/types/query.pb.go +646 -36
  72. package/x/vstorage/types/query.pb.gw.go +119 -0
  73. package/x/vstorage/vstorage.go +16 -15
  74. package/x/vstorage/vstorage_test.go +5 -5
@@ -7,11 +7,14 @@ import (
7
7
  stdlog "log"
8
8
  "math"
9
9
 
10
+ sdkmath "cosmossdk.io/math"
11
+
10
12
  "github.com/tendermint/tendermint/libs/log"
11
13
 
12
14
  "github.com/cosmos/cosmos-sdk/baseapp"
13
15
  "github.com/cosmos/cosmos-sdk/codec"
14
16
  "github.com/cosmos/cosmos-sdk/store/prefix"
17
+ storetypes "github.com/cosmos/cosmos-sdk/store/types"
15
18
  sdk "github.com/cosmos/cosmos-sdk/types"
16
19
  bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
17
20
  paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
@@ -69,7 +72,7 @@ type inboundQueueRecord struct {
69
72
 
70
73
  // Keeper maintains the link to data vstorage and exposes getter/setter methods for the various parts of the state machine
71
74
  type Keeper struct {
72
- storeKey sdk.StoreKey
75
+ storeKey storetypes.StoreKey
73
76
  cdc codec.Codec
74
77
  paramSpace paramtypes.Subspace
75
78
 
@@ -87,7 +90,7 @@ var _ ante.SwingsetKeeper = &Keeper{}
87
90
 
88
91
  // NewKeeper creates a new IBC transfer Keeper instance
89
92
  func NewKeeper(
90
- cdc codec.Codec, key sdk.StoreKey, paramSpace paramtypes.Subspace,
93
+ cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
91
94
  accountKeeper types.AccountKeeper, bankKeeper bankkeeper.Keeper,
92
95
  vstorageKeeper vstoragekeeper.Keeper, feeCollectorName string,
93
96
  callToController func(ctx sdk.Context, str string) (string, error),
@@ -139,13 +142,7 @@ func (k Keeper) pushAction(ctx sdk.Context, inboundQueuePath string, action vm.A
139
142
  }
140
143
  msgIdx, msgIdxOk := ctx.Context().Value(baseapp.TxMsgIdxContextKey).(int)
141
144
  if !txHashOk || !msgIdxOk {
142
- switch action.(type) {
143
- case *coreEvalAction:
144
- // This is expected for CORE_EVAL since it's not in a transaction
145
- // (deferred by governance to a BeginBlocker).
146
- default:
147
- stdlog.Printf("error while extracting context for action %q\n", action)
148
- }
145
+ stdlog.Printf("error while extracting context for action %q\n", action)
149
146
  }
150
147
  record := inboundQueueRecord{Action: action, Context: actionContext{BlockHeight: ctx.BlockHeight(), TxHash: txHash, MsgIdx: msgIdx}}
151
148
  bz, err := json.Marshal(record)
@@ -304,9 +301,9 @@ func (k Keeper) GetBeansOwing(ctx sdk.Context, addr sdk.AccAddress) sdk.Uint {
304
301
  path := getBeansOwingPathForAddress(addr)
305
302
  entry := k.vstorageKeeper.GetEntry(ctx, path)
306
303
  if !entry.HasValue() {
307
- return sdk.ZeroUint()
304
+ return sdkmath.ZeroUint()
308
305
  }
309
- return sdk.NewUintFromString(entry.StringValue())
306
+ return sdkmath.NewUintFromString(entry.StringValue())
310
307
  }
311
308
 
312
309
  // SetBeansOwing sets the number of beans that the given address owes to the
@@ -196,7 +196,7 @@ var (
196
196
  func makeTestStore() sdk.KVStore {
197
197
  db := dbm.NewMemDB()
198
198
  ms := store.NewCommitMultiStore(db)
199
- ms.MountStoreWithDB(swingsetStoreKey, sdk.StoreTypeIAVL, db)
199
+ ms.MountStoreWithDB(swingsetStoreKey, storetypes.StoreTypeIAVL, db)
200
200
  err := ms.LoadLatestVersion()
201
201
  if err != nil {
202
202
  panic(err)
@@ -43,13 +43,11 @@ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionM
43
43
  func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeliverInbound) (*types.MsgDeliverInboundResponse, error) {
44
44
  ctx := sdk.UnwrapSDKContext(goCtx)
45
45
 
46
+ // msg.Nums and msg.Messages must be zipped into an array of [num, message] pairs.
46
47
  messages := make([][]interface{}, len(msg.Messages))
47
48
  for i, message := range msg.Messages {
48
- messages[i] = make([]interface{}, 2)
49
- messages[i][0] = msg.Nums[i]
50
- messages[i][1] = message
49
+ messages[i] = []interface{}{msg.Nums[i], message}
51
50
  }
52
-
53
51
  action := &deliverInboundAction{
54
52
  Peer: msg.Submitter.String(),
55
53
  Messages: messages,
@@ -1,10 +1,13 @@
1
1
  package keeper
2
2
 
3
3
  import (
4
+ "context"
5
+
4
6
  sdk "github.com/cosmos/cosmos-sdk/types"
5
7
 
6
8
  "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
7
9
  "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
10
+ "github.com/cosmos/cosmos-sdk/baseapp"
8
11
  )
9
12
 
10
13
  type coreEvalAction struct {
@@ -18,5 +21,12 @@ func (k Keeper) CoreEvalProposal(ctx sdk.Context, p *types.CoreEvalProposal) err
18
21
  Evals: p.Evals,
19
22
  }
20
23
 
24
+ // While the CoreEvalProposal was originally created by a transaction, by the time it
25
+ // passes by governance, we no longer have its provenance information, so we need to
26
+ // synthesize unique context information.
27
+ // We use a fixed placeholder value for the txHash context. We use `0` for the message
28
+ // index which assumes there is a single proposal per block.
29
+ ctx = ctx.WithContext(context.WithValue(ctx.Context(), baseapp.TxHashContextKey, "x/gov"))
30
+ ctx = ctx.WithContext(context.WithValue(ctx.Context(), baseapp.TxMsgIdxContextKey, 0))
21
31
  return k.PushHighPriorityAction(ctx, action)
22
32
  }
@@ -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 == "" {
@@ -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
@@ -122,8 +122,9 @@ func marshal(event vm.Jsonable) ([]byte, error) {
122
122
  return json.Marshal(event)
123
123
  }
124
124
 
125
- 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) {
126
126
  // fmt.Println("vbank.go downcall", str)
127
+ ctx := sdk.UnwrapSDKContext(cctx)
127
128
  keeper := ch.keeper
128
129
 
129
130
  var msg portMessage
@@ -141,7 +142,7 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
141
142
  if err = sdk.ValidateDenom(msg.Denom); err != nil {
142
143
  return "", fmt.Errorf("invalid denom %s: %s", msg.Denom, err)
143
144
  }
144
- coin := keeper.GetBalance(ctx.Context, addr, msg.Denom)
145
+ coin := keeper.GetBalance(ctx, addr, msg.Denom)
145
146
  packet := coin.Amount.String()
146
147
  if err == nil {
147
148
  bytes, err := json.Marshal(&packet)
@@ -163,12 +164,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
163
164
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
164
165
  }
165
166
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
166
- if err := keeper.GrabCoins(ctx.Context, addr, coins); err != nil {
167
+ if err := keeper.GrabCoins(ctx, addr, coins); err != nil {
167
168
  return "", fmt.Errorf("cannot grab %s coins: %s", coins.Sort().String(), err)
168
169
  }
169
170
  addressToBalances := make(map[string]sdk.Coins, 1)
170
171
  addressToBalances[msg.Sender] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
171
- bz, err := marshal(getBalanceUpdate(ctx.Context, keeper, addressToBalances))
172
+ bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
172
173
  if err != nil {
173
174
  return "", err
174
175
  }
@@ -191,12 +192,12 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
191
192
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
192
193
  }
193
194
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
194
- if err := keeper.SendCoins(ctx.Context, addr, coins); err != nil {
195
+ if err := keeper.SendCoins(ctx, addr, coins); err != nil {
195
196
  return "", fmt.Errorf("cannot give %s coins: %s", coins.Sort().String(), err)
196
197
  }
197
198
  addressToBalances := make(map[string]sdk.Coins, 1)
198
199
  addressToBalances[msg.Recipient] = sdk.NewCoins(sdk.NewInt64Coin(msg.Denom, 1))
199
- bz, err := marshal(getBalanceUpdate(ctx.Context, keeper, addressToBalances))
200
+ bz, err := marshal(getBalanceUpdate(ctx, keeper, addressToBalances))
200
201
  if err != nil {
201
202
  return "", err
202
203
  }
@@ -212,20 +213,20 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
212
213
  return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
213
214
  }
214
215
  coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
215
- if err := keeper.StoreRewardCoins(ctx.Context, coins); err != nil {
216
+ if err := keeper.StoreRewardCoins(ctx, coins); err != nil {
216
217
  return "", fmt.Errorf("cannot store reward %s coins: %s", coins.Sort().String(), err)
217
218
  }
218
219
  if err != nil {
219
220
  return "", err
220
221
  }
221
- state := keeper.GetState(ctx.Context)
222
+ state := keeper.GetState(ctx)
222
223
  state.RewardPool = state.RewardPool.Add(coins...)
223
- keeper.SetState(ctx.Context, state)
224
+ keeper.SetState(ctx, state)
224
225
  // We don't supply the module balance, since the controller shouldn't know.
225
226
  ret = "true"
226
227
 
227
228
  case "VBANK_GET_MODULE_ACCOUNT_ADDRESS":
228
- addr := keeper.GetModuleAccountAddress(ctx.Context, msg.ModuleName).String()
229
+ addr := keeper.GetModuleAccountAddress(ctx, msg.ModuleName).String()
229
230
  if len(addr) == 0 {
230
231
  return "", fmt.Errorf("module account %s not found", msg.ModuleName)
231
232
  }
@@ -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",
@@ -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, `{