@agoric/client-utils 0.1.1-dev-8657c4c.0 → 0.1.1-dev-a2e9363.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.1.1-dev-8657c4c.0+8657c4c",
3
+ "version": "0.1.1-dev-a2e9363.0+a2e9363",
4
4
  "description": "Utilities for building Agoric clients",
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -27,11 +27,11 @@
27
27
  "ts-blank-space": "^0.4.1"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/casting": "0.4.3-dev-8657c4c.0+8657c4c",
31
- "@agoric/ertp": "0.16.3-dev-8657c4c.0+8657c4c",
32
- "@agoric/internal": "0.3.3-dev-8657c4c.0+8657c4c",
33
- "@agoric/smart-wallet": "0.5.4-dev-8657c4c.0+8657c4c",
34
- "@agoric/vats": "0.15.2-dev-8657c4c.0+8657c4c",
30
+ "@agoric/casting": "0.4.3-dev-a2e9363.0+a2e9363",
31
+ "@agoric/ertp": "0.16.3-dev-a2e9363.0+a2e9363",
32
+ "@agoric/internal": "0.3.3-dev-a2e9363.0+a2e9363",
33
+ "@agoric/smart-wallet": "0.5.4-dev-a2e9363.0+a2e9363",
34
+ "@agoric/vats": "0.15.2-dev-a2e9363.0+a2e9363",
35
35
  "@cosmjs/stargate": "^0.32.3",
36
36
  "@cosmjs/tendermint-rpc": "^0.32.3",
37
37
  "@endo/common": "^1.2.8",
@@ -58,5 +58,5 @@
58
58
  ],
59
59
  "timeout": "20m"
60
60
  },
61
- "gitHead": "8657c4cfc5dcb48602f730574afe5efb6f8ffb24"
61
+ "gitHead": "a2e936366843f74f9d101f3db4b1e76858abe3d7"
62
62
  }
package/src/cli.js ADDED
@@ -0,0 +1,20 @@
1
+ import { LOCAL_CONFIG_KEY, fetchNetworkConfig } from './network-config.js';
2
+
3
+ /**
4
+ * @import {MinimalNetworkConfig} from './network-config.js';
5
+ */
6
+
7
+ /**
8
+ * Fetch the network config for the AGORIC_NET environment variable.
9
+ *
10
+ * If none is set or it's 'local', return a local chain config.
11
+ *
12
+ * @param {{ env: typeof process.env, fetch: typeof fetch }} io
13
+ * @returns {Promise<MinimalNetworkConfig>}
14
+ */
15
+
16
+ export const fetchEnvNetworkConfig = async ({ env, fetch }) => {
17
+ const net = env.AGORIC_NET || LOCAL_CONFIG_KEY;
18
+
19
+ return fetchNetworkConfig(net, { fetch });
20
+ };
package/src/main.js CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './cli.js';
2
+ export * from './network-config.js';
1
3
  export * from './rpc.js';
2
4
  export * from './sync-tools.js';
3
5
  export * from './vstorage.js';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @typedef {{ rpcAddrs: string[], chainName: string }} MinimalNetworkConfig
3
+ */
4
+
5
+ export const toNetworkConfigUrl = agoricNetSubdomain =>
6
+ `https://${agoricNetSubdomain}.agoric.net/network-config`;
7
+
8
+ export const toRpcUrl = agoricNetSubdomain =>
9
+ `https://${agoricNetSubdomain}.rpc.agoric.net:443`;
10
+
11
+ /** @satisfies {MinimalNetworkConfig} */
12
+ export const LOCAL_CONFIG = {
13
+ rpcAddrs: ['http://0.0.0.0:26657'],
14
+ chainName: 'agoriclocal',
15
+ };
16
+
17
+ export const LOCAL_CONFIG_KEY = 'local';
18
+
19
+ /**
20
+ * Fetches the network config for the given network specifier.
21
+ *
22
+ * @param {string} spec
23
+ * @param {{ fetch: typeof fetch }} io
24
+ * @returns {Promise<MinimalNetworkConfig>}
25
+ */
26
+ export const fetchNetworkConfig = async (spec, { fetch }) => {
27
+ const [netName, chainName] = spec.split(',');
28
+
29
+ if (netName === LOCAL_CONFIG_KEY) {
30
+ return LOCAL_CONFIG;
31
+ }
32
+
33
+ if (chainName) {
34
+ return { chainName, rpcAddrs: [toRpcUrl(netName)] };
35
+ }
36
+
37
+ return fetch(toNetworkConfigUrl(netName))
38
+ .then(res => res.json())
39
+ .catch(err => {
40
+ throw Error(`cannot get network config (${spec}): ${err.message}`);
41
+ });
42
+ };
package/src/rpc.js CHANGED
@@ -3,7 +3,7 @@ import { StargateClient } from '@cosmjs/stargate';
3
3
  import { Tendermint34Client } from '@cosmjs/tendermint-rpc';
4
4
 
5
5
  /**
6
- * @typedef {{ rpcAddrs: string[], chainName: string }} MinimalNetworkConfig
6
+ * @import {MinimalNetworkConfig} from './network-config.js';
7
7
  */
8
8
 
9
9
  // TODO distribute load
@@ -7,7 +7,7 @@ import { makeVStorage } from './vstorage.js';
7
7
  export { boardSlottingMarshaller };
8
8
 
9
9
  /**
10
- * @import {MinimalNetworkConfig} from './rpc.js';
10
+ * @import {MinimalNetworkConfig} from './network-config.js';
11
11
  * @import {TypedPublished} from './types.js';
12
12
  * @import {VStorage} from './vstorage.js';
13
13
  */
package/src/vstorage.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* global Buffer */
2
2
 
3
3
  /**
4
- * @import {MinimalNetworkConfig} from './rpc.js';
4
+ * @import {MinimalNetworkConfig} from './network-config.js';
5
5
  */
6
6
 
7
7
  /**
@@ -6,7 +6,7 @@ import { boardSlottingMarshaller, makeVstorageKit } from './vstorage-kit.js';
6
6
  /**
7
7
  * @import {Amount, Brand} from '@agoric/ertp/src/types.js'
8
8
  * @import {CurrentWalletRecord, UpdateRecord} from '@agoric/smart-wallet/src/smartWallet.js';
9
- * @import {MinimalNetworkConfig} from './rpc.js';
9
+ * @import {MinimalNetworkConfig} from './network-config.js';
10
10
  */
11
11
 
12
12
  // XXX this is really a SmartWalletKit