@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.
@@ -1,160 +0,0 @@
1
- /*
2
- Package jsonrpcconn provides a way to multiplex an io stream into two
3
- streams where incoming JSON-RPC requests go to one stream and incoming
4
- JSON-RPC responses go to another. Outputs are merged.
5
-
6
- The JSON-RPCv1 protocol is peer-to-peer, but the implementation in the Go
7
- standard library only supports client-server. By multiplexing a single
8
- io.ReadWriteCloser stream into separate server (receives requests) and
9
- client (receives responses) streams, two RPC halves can share the same
10
- underlying connection.
11
- */
12
- package jsonrpcconn
13
-
14
- import (
15
- "encoding/json"
16
- "io"
17
- )
18
-
19
- // jsonRpcMsg can unmarshal either a JSON-RPC
20
- // request or response object.
21
- type jsonRpcMsg struct {
22
- Error json.RawMessage `json:"error"`
23
- Id json.RawMessage `json:"id"`
24
- Method *string `json:"method"`
25
- Params []json.RawMessage `json:"params"`
26
- Result json.RawMessage `json:"result"`
27
- }
28
-
29
- // mux holds the underlying connection and the pipe reader/writer
30
- // pairs for the server (request) and client (response) sides.
31
- // Any protocol error or closing any channel will cause shutdown.
32
- type mux struct {
33
- conn io.ReadWriteCloser
34
- reqReader *io.PipeReader
35
- reqWriter *io.PipeWriter
36
- respReader *io.PipeReader
37
- respWriter *io.PipeWriter
38
- }
39
-
40
- func newMux(conn io.ReadWriteCloser) mux {
41
- reqReader, reqWriter := io.Pipe()
42
- respReader, respWriter := io.Pipe()
43
- m := mux{
44
- conn: conn,
45
- reqReader: reqReader,
46
- reqWriter: reqWriter,
47
- respReader: respReader,
48
- respWriter: respWriter,
49
- }
50
- go m.input()
51
- return m
52
- }
53
-
54
- func (m mux) input() {
55
- var err error
56
- dec := json.NewDecoder(m.conn)
57
- for {
58
- // read the next JSON value, preserve its wire format
59
- var raw json.RawMessage
60
- err = dec.Decode(&raw)
61
- if err != nil {
62
- break
63
- }
64
-
65
- // parse as JSON-RPC
66
- var msg jsonRpcMsg
67
- err = json.Unmarshal(raw, &msg)
68
- if err != nil {
69
- break
70
- }
71
-
72
- // send to one of the outputs
73
- if msg.Method != nil {
74
- // presume a request, the consumer will handle any missing fields
75
- _, err = m.reqWriter.Write(raw)
76
- } else {
77
- // presume a response, the consumer will handle any missing fields
78
- _, err = m.respWriter.Write(raw)
79
- }
80
- if err != nil {
81
- break
82
- }
83
- }
84
- m.reqWriter.CloseWithError(err)
85
- m.respWriter.CloseWithError(err)
86
- m.conn.Close()
87
- }
88
-
89
- // clientChan is a view of the mux for the client channel.
90
- type clientChan mux
91
-
92
- // Close implements the io.Closer interface.
93
- func (c clientChan) Close() error {
94
- return c.conn.Close()
95
- }
96
-
97
- // Read implements the io.Reader interface.
98
- func (c clientChan) Read(p []byte) (int, error) {
99
- return c.respReader.Read(p)
100
- }
101
-
102
- // Write implements the io.Writer interface.
103
- func (c clientChan) Write(p []byte) (int, error) {
104
- return c.conn.Write(p)
105
- }
106
-
107
- // serverChan is a view of the mux for the server channel.
108
- type serverChan mux
109
-
110
- // Close implements the io.Closer interface.
111
- func (s serverChan) Close() error {
112
- return s.conn.Close()
113
- }
114
-
115
- // Read implements the io.Reader interface.
116
- func (s serverChan) Read(p []byte) (int, error) {
117
- return s.reqReader.Read(p)
118
- }
119
-
120
- // Write implements the io.Writer interface.
121
- func (s serverChan) Write(p []byte) (int, error) {
122
- return s.conn.Write(p)
123
- }
124
-
125
- // ClientServerConn multiplexes an input/output stream for the JSON-RPCv1
126
- // protocol into streams specific for client traffic and server traffic.
127
- // Full JSON objects must be written atomically to either stream to
128
- // interleave correctly.
129
- func ClientServerConn(conn io.ReadWriteCloser) (clientConn io.ReadWriteCloser, serverConn io.ReadWriteCloser) {
130
- m := newMux(conn)
131
- clientConn = clientChan(m)
132
- serverConn = serverChan(m)
133
- return
134
- }
135
-
136
- type conn struct {
137
- rd io.ReadCloser
138
- wr io.WriteCloser
139
- }
140
-
141
- // Close implments the io.Closer interface.
142
- func (e conn) Close() error {
143
- e.rd.Close()
144
- return e.wr.Close()
145
- }
146
-
147
- // Read implements the io.Reader interface.
148
- func (e conn) Read(p []byte) (int, error) {
149
- return e.rd.Read(p)
150
- }
151
-
152
- // Write implements the io.Writer interface.
153
- func (e conn) Write(p []byte) (int, error) {
154
- return e.wr.Write(p)
155
- }
156
-
157
- // NewConn returns a connection from a reader and a writer.
158
- func NewConn(rd io.ReadCloser, wr io.WriteCloser) io.ReadWriteCloser {
159
- return conn{rd: rd, wr: wr}
160
- }
@@ -1,126 +0,0 @@
1
- package jsonrpcconn_test
2
-
3
- import (
4
- "fmt"
5
- "net"
6
- "net/rpc"
7
- "net/rpc/jsonrpc"
8
- "testing"
9
-
10
- "github.com/Agoric/agoric-sdk/golang/cosmos/vm/jsonrpcconn"
11
- )
12
-
13
- /*
14
- type testConn struct {
15
- input *bytes.Buffer
16
- output *bytes.Buffer
17
- done chan struct{}
18
- }
19
-
20
- func newTestConn(input string) io.ReadWriteCloser {
21
- return testConn{
22
- input: bytes.NewBufferString(input),
23
- output: new(bytes.Buffer),
24
- done: make(chan struct{}),
25
- }
26
- }
27
-
28
- func (tc testConn) Read(p []byte) (int, error) {
29
- n, err := tc.input.Read(p)
30
- if err == io.EOF {
31
- <-tc.done
32
- }
33
- return n, err
34
- }
35
-
36
- func (tc testConn) Write(p []byte) (int, error) {
37
- return tc.output.Write(p)
38
- }
39
-
40
- func (tc testConn) Close() error {
41
- close(tc.done)
42
- return nil
43
- }
44
-
45
- func TestMux(t *testing.T) {
46
- input := `{"id": 1, "method": "foo", "params": [1, 2]}
47
- {"id": "aaa", "result": true, "error": null}
48
- {"id": null, "method": "bar", "params": ["string", 3, false]}`
49
- tc := newTestConn(input)
50
- client, server := jsonrpcconn.ClientServerConn(tc)
51
- client.Read
52
- var wg sync.WaitGroup
53
- wg.Add(2)
54
- go func() {
55
-
56
- }()
57
- wg.Wait()
58
- } */
59
-
60
- type Args struct {
61
- A, B int
62
- }
63
-
64
- type Arith struct{}
65
-
66
- func (a *Arith) Add(args Args, reply *int) error {
67
- *reply = args.A + args.B
68
- return nil
69
- }
70
-
71
- func (a *Arith) Mul(args Args, reply *int) error {
72
- *reply = args.A * args.B
73
- return nil
74
- }
75
-
76
- func (a *Arith) Oops(args Args, reply *int) error {
77
- return fmt.Errorf("oops")
78
- }
79
-
80
- func TestJsonRPC(t *testing.T) {
81
- left, right := net.Pipe()
82
- leftClientConn, leftServerConn := jsonrpcconn.ClientServerConn(left)
83
- rightClientConn, rightServerConn := jsonrpcconn.ClientServerConn(right)
84
-
85
- leftClient := jsonrpc.NewClient(leftClientConn)
86
- leftServer := rpc.NewServer()
87
- err := leftServer.RegisterName("foo", new(Arith))
88
- if err != nil {
89
- t.Fatal(err)
90
- }
91
- go leftServer.ServeCodec(jsonrpc.NewServerCodec(leftServerConn))
92
-
93
- rightClient := jsonrpc.NewClient(rightClientConn)
94
- rightServer := rpc.NewServer()
95
- err = rightServer.RegisterName("bar", new(Arith))
96
- if err != nil {
97
- t.Fatal(err)
98
- }
99
- go rightServer.ServeCodec(jsonrpc.NewServerCodec(rightServerConn))
100
-
101
- var reply int
102
- err = leftClient.Call("bar.Add", Args{1, 2}, &reply)
103
- if err != nil {
104
- t.Error(err)
105
- }
106
- if reply != 3 {
107
- t.Errorf("bar.Add want 3, got %d", reply)
108
- }
109
-
110
- err = rightClient.Call("foo.Mul", Args{2, 3}, &reply)
111
- if err != nil {
112
- t.Error(err)
113
- }
114
- if reply != 6 {
115
- t.Errorf("foo.Mul want 6, got %d", reply)
116
- }
117
-
118
- err = leftClient.Call("bar.Oops", Args{7, 11}, &reply)
119
- if err == nil {
120
- t.Errorf("bar.Oops want error, got reply %d", reply)
121
- } else if err.Error() != "oops" {
122
- t.Errorf(`bar.Oops want error "oops", got "%s"`, err.Error())
123
- }
124
- leftClient.Close()
125
- rightClient.Close()
126
- }
package/vm/server.go DELETED
@@ -1,23 +0,0 @@
1
- package vm
2
-
3
- import (
4
- "fmt"
5
- )
6
-
7
- type AgdServer struct {}
8
-
9
- func NewAgdServer() *AgdServer {
10
- return &AgdServer{}
11
- }
12
-
13
- // ReceiveMessage is the method the VM calls in order to have agd receive a
14
- // Message.
15
- func (s AgdServer) ReceiveMessage(msg *Message, reply *string) error {
16
- handler := portToHandler[msg.Port]
17
- if handler == nil {
18
- return fmt.Errorf("unregistered port %d", msg.Port)
19
- }
20
- resp, err := handler.Receive(controllerContext, msg.Data)
21
- *reply = resp
22
- return err
23
- }
@@ -1,140 +0,0 @@
1
- # Virtual Storage
2
-
3
- This module manages "[IAVL](https://github.com/cosmos/iavl)" chain storage data with a hierarchical keyspace in which each key is a "[path](./types/path_keys.go)" composed of zero or more dot-separated nonempty segments in a restricted alphabet. It exposes gRPC endpoints to arbitrary external clients for reading data, and internal read/write interfaces for use by SwingSet (which itself manages further subtree-scoped attenuation).
4
-
5
- ## Internal Go interface
6
-
7
- [Keeper](./keeper/keeper.go)
8
- * generic
9
- * GetChildren
10
- * GetEntry
11
- * HasEntry
12
- * HasStorage
13
- * SetStorage[AndNotify]
14
- * StreamCell-oriented (a StreamCell captures a block height and an array of values)
15
- * AppendStorageValue[AndNotify]
16
- * queue-oriented (a queue stores items at paths like "$prefix.$n", documenting
17
- the n for the next item to be consumed at "$prefix.head" and the n for the next
18
- next item to be pushed at "$prefix.tail" such that the queue is empty when both
19
- head and tail store the same n)
20
- * GetQueueLength
21
- * PushQueueItem
22
-
23
- ## Internal JSON interface
24
-
25
- This is used by the SwingSet "bridge".
26
-
27
- [Receive](./vstorage.go) with input `{ "method": "...", "args": [...] }`
28
- * generic
29
- * method "entries", args path
30
- * method "get"/"has", args path
31
- * method "set"/"setWithoutNotify", args [[path, value?], ...]
32
- * method "children", args path
33
- * method "values", args path (returns values for children in the same order as method "children")
34
- * method "size", args path (returns the count of children)
35
- * StreamCell-oriented
36
- * method "append", args [[path, value?], ...]
37
-
38
- ## CLI
39
-
40
- A blockchain node may be interrogated by RPC using `agd [--node $url] query vstorage $command` via [client/cli](./client/cli/query.go).
41
- * `children [--height $blockHeight] [-o {text,json}] [$path]`
42
- * `data [--height $blockHeight] [-o {text,json}] $path`
43
-
44
- Examples:
45
- ```sh
46
- $ agd --node https://main.rpc.agoric.net:443/ query vstorage children published.reserve
47
- children:
48
- - governance
49
- - metrics
50
- pagination: null
51
-
52
- $ agd --node https://main.rpc.agoric.net:443/ query vstorage children -o json published.reserve
53
- {"children":["governance","metrics"],"pagination":null}
54
-
55
- $ agd --node https://main.rpc.agoric.net:443/ query vstorage data published.reserve.metrics
56
- value: '{"blockHeight":"11030240","values":["{\"body\":\"#{\\\"allocations\\\":{\\\"Fee\\\":{\\\"brand\\\":\\\"$0.Alleged:
57
- IST brand\\\",\\\"value\\\":\\\"+20053582387\\\"}},\\\"shortfallBalance\\\":{\\\"brand\\\":\\\"$0\\\",\\\"value\\\":\\\"+0\\\"},\\\"totalFeeBurned\\\":{\\\"brand\\\":\\\"$0\\\",\\\"value\\\":\\\"+0\\\"},\\\"totalFeeMinted\\\":{\\\"brand\\\":\\\"$0\\\",\\\"value\\\":\\\"+0\\\"}}\",\"slots\":[\"board0257\"]}"]}'
58
- ```
59
-
60
- ## External protobuf interface
61
-
62
- RPC via [Querier](./keeper/grpc_query.go),
63
- and [CometBFT method "abci_query"](https://docs.cometbft.com/main/rpc/#/ABCI/abci_query)
64
- with params `path` "/agoric.vstorage.Query/..."
65
- and `data` \<serialized protobuf per [vstorage/query.proto](../../proto/agoric/vstorage/query.proto)>
66
- (also via [Querier](./keeper/grpc_query.go))
67
- * /agoric.vstorage.Query/CapData
68
- * /agoric.vstorage.Query/Children
69
- * /agoric.vstorage.Query/Data
70
-
71
- Example:
72
- ```sh
73
- $ curl -sS 'https://main.rpc.agoric.net/' -H 'Content-Type: application/json' -X POST --data "$(
74
- jq -n --arg queryChildrenRequestHex 0a147075626c69736865642e636f6d6d697474656573 '{
75
- id: 1,
76
- method: "abci_query",
77
- params: { path: "/agoric.vstorage.Query/Children", data: $queryChildrenRequestHex }
78
- }' | \
79
- tee /dev/stderr \
80
- )" | \
81
- jq . | \
82
- tee /dev/stderr | \
83
- jq -r '.result.response.value' | \
84
- base64 -d | \
85
- protoc -I golang/cosmos/proto/agoric/vstorage/ -I golang/cosmos/third_party/proto/ \
86
- --decode=agoric.vstorage.QueryChildrenResponse golang/cosmos/proto/agoric/vstorage/query.proto
87
- {
88
- "id": 1,
89
- "method": "abci_query",
90
- "params": {
91
- "path": "/agoric.vstorage.Query/Children",
92
- "data": "0a147075626c69736865642e636f6d6d697474656573"
93
- }
94
- }
95
- {
96
- "jsonrpc": "2.0",
97
- "id": 1,
98
- "result": {
99
- "response": {
100
- "code": 0,
101
- "log": "",
102
- "info": "",
103
- "index": "0",
104
- "key": null,
105
- "value": "ChJFY29ub21pY19Db21taXR0ZWUKCWtyZWFkLWdvdg==",
106
- "proofOps": null,
107
- "height": "12222836",
108
- "codespace": ""
109
- }
110
- }
111
- }
112
- children: "Economic_Committee"
113
- children: "kread-gov"
114
- ```
115
-
116
- ## External JSON interface
117
-
118
- As described at [Cosmos SDK: Using the REST Endpoints](https://docs.cosmos.network/main/run-node/interact-node#using-the-rest-endpoints), a blockchain node whose [`app.toml` configuration](https://docs.cosmos.network/main/run-node/run-node#configuring-the-node-using-apptoml-and-configtoml) enables the "REST" API server uses [gRPC-Gateway](https://grpc-ecosystem.github.io/grpc-gateway/) and `google.api.http` annotations in [vstorage/query.proto](../../proto/agoric/vstorage/query.proto) to automatically translate the protobuf-based RPC endpoints into URL paths that accept query parameters and emit JSON.
119
- * /agoric/vstorage/capdata/$path?remotableValueFormat={object,string}[&mediaType=JSON%20Lines][&itemFormat=flat]
120
- * /agoric/vstorage/children/$path
121
- * /agoric/vstorage/data/$path
122
-
123
- Example:
124
- ```sh
125
- $ curl -sS 'https://main.api.agoric.net/agoric/vstorage/children/published.committees'
126
- {
127
- "children": [
128
- "Economic_Committee"
129
- ],
130
- "pagination": null
131
- }
132
- ```
133
-
134
- ## Arbitrary-response HTTP interface
135
-
136
- This depends upon appModule `LegacyQuerierHandler` functionality that is [removed from cosmos-sdk as of v0.47](https://github.com/cosmos/cosmos-sdk/blob/fa4d87ef7e6d87aaccc94c337ffd2fe90fcb7a9d/CHANGELOG.md#api-breaking-changes-3)
137
-
138
- [legacy querier](./keeper/querier.go)
139
- * /custom/vstorage/children/$path
140
- * /custom/vstorage/data/$path