@agoric/client-utils 0.2.0-upgrade-19-dev-5428c4d.0 → 0.2.0-upgrade-20-dev-ef71cfd.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/client-utils",
3
- "version": "0.2.0-upgrade-19-dev-5428c4d.0+5428c4d",
3
+ "version": "0.2.0-upgrade-20-dev-ef71cfd.0+ef71cfd",
4
4
  "description": "Utilities for building Agoric clients",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -27,19 +27,21 @@
27
27
  "ts-blank-space": "^0.4.4"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/casting": "0.4.3-upgrade-19-dev-5428c4d.0+5428c4d",
31
- "@agoric/ertp": "0.16.3-upgrade-19-dev-5428c4d.0+5428c4d",
32
- "@agoric/internal": "0.4.0-upgrade-19-dev-5428c4d.0+5428c4d",
33
- "@agoric/smart-wallet": "0.5.4-upgrade-19-dev-5428c4d.0+5428c4d",
34
- "@agoric/vats": "0.16.0-upgrade-19-dev-5428c4d.0+5428c4d",
35
- "@cosmjs/stargate": "^0.32.3",
36
- "@cosmjs/tendermint-rpc": "^0.32.3",
37
- "@endo/common": "^1.2.9",
38
- "@endo/errors": "^1.2.9",
39
- "@endo/marshal": "^1.6.3",
40
- "@endo/pass-style": "^1.4.8",
41
- "@endo/patterns": "^1.4.8",
42
- "@endo/promise-kit": "^1.1.9"
30
+ "@agoric/casting": "0.5.0-upgrade-20-dev-ef71cfd.0+ef71cfd",
31
+ "@agoric/cosmic-proto": "0.5.0-upgrade-20-dev-ef71cfd.0+ef71cfd",
32
+ "@agoric/ertp": "0.16.3-upgrade-20-dev-ef71cfd.0+ef71cfd",
33
+ "@agoric/internal": "0.4.0-upgrade-20-dev-ef71cfd.0+ef71cfd",
34
+ "@agoric/smart-wallet": "0.5.4-upgrade-20-dev-ef71cfd.0+ef71cfd",
35
+ "@agoric/vats": "0.16.0-upgrade-20-dev-ef71cfd.0+ef71cfd",
36
+ "@cosmjs/stargate": "^0.33.0",
37
+ "@cosmjs/tendermint-rpc": "^0.33.0",
38
+ "@endo/base64": "^1.0.9",
39
+ "@endo/common": "^1.2.10",
40
+ "@endo/errors": "^1.2.10",
41
+ "@endo/marshal": "^1.6.4",
42
+ "@endo/pass-style": "^1.5.0",
43
+ "@endo/patterns": "^1.5.0",
44
+ "@endo/promise-kit": "^1.1.10"
43
45
  },
44
46
  "ava": {
45
47
  "extensions": {
@@ -58,5 +60,5 @@
58
60
  ],
59
61
  "timeout": "20m"
60
62
  },
61
- "gitHead": "5428c4da67b53cef7ff53ba7b2a28cf6ec8f643a"
63
+ "gitHead": "ef71cfdc9e62572cab9a3d2821dc446ce0d700c3"
62
64
  }
package/src/types.d.ts CHANGED
@@ -10,7 +10,11 @@ import type {
10
10
  CurrentWalletRecord,
11
11
  UpdateRecord,
12
12
  } from '@agoric/smart-wallet/src/smartWallet.js';
13
- import type { ContractRecord, PoolMetrics } from '@agoric/fast-usdc';
13
+ import type {
14
+ ContractRecord,
15
+ PoolMetrics,
16
+ TransactionRecord,
17
+ } from '@agoric/fast-usdc';
14
18
 
15
19
  // For static string key types. String template matching has to be in the ternary below.
16
20
  type PublishedTypeMap = {
@@ -41,6 +45,10 @@ export type TypedPublished<T extends string> = T extends keyof PublishedTypeMap
41
45
  ? Array<[string, Brand]>
42
46
  : T extends 'fastUsdc'
43
47
  ? ContractRecord
44
- : T extends 'fastUsdc.poolMetrics'
45
- ? PoolMetrics
46
- : unknown;
48
+ : T extends 'fastUsdc.feeConfig'
49
+ ? FeeConfig
50
+ : T extends 'fastUsdc.poolMetrics'
51
+ ? PoolMetrics
52
+ : T extends `fastUsdc.txns.${string}`
53
+ ? TransactionRecord
54
+ : unknown;
package/src/vstorage.js CHANGED
@@ -1,26 +1,81 @@
1
- /* global Buffer */
1
+ import {
2
+ QueryChildrenRequest,
3
+ QueryChildrenResponse,
4
+ QueryDataRequest,
5
+ QueryDataResponse,
6
+ } from '@agoric/cosmic-proto/agoric/vstorage/query.js';
7
+ import { decodeBase64 } from '@endo/base64';
8
+ import { encodeHex } from '@agoric/internal/src/hex.js';
2
9
 
3
10
  /**
4
11
  * @import {MinimalNetworkConfig} from './network-config.js';
5
12
  */
6
13
 
14
+ const codecs = {
15
+ children: {
16
+ rpc: '/agoric.vstorage.Query/Children',
17
+ request: QueryChildrenRequest,
18
+ response: QueryChildrenResponse,
19
+ },
20
+ data: {
21
+ rpc: '/agoric.vstorage.Query/Data',
22
+ request: QueryDataRequest,
23
+ response: QueryDataResponse,
24
+ },
25
+ };
26
+
27
+ /** @typedef {(typeof codecs)[keyof typeof codecs]['response']} ResponseCodec */
28
+
7
29
  /**
8
30
  * @param {object} powers
9
31
  * @param {typeof window.fetch} powers.fetch
10
32
  * @param {MinimalNetworkConfig} config
11
33
  */
12
34
  export const makeVStorage = ({ fetch }, config) => {
13
- /** @param {string} path */
14
- const getJSON = path => {
35
+ /**
36
+ * @param {string} path
37
+ */
38
+ const getJSON = async path => {
15
39
  const url = config.rpcAddrs[0] + path;
16
40
  // console.warn('fetching', url);
17
- return fetch(url, { keepalive: true }).then(res => res.json());
41
+ const res = await fetch(url, { keepalive: true });
42
+ return res.json();
43
+ };
44
+
45
+ /**
46
+ * @template {keyof codecs} T
47
+ * @param {string} [path]
48
+ * @param {object} [opts]
49
+ * @param {T} [opts.kind]
50
+ * @param {number | bigint} [opts.height] 0 is the same as omitting height and implies the highest block
51
+ */
52
+ const url = (
53
+ path = 'published',
54
+ { kind = /** @type {T} */ ('children'), height = 0 } = {},
55
+ ) => {
56
+ const codec = codecs[kind];
57
+ if (!codec) {
58
+ throw Error(`unknown rpc kind: ${kind}`);
59
+ }
60
+
61
+ const { rpc, request } = codec;
62
+ const buf = request.toProto({ path });
63
+
64
+ const hexData = encodeHex(buf);
65
+ return `/abci_query?path=%22${rpc}%22&data=0x${hexData}&height=${height}`;
18
66
  };
19
- // height=0 is the same as omitting height and implies the highest block
20
- const url = (path = 'published', { kind = 'children', height = 0 } = {}) =>
21
- `/abci_query?path=%22/custom/vstorage/${kind}/${path}%22&height=${height}`;
22
67
 
23
- const readStorage = (path = 'published', { kind = 'children', height = 0 }) =>
68
+ /**
69
+ * @template {keyof codecs} T
70
+ * @param {string} [path]
71
+ * @param {object} [opts]
72
+ * @param {T} [opts.kind]
73
+ * @param {number | bigint} [opts.height] 0 is the same as omitting height and implies the highest block
74
+ */
75
+ const readStorage = (
76
+ path = 'published',
77
+ { kind = /** @type {T} */ ('children'), height = 0 } = {},
78
+ ) =>
24
79
  getJSON(url(path, { kind, height }))
25
80
  .catch(err => {
26
81
  throw Error(`cannot read ${kind} of ${path}: ${err.message}`);
@@ -38,18 +93,29 @@ export const makeVStorage = ({ fetch }, config) => {
38
93
  err.codespace = response?.codespace;
39
94
  throw err;
40
95
  }
41
- return data;
96
+
97
+ const codec = codecs[kind];
98
+ if (!codec) {
99
+ throw Error(`unknown codec for kind: ${kind}`);
100
+ }
101
+ return { ...data, codec: codec.response };
42
102
  });
43
103
 
44
104
  const vstorage = {
45
105
  url,
46
- decode({ result: { response } }) {
106
+ /**
107
+ * @param {{ result: { response: { value: string, code: number } }, codec?: ResponseCodec }} param0
108
+ */
109
+ decode({ result: { response }, codec }) {
47
110
  const { code } = response;
48
111
  if (code !== 0) {
49
112
  throw response;
50
113
  }
51
- const { value } = response;
52
- return Buffer.from(value, 'base64').toString();
114
+ const { value: b64Value } = response;
115
+ if (!codec) {
116
+ return atob(b64Value);
117
+ }
118
+ return JSON.stringify(codec.decode(decodeBase64(b64Value)));
53
119
  },
54
120
  /**
55
121
  *