@agoric/cosmos 0.34.2-dev-1b6f03b.0 → 0.34.2-dev-9380cfe.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/git-revision.txt CHANGED
@@ -1 +1 @@
1
- 1b6f03b
1
+ 9380cfe
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/cosmos",
3
- "version": "0.34.2-dev-1b6f03b.0+1b6f03b",
3
+ "version": "0.34.2-dev-9380cfe.0+9380cfe",
4
4
  "description": "Connect JS to the Cosmos blockchain SDK",
5
5
  "parsers": {
6
6
  "js": "mjs"
@@ -38,5 +38,5 @@
38
38
  "typeCoverage": {
39
39
  "atLeast": 0
40
40
  },
41
- "gitHead": "1b6f03be8aa5cfe86039900ae8e1f15277a8333d"
41
+ "gitHead": "9380cfe04661eaed6de168e65a96730a8798bffb"
42
42
  }
@@ -2,6 +2,7 @@ package cli
2
2
 
3
3
  import (
4
4
  "fmt"
5
+ "io"
5
6
  "os"
6
7
  "strings"
7
8
 
@@ -56,20 +57,18 @@ func GetCmdDeliver() *cobra.Command {
56
57
  }
57
58
 
58
59
  jsonIn := args[0]
59
- if jsonIn[0] == '@' {
60
- fname := args[0][1:]
60
+ if strings.HasPrefix(jsonIn, "@") {
61
+ var jsonBytes []byte
62
+ fname := jsonIn[1:]
61
63
  if fname == "-" {
62
- // Reading from stdin.
63
- if _, err := fmt.Scanln(&jsonIn); err != nil {
64
- return err
65
- }
64
+ jsonBytes, err = io.ReadAll(os.Stdin)
66
65
  } else {
67
- jsonBytes, err := os.ReadFile(fname)
68
- if err != nil {
69
- return err
70
- }
71
- jsonIn = string(jsonBytes)
66
+ jsonBytes, err = os.ReadFile(fname)
72
67
  }
68
+ if err != nil {
69
+ return err
70
+ }
71
+ jsonIn = string(jsonBytes)
73
72
  }
74
73
  msgs, err := types.UnmarshalMessagesJSON(jsonIn)
75
74
  if err != nil {
@@ -102,20 +101,18 @@ func GetCmdInstallBundle() *cobra.Command {
102
101
  }
103
102
 
104
103
  jsonIn := args[0]
105
- if jsonIn[0] == '@' {
106
- fname := args[0][1:]
104
+ if strings.HasPrefix(jsonIn, "@") {
105
+ var jsonBytes []byte
106
+ fname := jsonIn[1:]
107
107
  if fname == "-" {
108
- // Reading from stdin.
109
- if _, err := fmt.Scanln(&jsonIn); err != nil {
110
- return err
111
- }
108
+ jsonBytes, err = io.ReadAll(os.Stdin)
112
109
  } else {
113
- jsonBytes, err := os.ReadFile(fname)
114
- if err != nil {
115
- return err
116
- }
117
- jsonIn = string(jsonBytes)
110
+ jsonBytes, err = os.ReadFile(fname)
118
111
  }
112
+ if err != nil {
113
+ return err
114
+ }
115
+ jsonIn = string(jsonBytes)
119
116
  }
120
117
 
121
118
  msg := types.NewMsgInstallBundle(jsonIn, cctx.GetFromAddress())
@@ -160,6 +157,8 @@ func GetCmdProvisionOne() *cobra.Command {
160
157
  return err
161
158
  }
162
159
 
160
+ nickname := args[0]
161
+
163
162
  addr, err := sdk.AccAddressFromBech32(args[1])
164
163
  if err != nil {
165
164
  return err
@@ -170,7 +169,7 @@ func GetCmdProvisionOne() *cobra.Command {
170
169
  powerFlags = strings.Split(args[2], ",")
171
170
  }
172
171
 
173
- msg := types.NewMsgProvision(args[0], addr, powerFlags, cctx.GetFromAddress())
172
+ msg := types.NewMsgProvision(nickname, addr, powerFlags, cctx.GetFromAddress())
174
173
  if err := msg.ValidateBasic(); err != nil {
175
174
  return err
176
175
  }
@@ -45,13 +45,11 @@ func (keeper msgServer) routeAction(ctx sdk.Context, msg vm.ControllerAdmissionM
45
45
  func (keeper msgServer) DeliverInbound(goCtx context.Context, msg *types.MsgDeliverInbound) (*types.MsgDeliverInboundResponse, error) {
46
46
  ctx := sdk.UnwrapSDKContext(goCtx)
47
47
 
48
+ // msg.Nums and msg.Messages must be zipped into an array of [num, message] pairs.
48
49
  messages := make([][]interface{}, len(msg.Messages))
49
50
  for i, message := range msg.Messages {
50
- messages[i] = make([]interface{}, 2)
51
- messages[i][0] = msg.Nums[i]
52
- messages[i][1] = message
51
+ messages[i] = []interface{}{msg.Nums[i], message}
53
52
  }
54
-
55
53
  action := &deliverInboundAction{
56
54
  Type: "DELIVER_INBOUND",
57
55
  Peer: msg.Submitter.String(),
@@ -24,11 +24,21 @@ 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:
@@ -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 == "" {
@@ -45,16 +45,18 @@ type Messages struct {
45
45
  Ack uint64
46
46
  }
47
47
 
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)
48
+ // UnmarshalMessagesJSON decodes Messages from JSON text.
49
+ // Input must represent an array in which the first element is an array of
50
+ // [messageNum: integer, messageBody: string] pairs and the second element is
51
+ // an "Ack" integer.
52
+ func UnmarshalMessagesJSON(jsonString string) (ret *Messages, err error) {
53
+ packet := [2]interface{}{}
54
+ err = json.Unmarshal([]byte(jsonString), &packet)
53
55
  if err != nil {
54
56
  return nil, err
55
57
  }
56
58
 
57
- ret := &Messages{}
59
+ ret = &Messages{}
58
60
 
59
61
  ackFloat, ok := packet[1].(float64)
60
62
  if !ok {
@@ -72,12 +74,13 @@ func UnmarshalMessagesJSON(jsonString string) (*Messages, error) {
72
74
 
73
75
  ret.Messages = make([]string, len(msgs))
74
76
  ret.Nums = make([]uint64, len(msgs))
75
- for i, nummsgi := range msgs {
76
- nummsg, ok := nummsgi.([]interface{})
77
- if !ok || len(nummsg) != 2 {
77
+ for i, rawMsg := range msgs {
78
+ arrMsg, ok := rawMsg.([]interface{})
79
+ if !ok || len(arrMsg) != 2 {
78
80
  return nil, errors.New("Message is not a pair")
79
81
  }
80
- numFloat, ok := nummsg[0].(float64)
82
+
83
+ numFloat, ok := arrMsg[0].(float64)
81
84
  if !ok {
82
85
  return nil, errors.New("Message Num is not an integer")
83
86
  }
@@ -85,11 +88,11 @@ func UnmarshalMessagesJSON(jsonString string) (*Messages, error) {
85
88
  if err != nil {
86
89
  return nil, errors.New("Message num is not a Nat")
87
90
  }
88
- msg, ok := nummsg[1].(string)
91
+
92
+ ret.Messages[i], ok = arrMsg[1].(string)
89
93
  if !ok {
90
94
  return nil, errors.New("Message is not a string")
91
95
  }
92
- ret.Messages[i] = msg
93
96
  }
94
97
 
95
98
  return ret, nil
@@ -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
 
@@ -33,7 +33,11 @@ func getVstorageEntryPath(urlPathSegments []string) (string, error) {
33
33
  // be used to extend it to a vstorage path such as "foo.bar.baz").
34
34
  func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
35
35
  return func(ctx sdk.Context, urlPathSegments []string, req abci.RequestQuery) (res []byte, err error) {
36
- switch urlPathSegments[0] {
36
+ var queryType string
37
+ if len(urlPathSegments) > 0 {
38
+ queryType = urlPathSegments[0]
39
+ }
40
+ switch queryType {
37
41
  case QueryData:
38
42
  entryPath, entryPathErr := getVstorageEntryPath(urlPathSegments[1:])
39
43
  if entryPathErr != nil {