@agoric/cosmos 0.34.2-dev-7cc5def.0 → 0.35.0-u11.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 +45 -0
- package/app/app.go +10 -1
- package/cmd/agd/main.go +5 -2
- package/daemon/cmd/root.go +93 -3
- package/git-revision.txt +1 -1
- package/package.json +3 -3
- package/proto/agoric/vstorage/query.proto +1 -53
- package/x/swingset/genesis.go +88 -15
- package/x/swingset/keeper/swing_store_exports_handler.go +64 -42
- package/x/swingset/module.go +22 -10
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/vibc/ibc.go +2 -1
- package/x/vibc/keeper/keeper.go +15 -1
- package/x/vibc/types/expected_keepers.go +1 -2
- 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/README.md +0 -95
- 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
package/x/swingset/module.go
CHANGED
|
@@ -80,18 +80,22 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
|
|
80
80
|
|
|
81
81
|
type AppModule struct {
|
|
82
82
|
AppModuleBasic
|
|
83
|
-
keeper
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
keeper Keeper
|
|
84
|
+
swingStoreExportsHandler *SwingStoreExportsHandler
|
|
85
|
+
setBootstrapNeeded func()
|
|
86
|
+
ensureControllerInited func(sdk.Context)
|
|
87
|
+
swingStoreExportDir string
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
// NewAppModule creates a new AppModule Object
|
|
89
|
-
func NewAppModule(k Keeper, setBootstrapNeeded func(), ensureControllerInited func(sdk.Context)) AppModule {
|
|
91
|
+
func NewAppModule(k Keeper, swingStoreExportsHandler *SwingStoreExportsHandler, setBootstrapNeeded func(), ensureControllerInited func(sdk.Context), swingStoreExportDir string) AppModule {
|
|
90
92
|
am := AppModule{
|
|
91
|
-
AppModuleBasic:
|
|
92
|
-
keeper:
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
AppModuleBasic: AppModuleBasic{},
|
|
94
|
+
keeper: k,
|
|
95
|
+
swingStoreExportsHandler: swingStoreExportsHandler,
|
|
96
|
+
setBootstrapNeeded: setBootstrapNeeded,
|
|
97
|
+
ensureControllerInited: ensureControllerInited,
|
|
98
|
+
swingStoreExportDir: swingStoreExportDir,
|
|
95
99
|
}
|
|
96
100
|
return am
|
|
97
101
|
}
|
|
@@ -150,10 +154,17 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V
|
|
|
150
154
|
return []abci.ValidatorUpdate{}
|
|
151
155
|
}
|
|
152
156
|
|
|
157
|
+
func (am AppModule) checkSwingStoreExportSetup() {
|
|
158
|
+
if am.swingStoreExportDir == "" {
|
|
159
|
+
panic(fmt.Errorf("SwingStore export dir not set"))
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
153
163
|
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
|
|
154
164
|
var genesisState types.GenesisState
|
|
155
165
|
cdc.MustUnmarshalJSON(data, &genesisState)
|
|
156
|
-
|
|
166
|
+
am.checkSwingStoreExportSetup()
|
|
167
|
+
bootstrapNeeded := InitGenesis(ctx, am.keeper, am.swingStoreExportsHandler, am.swingStoreExportDir, &genesisState)
|
|
157
168
|
if bootstrapNeeded {
|
|
158
169
|
am.setBootstrapNeeded()
|
|
159
170
|
}
|
|
@@ -161,6 +172,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.
|
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
|
|
164
|
-
|
|
175
|
+
am.checkSwingStoreExportSetup()
|
|
176
|
+
gs := ExportGenesis(ctx, am.keeper, am.swingStoreExportsHandler, am.swingStoreExportDir)
|
|
165
177
|
return cdc.MustMarshalJSON(gs)
|
|
166
178
|
}
|
|
@@ -50,7 +50,7 @@ var (
|
|
|
50
50
|
DefaultBeansPerMinFeeDebit = DefaultBeansPerFeeUnit.Quo(sdk.NewUint(5)) // $0.2
|
|
51
51
|
DefaultBeansPerStorageByte = DefaultBeansPerFeeUnit.Quo(sdk.NewUint(500)) // $0.002
|
|
52
52
|
|
|
53
|
-
DefaultBootstrapVatConfig = "@agoric/
|
|
53
|
+
DefaultBootstrapVatConfig = "@agoric/vats/decentral-core-config.json"
|
|
54
54
|
|
|
55
55
|
DefaultPowerFlagFees = []PowerFlagFee{
|
|
56
56
|
NewPowerFlagFee("SMART_WALLET", sdk.NewCoins(sdk.NewInt64Coin("ubld", 10_000_000))),
|
|
@@ -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:"
|
|
436
|
+
CompressedBundle []byte `protobuf:"bytes,3,opt,name=compressed_bundle,json=compressedBundle,proto3" json:"compressedBundle" yaml:"bcompressedBndle"`
|
|
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
|
-
//
|
|
556
|
+
// 789 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,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
0x4b, 0x08, 0x00, 0x00,
|
|
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,
|
|
607
607
|
}
|
|
608
608
|
|
|
609
609
|
// Reference imports to suppress errors if they are not otherwise used.
|
package/x/vibc/ibc.go
CHANGED
|
@@ -228,6 +228,7 @@ type channelOpenAckEvent struct {
|
|
|
228
228
|
Event string `json:"event"` // channelOpenAck
|
|
229
229
|
PortID string `json:"portID"`
|
|
230
230
|
ChannelID string `json:"channelID"`
|
|
231
|
+
CounterpartyChannelID string `json:"counterpartyChannelID"`
|
|
231
232
|
CounterpartyVersion string `json:"counterpartyVersion"`
|
|
232
233
|
Counterparty channeltypes.Counterparty `json:"counterparty"`
|
|
233
234
|
ConnectionHops []string `json:"connectionHops"`
|
|
@@ -246,12 +247,12 @@ func (im IBCModule) OnChanOpenAck(
|
|
|
246
247
|
// returns an empty channel object that we can still use without crashing.
|
|
247
248
|
channel, _ := im.keeper.GetChannel(ctx, portID, channelID)
|
|
248
249
|
|
|
249
|
-
channel.Counterparty.ChannelId = counterpartyChannelID
|
|
250
250
|
event := channelOpenAckEvent{
|
|
251
251
|
Type: "IBC_EVENT",
|
|
252
252
|
Event: "channelOpenAck",
|
|
253
253
|
PortID: portID,
|
|
254
254
|
ChannelID: channelID,
|
|
255
|
+
CounterpartyChannelID: counterpartyChannelID,
|
|
255
256
|
CounterpartyVersion: counterpartyVersion,
|
|
256
257
|
Counterparty: channel.Counterparty,
|
|
257
258
|
ConnectionHops: channel.ConnectionHops,
|
package/x/vibc/keeper/keeper.go
CHANGED
|
@@ -92,7 +92,13 @@ func (k Keeper) ChanOpenInit(ctx sdk.Context, order channeltypes.Order, connecti
|
|
|
92
92
|
return err
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
// We need to emit a channel event to notify the relayer.
|
|
96
|
+
ctx.EventManager().EmitEvents(sdk.Events{
|
|
97
|
+
sdk.NewEvent(
|
|
98
|
+
sdk.EventTypeMessage,
|
|
99
|
+
sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory),
|
|
100
|
+
),
|
|
101
|
+
})
|
|
96
102
|
return nil
|
|
97
103
|
}
|
|
98
104
|
|
|
@@ -151,6 +157,14 @@ func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
|
|
|
151
157
|
if err != nil {
|
|
152
158
|
return err
|
|
153
159
|
}
|
|
160
|
+
|
|
161
|
+
// We need to emit a channel event to notify the relayer.
|
|
162
|
+
ctx.EventManager().EmitEvents(sdk.Events{
|
|
163
|
+
sdk.NewEvent(
|
|
164
|
+
sdk.EventTypeMessage,
|
|
165
|
+
sdk.NewAttribute(sdk.AttributeKeyModule, channeltypes.AttributeValueCategory),
|
|
166
|
+
),
|
|
167
|
+
})
|
|
154
168
|
return nil
|
|
155
169
|
}
|
|
156
170
|
|
|
@@ -16,8 +16,7 @@ type ChannelKeeper interface {
|
|
|
16
16
|
WriteAcknowledgement(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error
|
|
17
17
|
ChanOpenInit(ctx sdk.Context, order channel.Order, connectionHops []string, portID string,
|
|
18
18
|
portCap *capability.Capability, counterparty channel.Counterparty, version string) (string, *capability.Capability, error)
|
|
19
|
-
|
|
20
|
-
connectionHops []string, counterparty channel.Counterparty, version string)
|
|
19
|
+
|
|
21
20
|
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capability.Capability) error
|
|
22
21
|
TimeoutExecuted(ctx sdk.Context, channelCap *capability.Capability, packet ibcexported.PacketI) error
|
|
23
22
|
}
|
|
@@ -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")
|