@agoric/cosmos 0.34.2-dev-5dc325b.0 → 0.35.0-getting-started-dev-26244e8.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 +73 -0
- package/app/app.go +4 -5
- package/cmd/agd/main.go +11 -133
- package/cmd/libdaemon/main.go +53 -67
- package/daemon/cmd/root.go +24 -55
- package/daemon/main.go +1 -3
- package/git-revision.txt +1 -1
- package/package.json +3 -6
- package/proto/agoric/vstorage/query.proto +1 -53
- package/vm/controller.go +18 -8
- package/x/lien/lien.go +4 -6
- package/x/lien/lien_test.go +15 -19
- package/x/swingset/abci.go +2 -3
- package/x/swingset/swingset.go +2 -4
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/vbank/vbank.go +10 -11
- package/x/vbank/vbank_test.go +5 -5
- package/x/vibc/ibc.go +9 -11
- package/x/vstorage/keeper/grpc_query.go +0 -221
- package/x/vstorage/types/query.pb.go +36 -646
- package/x/vstorage/types/query.pb.gw.go +0 -119
- package/x/vstorage/vstorage.go +15 -16
- package/x/vstorage/vstorage_test.go +4 -4
- package/cmd/agd/agvm.go +0 -42
- package/vm/client.go +0 -113
- package/vm/client_test.go +0 -184
- package/vm/jsonrpcconn/jsonrpcconn.go +0 -160
- package/vm/jsonrpcconn/jsonrpcconn_test.go +0 -126
- package/vm/server.go +0 -23
- package/x/vstorage/README.md +0 -140
- package/x/vstorage/capdata/capdata.go +0 -298
- package/x/vstorage/capdata/capdata_test.go +0 -352
- package/x/vstorage/keeper/keeper_grpc_test.go +0 -300
|
@@ -2,14 +2,10 @@ package keeper
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
|
-
"encoding/json"
|
|
6
|
-
"fmt"
|
|
7
|
-
"strings"
|
|
8
5
|
|
|
9
6
|
"google.golang.org/grpc/codes"
|
|
10
7
|
"google.golang.org/grpc/status"
|
|
11
8
|
|
|
12
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/capdata"
|
|
13
9
|
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
|
|
14
10
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
15
11
|
)
|
|
@@ -21,11 +17,6 @@ type Querier struct {
|
|
|
21
17
|
|
|
22
18
|
var _ types.QueryServer = Querier{}
|
|
23
19
|
|
|
24
|
-
// ===================================================================
|
|
25
|
-
// /agoric.vstorage.Query/Data
|
|
26
|
-
// ===================================================================
|
|
27
|
-
|
|
28
|
-
// /agoric.vstorage.Query/Data returns data for a specified path.
|
|
29
20
|
func (k Querier) Data(c context.Context, req *types.QueryDataRequest) (*types.QueryDataResponse, error) {
|
|
30
21
|
if req == nil {
|
|
31
22
|
return nil, status.Error(codes.InvalidArgument, "empty request")
|
|
@@ -39,218 +30,6 @@ func (k Querier) Data(c context.Context, req *types.QueryDataRequest) (*types.Qu
|
|
|
39
30
|
}, nil
|
|
40
31
|
}
|
|
41
32
|
|
|
42
|
-
// ===================================================================
|
|
43
|
-
// /agoric.vstorage.Query/CapData
|
|
44
|
-
// ===================================================================
|
|
45
|
-
|
|
46
|
-
const (
|
|
47
|
-
// Media types.
|
|
48
|
-
JSONLines = "JSON Lines"
|
|
49
|
-
|
|
50
|
-
// CapData transformation formats.
|
|
51
|
-
FormatCapDataFlat = "flat"
|
|
52
|
-
|
|
53
|
-
// CapData remotable value formats.
|
|
54
|
-
FormatRemotableAsObject = "object"
|
|
55
|
-
FormatRemotableAsString = "string"
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
var capDataResponseMediaTypes = map[string]string{
|
|
59
|
-
JSONLines: JSONLines,
|
|
60
|
-
// Default to JSON Lines.
|
|
61
|
-
"": JSONLines,
|
|
62
|
-
}
|
|
63
|
-
var capDataTransformationFormats = map[string]string{
|
|
64
|
-
FormatCapDataFlat: FormatCapDataFlat,
|
|
65
|
-
// Default to no transformation.
|
|
66
|
-
"": "",
|
|
67
|
-
}
|
|
68
|
-
var capDataRemotableValueFormats = map[string]string{
|
|
69
|
-
FormatRemotableAsObject: FormatRemotableAsObject,
|
|
70
|
-
FormatRemotableAsString: FormatRemotableAsString,
|
|
71
|
-
// No default because both formats are lossy.
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// flatten converts data into a flat structure in which each deep leaf entry is replaced with
|
|
75
|
-
// a top-level entry having the same value but a key generated by joining the keys on its path
|
|
76
|
-
// with separating dashes.
|
|
77
|
-
// For example,
|
|
78
|
-
// ```
|
|
79
|
-
// { "contacts": [
|
|
80
|
-
//
|
|
81
|
-
// { "name": "Alice", "email": "a@example.com" },
|
|
82
|
-
// { "name": "Bob", "email": "b@example.com" }
|
|
83
|
-
//
|
|
84
|
-
// ] }
|
|
85
|
-
// ```
|
|
86
|
-
// becomes
|
|
87
|
-
// ```
|
|
88
|
-
//
|
|
89
|
-
// {
|
|
90
|
-
// "contacts-0-name": "Alice",
|
|
91
|
-
// "contacts-0-email": "a@example.com",
|
|
92
|
-
// "contacts-1-name": "Bob",
|
|
93
|
-
// "contacts-1-email": "b@example.com"
|
|
94
|
-
// }
|
|
95
|
-
//
|
|
96
|
-
// ```
|
|
97
|
-
// cf. https://github.com/Agoric/agoric-sdk/blob/6e5b422b80e47c4dac151404f43faea5ab41e9b0/scripts/get-flattened-publication.sh
|
|
98
|
-
func flatten(input interface{}, output map[string]interface{}, key string, top bool) error {
|
|
99
|
-
// Act on the raw representation of a Remotable.
|
|
100
|
-
if remotable, ok := input.(*capdata.CapdataRemotable); ok {
|
|
101
|
-
var replacement interface{}
|
|
102
|
-
repr, err := capdata.JsonMarshal(remotable)
|
|
103
|
-
if err == nil {
|
|
104
|
-
err = json.Unmarshal(repr, &replacement)
|
|
105
|
-
}
|
|
106
|
-
if err != nil {
|
|
107
|
-
return err
|
|
108
|
-
}
|
|
109
|
-
input = replacement
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
childKeyPrefix := key
|
|
113
|
-
if !top {
|
|
114
|
-
childKeyPrefix = childKeyPrefix + "-"
|
|
115
|
-
}
|
|
116
|
-
if arr, ok := input.([]interface{}); ok {
|
|
117
|
-
for i, v := range arr {
|
|
118
|
-
if err := flatten(v, output, childKeyPrefix+fmt.Sprintf("%d", i), false); err != nil {
|
|
119
|
-
return err
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
} else if obj, ok := input.(map[string]interface{}); ok {
|
|
123
|
-
for k, v := range obj {
|
|
124
|
-
if err := flatten(v, output, childKeyPrefix+k, false); err != nil {
|
|
125
|
-
return err
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
if _, has := output[key]; has {
|
|
130
|
-
return fmt.Errorf("key conflict: %q", key)
|
|
131
|
-
}
|
|
132
|
-
output[key] = input
|
|
133
|
-
}
|
|
134
|
-
return nil
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// capdataBigintToDigits represents a bigint as a string consisting of
|
|
138
|
-
// an optional "-" followed by a sequence of digits with no extraneous zeroes
|
|
139
|
-
// (e.g., "0" or "-40").
|
|
140
|
-
func capdataBigintToDigits(bigint *capdata.CapdataBigint) interface{} {
|
|
141
|
-
return bigint.Normalized
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// capdataRemotableToString represents a Remotable as a bracketed string
|
|
145
|
-
// containing its alleged name and id from `slots`
|
|
146
|
-
// (e.g., "[Alleged: IST brand <board007>]").
|
|
147
|
-
func capdataRemotableToString(r *capdata.CapdataRemotable) interface{} {
|
|
148
|
-
iface := "Remotable"
|
|
149
|
-
if r.Iface != nil || *r.Iface != "" {
|
|
150
|
-
iface = *r.Iface
|
|
151
|
-
}
|
|
152
|
-
return fmt.Sprintf("[%s <%s>]", iface, r.Id)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// capdataRemotableToObject represents a Remotable as an object containing
|
|
156
|
-
// its id from `slots` and its alleged name minus any "Alleged:" prefix
|
|
157
|
-
// (e.g., `{ "id": "board007", "allegedName": "IST brand" }`).
|
|
158
|
-
func capdataRemotableToObject(r *capdata.CapdataRemotable) interface{} {
|
|
159
|
-
iface := "Remotable"
|
|
160
|
-
if r.Iface != nil || *r.Iface != "" {
|
|
161
|
-
iface = *r.Iface
|
|
162
|
-
iface, _ = strings.CutPrefix(iface, "Alleged: ")
|
|
163
|
-
}
|
|
164
|
-
return map[string]interface{}{"id": r.Id, "allegedName": iface}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// /agoric.vstorage.Query/CapData returns data for a specified path,
|
|
168
|
-
// interpreted as CapData in a StreamCell (auto-promoting isolated CapData
|
|
169
|
-
// into a single-item StreamCell) and transformed as specified.
|
|
170
|
-
func (k Querier) CapData(c context.Context, req *types.QueryCapDataRequest) (*types.QueryCapDataResponse, error) {
|
|
171
|
-
if req == nil {
|
|
172
|
-
return nil, status.Error(codes.InvalidArgument, "empty request")
|
|
173
|
-
}
|
|
174
|
-
ctx := sdk.UnwrapSDKContext(c)
|
|
175
|
-
|
|
176
|
-
valueTransformations := capdata.CapdataValueTransformations{
|
|
177
|
-
Bigint: capdataBigintToDigits,
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// A response Value is "<prefix><separator-joined items><suffix>".
|
|
181
|
-
prefix, separator, suffix := "", "\n", ""
|
|
182
|
-
|
|
183
|
-
// Read options.
|
|
184
|
-
mediaType, ok := capDataResponseMediaTypes[req.MediaType]
|
|
185
|
-
if !ok {
|
|
186
|
-
return nil, status.Error(codes.InvalidArgument, "invalid media_type")
|
|
187
|
-
}
|
|
188
|
-
transformation, ok := capDataTransformationFormats[req.ItemFormat]
|
|
189
|
-
if !ok {
|
|
190
|
-
return nil, status.Error(codes.InvalidArgument, "invalid item_format")
|
|
191
|
-
}
|
|
192
|
-
switch remotableFormat, ok := capDataRemotableValueFormats[req.RemotableValueFormat]; {
|
|
193
|
-
case !ok:
|
|
194
|
-
return nil, status.Error(codes.InvalidArgument, "invalid remotable_value_format")
|
|
195
|
-
case remotableFormat == FormatRemotableAsObject:
|
|
196
|
-
valueTransformations.Remotable = capdataRemotableToObject
|
|
197
|
-
case remotableFormat == FormatRemotableAsString:
|
|
198
|
-
valueTransformations.Remotable = capdataRemotableToString
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Read data, auto-upgrading a standalone value to a single-value StreamCell.
|
|
202
|
-
entry := k.GetEntry(ctx, req.Path)
|
|
203
|
-
if !entry.HasValue() {
|
|
204
|
-
return nil, status.Error(codes.FailedPrecondition, "no data")
|
|
205
|
-
}
|
|
206
|
-
value := entry.StringValue()
|
|
207
|
-
var cell StreamCell
|
|
208
|
-
_ = json.Unmarshal([]byte(value), &cell)
|
|
209
|
-
if cell.BlockHeight == "" {
|
|
210
|
-
cell = StreamCell{Values: []string{value}}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Format each StreamCell value.
|
|
214
|
-
responseItems := make([]string, len(cell.Values))
|
|
215
|
-
for i, capDataJson := range cell.Values {
|
|
216
|
-
item, err := capdata.DecodeSerializedCapdata(capDataJson, valueTransformations)
|
|
217
|
-
if err != nil {
|
|
218
|
-
return nil, status.Error(codes.FailedPrecondition, err.Error())
|
|
219
|
-
}
|
|
220
|
-
if transformation == FormatCapDataFlat {
|
|
221
|
-
flattened := map[string]interface{}{}
|
|
222
|
-
if err := flatten(item, flattened, "", true); err != nil {
|
|
223
|
-
return nil, status.Error(codes.Internal, err.Error())
|
|
224
|
-
}
|
|
225
|
-
// Replace the item, unless it was a scalar that "flattened" to `{ "": ... }`.
|
|
226
|
-
if _, singleton := flattened[""]; !singleton {
|
|
227
|
-
item = flattened
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
switch mediaType {
|
|
231
|
-
case JSONLines:
|
|
232
|
-
jsonText, err := capdata.JsonMarshal(item)
|
|
233
|
-
if err != nil {
|
|
234
|
-
return nil, status.Error(codes.Internal, err.Error())
|
|
235
|
-
}
|
|
236
|
-
responseItems[i] = string(jsonText)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return &types.QueryCapDataResponse{
|
|
241
|
-
BlockHeight: cell.BlockHeight,
|
|
242
|
-
Value: prefix + strings.Join(responseItems, separator) + suffix,
|
|
243
|
-
}, nil
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// ===================================================================
|
|
247
|
-
// /agoric.vstorage.Query/Children
|
|
248
|
-
// ===================================================================
|
|
249
|
-
|
|
250
|
-
// /agoric.vstorage.Query/Children returns the list of path segments
|
|
251
|
-
// that exist immediately underneath a specified path, including
|
|
252
|
-
// those corresponding with "empty non-terminals" having children
|
|
253
|
-
// but no data of their own.
|
|
254
33
|
func (k Querier) Children(c context.Context, req *types.QueryChildrenRequest) (*types.QueryChildrenResponse, error) {
|
|
255
34
|
if req == nil {
|
|
256
35
|
return nil, status.Error(codes.InvalidArgument, "empty request")
|