@agoric/cosmos 0.34.2-dev-3573f79.0 → 0.34.2-dev-fed2b5e.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/app/app.go +41 -23
- package/git-revision.txt +1 -1
- package/package.json +2 -2
- package/proto/agoric/swingset/genesis.proto +10 -0
- package/types/kv_entry.go +114 -0
- package/types/kv_entry_helpers.go +234 -0
- package/types/kv_entry_helpers_test.go +237 -0
- package/types/kv_entry_test.go +143 -0
- package/x/swingset/genesis.go +30 -8
- package/x/swingset/keeper/extension_snapshotter.go +25 -37
- package/x/swingset/keeper/extension_snapshotter_test.go +0 -2
- package/x/swingset/keeper/keeper.go +14 -9
- package/x/swingset/keeper/keeper_test.go +77 -0
- package/x/swingset/keeper/querier.go +1 -1
- package/x/swingset/keeper/swing_store_exports_handler.go +23 -44
- package/x/swingset/keeper/swing_store_exports_handler_test.go +1 -1
- package/x/swingset/swingset.go +71 -0
- package/x/swingset/types/genesis.pb.go +308 -18
- package/x/vstorage/keeper/grpc_query.go +1 -1
- package/x/vstorage/keeper/keeper.go +19 -19
- package/x/vstorage/keeper/keeper_grpc_test.go +3 -2
- package/x/vstorage/keeper/keeper_test.go +21 -20
- package/x/vstorage/keeper/querier.go +1 -1
- package/x/vstorage/types/types.go +0 -66
- package/x/vstorage/vstorage.go +19 -22
- package/x/vstorage/vstorage_test.go +14 -14
|
@@ -35,7 +35,7 @@ func NewQuerier(keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
|
|
|
35
35
|
// nolint: unparam
|
|
36
36
|
func queryData(ctx sdk.Context, path string, req abci.RequestQuery, keeper Keeper, legacyQuerierCdc *codec.LegacyAmino) (res []byte, err error) {
|
|
37
37
|
entry := keeper.GetEntry(ctx, path)
|
|
38
|
-
if !entry.
|
|
38
|
+
if !entry.HasValue() {
|
|
39
39
|
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "could not get vstorage path")
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
package types
|
|
2
2
|
|
|
3
|
-
import (
|
|
4
|
-
"encoding/json"
|
|
5
|
-
"fmt"
|
|
6
|
-
)
|
|
7
|
-
|
|
8
3
|
func NewData() *Data {
|
|
9
4
|
return &Data{}
|
|
10
5
|
}
|
|
@@ -12,64 +7,3 @@ func NewData() *Data {
|
|
|
12
7
|
func NewChildren() *Children {
|
|
13
8
|
return &Children{}
|
|
14
9
|
}
|
|
15
|
-
|
|
16
|
-
type StorageEntry struct {
|
|
17
|
-
path string
|
|
18
|
-
value *string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
func NewStorageEntry(path string, value string) StorageEntry {
|
|
22
|
-
return StorageEntry{path, &value}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
func NewStorageEntryWithNoData(path string) StorageEntry {
|
|
26
|
-
return StorageEntry{path, nil}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// UnmarshalStorageEntry interprets its argument as a [key: string, value?: string | null]
|
|
30
|
-
// JSON array and returns a corresponding StorageEntry.
|
|
31
|
-
// The key must be a string, and the value (if present) must be a string or null.
|
|
32
|
-
func UnmarshalStorageEntry(msg json.RawMessage) (entry StorageEntry, err error) {
|
|
33
|
-
var generic [2]interface{}
|
|
34
|
-
err = json.Unmarshal(msg, &generic)
|
|
35
|
-
|
|
36
|
-
if err != nil {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
path, ok := generic[0].(string)
|
|
41
|
-
if !ok {
|
|
42
|
-
err = fmt.Errorf("invalid storage entry path: %q", generic[0])
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
switch generic[1].(type) {
|
|
47
|
-
case string:
|
|
48
|
-
entry = NewStorageEntry(path, generic[1].(string))
|
|
49
|
-
case nil:
|
|
50
|
-
entry = NewStorageEntryWithNoData(path)
|
|
51
|
-
default:
|
|
52
|
-
err = fmt.Errorf("invalid storage entry value: %q", generic[1])
|
|
53
|
-
}
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
func (se StorageEntry) HasData() bool {
|
|
58
|
-
return se.value != nil
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
func (se StorageEntry) Path() string {
|
|
62
|
-
return se.path
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
func (se StorageEntry) Value() *string {
|
|
66
|
-
return se.value
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
func (se StorageEntry) StringValue() string {
|
|
70
|
-
if se.value != nil {
|
|
71
|
-
return *se.value
|
|
72
|
-
} else {
|
|
73
|
-
return ""
|
|
74
|
-
}
|
|
75
|
-
}
|
package/x/vstorage/vstorage.go
CHANGED
|
@@ -7,8 +7,8 @@ import (
|
|
|
7
7
|
|
|
8
8
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
9
9
|
|
|
10
|
+
agoric "github.com/Agoric/agoric-sdk/golang/cosmos/types"
|
|
10
11
|
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
11
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
|
|
12
12
|
)
|
|
13
13
|
|
|
14
14
|
type vstorageHandler struct {
|
|
@@ -69,8 +69,8 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
69
69
|
switch msg.Method {
|
|
70
70
|
case "set":
|
|
71
71
|
for _, arg := range msg.Args {
|
|
72
|
-
var entry
|
|
73
|
-
|
|
72
|
+
var entry agoric.KVEntry
|
|
73
|
+
err = json.Unmarshal(arg, &entry)
|
|
74
74
|
if err != nil {
|
|
75
75
|
return
|
|
76
76
|
}
|
|
@@ -83,8 +83,8 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
83
83
|
// FIXME: Use just "set" and remove this case.
|
|
84
84
|
case "legacySet":
|
|
85
85
|
for _, arg := range msg.Args {
|
|
86
|
-
var entry
|
|
87
|
-
|
|
86
|
+
var entry agoric.KVEntry
|
|
87
|
+
err = json.Unmarshal(arg, &entry)
|
|
88
88
|
if err != nil {
|
|
89
89
|
return
|
|
90
90
|
}
|
|
@@ -95,8 +95,8 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
95
95
|
|
|
96
96
|
case "setWithoutNotify":
|
|
97
97
|
for _, arg := range msg.Args {
|
|
98
|
-
var entry
|
|
99
|
-
|
|
98
|
+
var entry agoric.KVEntry
|
|
99
|
+
err = json.Unmarshal(arg, &entry)
|
|
100
100
|
if err != nil {
|
|
101
101
|
return
|
|
102
102
|
}
|
|
@@ -106,16 +106,16 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
106
106
|
|
|
107
107
|
case "append":
|
|
108
108
|
for _, arg := range msg.Args {
|
|
109
|
-
var entry
|
|
110
|
-
|
|
109
|
+
var entry agoric.KVEntry
|
|
110
|
+
err = json.Unmarshal(arg, &entry)
|
|
111
111
|
if err != nil {
|
|
112
112
|
return
|
|
113
113
|
}
|
|
114
|
-
if !entry.
|
|
115
|
-
err = fmt.Errorf("no value for append entry with path: %q", entry.
|
|
114
|
+
if !entry.HasValue() {
|
|
115
|
+
err = fmt.Errorf("no value for append entry with path: %q", entry.Key())
|
|
116
116
|
return
|
|
117
117
|
}
|
|
118
|
-
err = keeper.AppendStorageValueAndNotify(cctx.Context, entry.
|
|
118
|
+
err = keeper.AppendStorageValueAndNotify(cctx.Context, entry.Key(), entry.StringValue())
|
|
119
119
|
if err != nil {
|
|
120
120
|
return
|
|
121
121
|
}
|
|
@@ -131,10 +131,7 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
entry := keeper.GetEntry(cctx.Context, path)
|
|
134
|
-
|
|
135
|
-
return "null", nil
|
|
136
|
-
}
|
|
137
|
-
bz, err := json.Marshal(entry.StringValue())
|
|
134
|
+
bz, err := json.Marshal(entry.Value())
|
|
138
135
|
if err != nil {
|
|
139
136
|
return "", err
|
|
140
137
|
}
|
|
@@ -194,13 +191,13 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
194
191
|
return
|
|
195
192
|
}
|
|
196
193
|
children := keeper.GetChildren(cctx.Context, path)
|
|
197
|
-
entries := make([]
|
|
194
|
+
entries := make([]agoric.KVEntry, len(children.Children))
|
|
198
195
|
for i, child := range children.Children {
|
|
199
196
|
entry := keeper.GetEntry(cctx.Context, fmt.Sprintf("%s.%s", path, child))
|
|
200
|
-
if !entry.
|
|
201
|
-
entries[i] =
|
|
197
|
+
if !entry.HasValue() {
|
|
198
|
+
entries[i] = agoric.NewKVEntryWithNoValue(child)
|
|
202
199
|
} else {
|
|
203
|
-
entries[i] =
|
|
200
|
+
entries[i] = agoric.NewKVEntry(child, entry.StringValue())
|
|
204
201
|
}
|
|
205
202
|
}
|
|
206
203
|
bytes, err := json.Marshal(entries)
|
|
@@ -216,9 +213,9 @@ func (sh vstorageHandler) Receive(cctx *vm.ControllerContext, str string) (ret s
|
|
|
216
213
|
return
|
|
217
214
|
}
|
|
218
215
|
children := keeper.GetChildren(cctx.Context, path)
|
|
219
|
-
vals := make([]string, len(children.Children))
|
|
216
|
+
vals := make([]*string, len(children.Children))
|
|
220
217
|
for i, child := range children.Children {
|
|
221
|
-
vals[i] = keeper.GetEntry(cctx.Context, fmt.Sprintf("%s.%s", path, child)).
|
|
218
|
+
vals[i] = keeper.GetEntry(cctx.Context, fmt.Sprintf("%s.%s", path, child)).Value()
|
|
222
219
|
}
|
|
223
220
|
bytes, err := json.Marshal(vals)
|
|
224
221
|
if err != nil {
|
|
@@ -70,10 +70,10 @@ func TestGetAndHas(t *testing.T) {
|
|
|
70
70
|
kit := makeTestKit()
|
|
71
71
|
keeper, handler, ctx, cctx := kit.keeper, kit.handler, kit.ctx, kit.cctx
|
|
72
72
|
|
|
73
|
-
keeper.SetStorage(ctx,
|
|
74
|
-
keeper.SetStorage(ctx,
|
|
75
|
-
keeper.SetStorage(ctx,
|
|
76
|
-
keeper.SetStorage(ctx,
|
|
73
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("foo", "bar"))
|
|
74
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("empty", ""))
|
|
75
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("top.empty-non-terminal.leaf", ""))
|
|
76
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntryWithNoValue("top.empty-non-terminal"))
|
|
77
77
|
|
|
78
78
|
type testCase struct {
|
|
79
79
|
label string
|
|
@@ -153,7 +153,7 @@ func doTestSet(t *testing.T, method string, expectNotify bool) {
|
|
|
153
153
|
// TODO: Fully validate input before making changes
|
|
154
154
|
// args: []interface{}{[]string{"foo", "X"}, []interface{}{42, "new"}},
|
|
155
155
|
args: []interface{}{[]interface{}{42, "new"}},
|
|
156
|
-
errContains: ptr("
|
|
156
|
+
errContains: ptr("json"),
|
|
157
157
|
},
|
|
158
158
|
{label: "non-string value",
|
|
159
159
|
// TODO: Fully validate input before making changes
|
|
@@ -259,15 +259,15 @@ func TestEntries(t *testing.T) {
|
|
|
259
259
|
kit := makeTestKit()
|
|
260
260
|
keeper, handler, ctx, cctx := kit.keeper, kit.handler, kit.ctx, kit.cctx
|
|
261
261
|
|
|
262
|
-
keeper.SetStorage(ctx,
|
|
263
|
-
keeper.SetStorage(ctx,
|
|
264
|
-
keeper.SetStorage(ctx,
|
|
265
|
-
keeper.SetStorage(ctx,
|
|
266
|
-
keeper.SetStorage(ctx,
|
|
267
|
-
keeper.SetStorage(ctx,
|
|
268
|
-
keeper.SetStorage(ctx,
|
|
269
|
-
keeper.SetStorage(ctx,
|
|
270
|
-
keeper.SetStorage(ctx,
|
|
262
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("key1", "value1"))
|
|
263
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("key1.child1.grandchild1", "value1grandchild"))
|
|
264
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntryWithNoValue("key1.child1.grandchild2"))
|
|
265
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntryWithNoValue("key1.child1"))
|
|
266
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("key1.child1.empty-non-terminal.leaf", ""))
|
|
267
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntryWithNoValue("key2"))
|
|
268
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntryWithNoValue("key2.child2"))
|
|
269
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("key2.child2.grandchild2", "value2grandchild"))
|
|
270
|
+
keeper.SetStorage(ctx, agorictypes.NewKVEntry("key2.child2.grandchild2a", "value2grandchilda"))
|
|
271
271
|
|
|
272
272
|
type testCase struct {
|
|
273
273
|
path string
|