agoric 0.21.2-other-dev-3eb1a1d.0 → 0.21.2-other-dev-fbe72e7.0.fbe72e7

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.
@@ -7,6 +7,7 @@ import {
7
7
  makeFollower,
8
8
  makeLeaderFromRpcAddresses,
9
9
  } from '@agoric/casting';
10
+ import { fetchEnvNetworkConfig } from '@agoric/client-utils';
10
11
  import { slotToRemotable } from '@agoric/internal/src/storage-test-utils.js';
11
12
  import { boardSlottingMarshaller } from '@agoric/vats/tools/board-utils.js';
12
13
  import { Command } from 'commander';
@@ -17,12 +18,11 @@ import {
17
18
  execSwingsetTransaction,
18
19
  normalizeAddressWithOptions,
19
20
  } from '../lib/chain.js';
20
- import { getNetworkConfig } from '../lib/network-config.js';
21
21
 
22
22
  // tight for perf testing but less than this tends to hang.
23
23
  const SLEEP_SECONDS = 0.1;
24
24
 
25
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
25
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
26
26
 
27
27
  /**
28
28
  * @param {import('anylogger').Logger} logger
@@ -51,6 +51,7 @@ export const makePerfCommand = logger => {
51
51
  'address literal or name',
52
52
  normalizeAddress,
53
53
  )
54
+ .option('--verbose')
54
55
  .action(async function (opts) {
55
56
  const sharedOpts = perf.opts();
56
57
  logger.warn({ sharedOpts, opts });
@@ -63,15 +64,13 @@ export const makePerfCommand = logger => {
63
64
 
64
65
  const spec = `:published.wallet.${opts.from}`;
65
66
 
66
- const leaderOptions = makeLeaderOptions({
67
- sleep: SLEEP_SECONDS,
68
- jitter: 0,
69
- log: () => undefined,
70
- });
71
-
72
67
  const leader = makeLeaderFromRpcAddresses(
73
68
  networkConfig.rpcAddrs,
74
- leaderOptions,
69
+ makeLeaderOptions({
70
+ sleep: SLEEP_SECONDS,
71
+ jitter: 0,
72
+ log: console.warn,
73
+ }),
75
74
  );
76
75
 
77
76
  logger.warn('Following', spec);
@@ -86,9 +85,10 @@ export const makePerfCommand = logger => {
86
85
  if (status.error) {
87
86
  console.error(status.error);
88
87
  exit(1);
89
- } else if (status.numWantsSatisfied)
88
+ } else if (status.numWantsSatisfied) {
90
89
  process.stdout.write(`satisfied: ${status.numWantsSatisfied}\n`);
91
- exit(0);
90
+ exit(0);
91
+ }
92
92
  }
93
93
  }
94
94
  };
@@ -102,7 +102,11 @@ export const makePerfCommand = logger => {
102
102
  if (sharedOpts.home) {
103
103
  cmd.push(`--home=${sharedOpts.home}`);
104
104
  }
105
- execSwingsetTransaction(cmd, { from: opts.from, ...networkConfig });
105
+ execSwingsetTransaction(cmd, {
106
+ from: opts.from,
107
+ verbose: opts.verbose,
108
+ ...networkConfig,
109
+ });
106
110
  });
107
111
 
108
112
  return perf;
@@ -1,14 +1,18 @@
1
1
  // @ts-check
2
2
  /* eslint-disable func-names */
3
3
  /* eslint-env node */
4
- import { makeVstorageKit, storageHelper } from '@agoric/client-utils';
4
+ import {
5
+ fetchEnvNetworkConfig,
6
+ makeAgoricNames,
7
+ makeVstorageKit,
8
+ storageHelper,
9
+ } from '@agoric/client-utils';
5
10
  import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
6
11
  import { Command } from 'commander';
7
- import { getNetworkConfig } from '../lib/network-config.js';
8
- import { outputExecuteOfferAction } from '../lib/wallet.js';
9
12
  import { asPercent } from '../lib/format.js';
13
+ import { outputExecuteOfferAction } from '../lib/wallet.js';
10
14
 
11
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
15
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
12
16
 
13
17
  // Adapted from https://gist.github.com/dckc/8b5b2f16395cb4d7f2ff340e0bc6b610#file-psm-tool
14
18
 
@@ -63,13 +67,14 @@ export const makePsmCommand = logger => {
63
67
  );
64
68
 
65
69
  const rpcTools = async () => {
66
- const utils = await makeVstorageKit({ fetch }, networkConfig);
70
+ const vsk = await makeVstorageKit({ fetch }, networkConfig);
71
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
67
72
 
68
73
  const lookupPsmInstance = ([minted, anchor]) => {
69
74
  const name = `psm-${minted}-${anchor}`;
70
- const instance = utils.agoricNames.instance[name];
75
+ const instance = agoricNames.instance[name];
71
76
  if (!instance) {
72
- logger.debug('known instances:', utils.agoricNames.instance);
77
+ logger.debug('known instances:', agoricNames.instance);
73
78
  throw Error(`Unknown instance ${name}`);
74
79
  }
75
80
  return instance;
@@ -80,20 +85,19 @@ export const makePsmCommand = logger => {
80
85
  * @param {[Minted: string, Anchor: string]} pair
81
86
  */
82
87
  const getGovernanceState = async ([Minted, Anchor]) => {
83
- const govContent = await utils.vstorage.readLatest(
88
+ const govContent = await vsk.vstorage.readLatest(
84
89
  `published.psm.${Minted}.${Anchor}.governance`,
85
90
  );
86
91
  assert(govContent, 'no gov content');
87
92
  const { current: governance } = last(
88
- storageHelper.unserializeTxt(govContent, utils.fromBoard),
93
+ storageHelper.unserializeTxt(govContent, vsk.fromBoard),
89
94
  );
90
- const { [`psm.${Minted}.${Anchor}`]: instance } =
91
- utils.agoricNames.instance;
95
+ const { [`psm.${Minted}.${Anchor}`]: instance } = agoricNames.instance;
92
96
 
93
97
  return { instance, governance };
94
98
  };
95
99
 
96
- return { ...utils, lookupPsmInstance, getGovernanceState };
100
+ return { ...vsk, agoricNames, lookupPsmInstance, getGovernanceState };
97
101
  };
98
102
 
99
103
  psm
@@ -1,13 +1,16 @@
1
1
  // @ts-check
2
2
  /* eslint-disable func-names */
3
3
  /* eslint-env node */
4
- import { makeVstorageKit } from '@agoric/client-utils';
4
+ import {
5
+ fetchEnvNetworkConfig,
6
+ makeAgoricNames,
7
+ makeVstorageKit,
8
+ } from '@agoric/client-utils';
5
9
  import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
6
10
  import { Command } from 'commander';
7
- import { getNetworkConfig } from '../lib/network-config.js';
8
11
  import { outputActionAndHint } from '../lib/wallet.js';
9
12
 
10
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
13
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
11
14
 
12
15
  /**
13
16
  * @param {import('anylogger').Logger} _logger
@@ -32,7 +35,8 @@ export const makeReserveCommand = (_logger, io = {}) => {
32
35
  * }} opts
33
36
  */
34
37
  async ({ collateralBrand, ...opts }) => {
35
- const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig);
38
+ const vsk = makeVstorageKit({ fetch }, networkConfig);
39
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
36
40
 
37
41
  const offer = Offers.reserve.AddCollateral(agoricNames, {
38
42
  collateralBrandKey: collateralBrand,
@@ -66,7 +70,8 @@ export const makeReserveCommand = (_logger, io = {}) => {
66
70
  1,
67
71
  )
68
72
  .action(async function (opts) {
69
- const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig);
73
+ const vsk = makeVstorageKit({ fetch }, networkConfig);
74
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
70
75
 
71
76
  const reserveInstance = agoricNames.instance.reserve;
72
77
  assert(reserveInstance, 'missing reserve in names');
@@ -1,12 +1,11 @@
1
1
  // @ts-check
2
2
  /* eslint-env node */
3
- import { makeWalletUtils } from '@agoric/client-utils';
3
+ import { fetchEnvNetworkConfig, makeWalletUtils } from '@agoric/client-utils';
4
4
  import { Fail } from '@endo/errors';
5
5
  import { CommanderError } from 'commander';
6
6
  import { normalizeAddressWithOptions } from '../lib/chain.js';
7
- import { getNetworkConfig } from '../lib/network-config.js';
8
- import { sendAction } from '../lib/wallet.js';
9
7
  import { bigintReplacer } from '../lib/format.js';
8
+ import { sendAction } from '../lib/wallet.js';
10
9
 
11
10
  /**
12
11
  * Make commands for testing.
@@ -39,7 +38,7 @@ export const makeTestCommand = (
39
38
  try {
40
39
  // XXX pass fetch to getNetworkConfig() explicitly
41
40
  // await null above makes this await safe
42
- const networkConfig = await getNetworkConfig({ env, fetch });
41
+ const networkConfig = await fetchEnvNetworkConfig({ env, fetch });
43
42
  return makeWalletUtils({ fetch, delay }, networkConfig);
44
43
  } catch (err) {
45
44
  // CommanderError is a class constructor, and so
@@ -1,7 +1,11 @@
1
1
  // @ts-check
2
2
  /* eslint-disable func-names */
3
3
  /* eslint-env node */
4
- import { makeVstorageKit } from '@agoric/client-utils';
4
+ import {
5
+ fetchEnvNetworkConfig,
6
+ makeAgoricNames,
7
+ makeVstorageKit,
8
+ } from '@agoric/client-utils';
5
9
  import {
6
10
  lookupOfferIdForVault,
7
11
  Offers,
@@ -9,9 +13,8 @@ import {
9
13
  import { Command } from 'commander';
10
14
  import { normalizeAddressWithOptions } from '../lib/chain.js';
11
15
  import { getCurrent, outputExecuteOfferAction } from '../lib/wallet.js';
12
- import { getNetworkConfig } from '../lib/network-config.js';
13
16
 
14
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
17
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
15
18
 
16
19
  /**
17
20
  * @param {import('anylogger').Logger} logger
@@ -64,7 +67,8 @@ export const makeVaultsCommand = logger => {
64
67
  .option('--collateralBrand <string>', 'Collateral brand key', 'ATOM')
65
68
  .action(async function (opts) {
66
69
  logger.warn('running with options', opts);
67
- const { agoricNames } = await makeVstorageKit({ fetch }, networkConfig);
70
+ const vsk = makeVstorageKit({ fetch }, networkConfig);
71
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
68
72
 
69
73
  const offer = Offers.vaults.OpenVault(agoricNames, {
70
74
  giveCollateral: opts.giveCollateral,
@@ -99,10 +103,11 @@ export const makeVaultsCommand = logger => {
99
103
  .requiredOption('--vaultId <string>', 'Key of vault (e.g. vault1)')
100
104
  .action(async function (opts) {
101
105
  logger.warn('running with options', opts);
102
- const { agoricNames, readPublished } = await makeVstorageKit(
106
+ const { readPublished, ...vsk } = makeVstorageKit(
103
107
  { fetch },
104
108
  networkConfig,
105
109
  );
110
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
106
111
 
107
112
  const previousOfferId = await lookupOfferIdForVault(
108
113
  opts.vaultId,
@@ -143,10 +148,11 @@ export const makeVaultsCommand = logger => {
143
148
  )
144
149
  .action(async function (opts) {
145
150
  logger.warn('running with options', opts);
146
- const { agoricNames, readPublished } = await makeVstorageKit(
151
+ const { readPublished, ...vsk } = makeVstorageKit(
147
152
  { fetch },
148
153
  networkConfig,
149
154
  );
155
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
150
156
 
151
157
  const previousOfferId = await lookupOfferIdForVault(
152
158
  opts.vaultId,
@@ -8,7 +8,11 @@ import {
8
8
  makeLeader,
9
9
  makeLeaderFromRpcAddresses,
10
10
  } from '@agoric/casting';
11
- import { makeVstorageKit } from '@agoric/client-utils';
11
+ import {
12
+ makeVstorageKit,
13
+ fetchEnvNetworkConfig,
14
+ makeAgoricNames,
15
+ } from '@agoric/client-utils';
12
16
  import { execFileSync } from 'child_process';
13
17
  import fs from 'fs';
14
18
  import util from 'util';
@@ -19,15 +23,14 @@ import {
19
23
  fetchSwingsetParams,
20
24
  normalizeAddressWithOptions,
21
25
  } from '../lib/chain.js';
22
- import { getNetworkConfig } from '../lib/network-config.js';
23
- import { coalesceWalletState, getCurrent } from '../lib/wallet.js';
24
26
  import {
25
- summarize,
26
27
  fmtRecordOfLines,
27
28
  parseFiniteNumber,
29
+ summarize,
28
30
  } from '../lib/format.js';
31
+ import { coalesceWalletState, getCurrent } from '../lib/wallet.js';
29
32
 
30
- const networkConfig = await getNetworkConfig({ env: process.env, fetch });
33
+ const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });
31
34
 
32
35
  const SLEEP_SECONDS = 3;
33
36
 
@@ -52,6 +55,7 @@ export const makeWalletCommand = async command => {
52
55
  'wallet commands',
53
56
  );
54
57
 
58
+ /** @param {string} literalOrName */
55
59
  const normalizeAddress = literalOrName =>
56
60
  normalizeAddressWithOptions(literalOrName, wallet.opts());
57
61
 
@@ -64,7 +68,8 @@ export const makeWalletCommand = async command => {
64
68
  )
65
69
  .option('--spend', 'confirm you want to spend')
66
70
  .option('--nickname <string>', 'nickname to use', 'my-wallet')
67
- .action(function (opts) {
71
+ .action(async function (opts) {
72
+ await null;
68
73
  /** @typedef {{account: string, spend?: boolean, nickname: 'my-wallet' | string }} Opts */
69
74
  const {
70
75
  account,
@@ -81,12 +86,12 @@ export const makeWalletCommand = async command => {
81
86
  ...networkConfig,
82
87
  });
83
88
  } else {
84
- const params = fetchSwingsetParams(networkConfig);
89
+ const params = await fetchSwingsetParams(networkConfig);
85
90
  assert(
86
- params.power_flag_fees.length === 1,
91
+ params.powerFlagFees.length === 1,
87
92
  'multiple power_flag_fees not supported',
88
93
  );
89
- const { fee: fees } = params.power_flag_fees[0];
94
+ const { fee: fees } = params.powerFlagFees[0];
90
95
  const nf = new Intl.NumberFormat('en-US');
91
96
  const costs = fees
92
97
  .map(f => `${nf.format(Number(f.amount))} ${f.denom}`)
@@ -109,9 +114,9 @@ export const makeWalletCommand = async command => {
109
114
  .action(async function (opts) {
110
115
  const offerStr = fs.readFileSync(opts.file).toString();
111
116
 
112
- const { unserializer } = await makeVstorageKit({ fetch }, networkConfig);
117
+ const { marshaller } = makeVstorageKit({ fetch }, networkConfig);
113
118
 
114
- const offerObj = unserializer.fromCapData(JSON.parse(offerStr));
119
+ const offerObj = marshaller.fromCapData(JSON.parse(offerStr));
115
120
  console.log(offerObj);
116
121
  });
117
122
 
@@ -124,9 +129,9 @@ export const makeWalletCommand = async command => {
124
129
  .action(async function (opts) {
125
130
  const offerStr = fs.readFileSync(opts.offer).toString();
126
131
 
127
- const { unserializer } = await makeVstorageKit({ fetch }, networkConfig);
132
+ const { marshaller } = makeVstorageKit({ fetch }, networkConfig);
128
133
 
129
- const offerObj = unserializer.fromCapData(JSON.parse(offerStr));
134
+ const offerObj = marshaller.fromCapData(JSON.parse(offerStr));
130
135
  console.log(offerObj.offer.id);
131
136
  });
132
137
 
@@ -201,7 +206,7 @@ export const makeWalletCommand = async command => {
201
206
  .command('list')
202
207
  .description('list all wallets in vstorage')
203
208
  .action(async function () {
204
- const { vstorage } = await makeVstorageKit({ fetch }, networkConfig);
209
+ const { vstorage } = makeVstorageKit({ fetch }, networkConfig);
205
210
  const wallets = await vstorage.keys('published.wallet');
206
211
  process.stdout.write(wallets.join('\n'));
207
212
  });
@@ -215,19 +220,19 @@ export const makeWalletCommand = async command => {
215
220
  normalizeAddress,
216
221
  )
217
222
  .action(async function (opts) {
218
- const { agoricNames, unserializer, readPublished } =
219
- await makeVstorageKit(
220
- {
221
- fetch,
222
- },
223
- networkConfig,
224
- );
223
+ const {
224
+ readPublished,
225
+ marshaller: unserializer,
226
+ ...vsk
227
+ } = makeVstorageKit({ fetch }, networkConfig);
228
+ const agoricNames = await makeAgoricNames(vsk.fromBoard, vsk.vstorage);
225
229
 
226
230
  const leader = makeLeader(networkConfig.rpcAddrs[0]);
227
231
  const follower = await makeFollower(
228
232
  `:published.wallet.${opts.from}`,
229
233
  leader,
230
234
  {
235
+ // @ts-expect-error xxx follower/marshaller types
231
236
  unserializer,
232
237
  },
233
238
  );
@@ -274,15 +279,13 @@ export const makeWalletCommand = async command => {
274
279
  .action(async function ({ from }) {
275
280
  const spec = `:published.wallet.${from}`;
276
281
 
277
- const leaderOptions = makeLeaderOptions({
278
- sleep: SLEEP_SECONDS,
279
- jitter: 0,
280
- log: () => undefined,
281
- });
282
-
283
282
  const leader = makeLeaderFromRpcAddresses(
284
283
  networkConfig.rpcAddrs,
285
- leaderOptions,
284
+ makeLeaderOptions({
285
+ sleep: SLEEP_SECONDS,
286
+ jitter: 0,
287
+ log: console.warn,
288
+ }),
286
289
  );
287
290
 
288
291
  console.warn('Following', spec);
package/src/deploy.js CHANGED
@@ -190,6 +190,12 @@ const connectAndRun = async (
190
190
  return retryWebsocket().then(() => exit.promise);
191
191
  };
192
192
 
193
+ /**
194
+ * @param {string} progname
195
+ * @param {string[]} rawArgs
196
+ * @param {{ makeWebSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket; anylogger: (name: string) => Console; now?: () => number; fs?: any; }} powers
197
+ * @param {{ allowUnsafePlugins: any; provide: string; sdk: any; need: string; hostport: string; target: string | number | undefined; scriptArgs: any; }} opts
198
+ */
193
199
  export default async function deployMain(progname, rawArgs, powers, opts) {
194
200
  const { anylogger, now, fs } = powers;
195
201
  const console = anylogger('agoric:deploy');
@@ -238,7 +244,7 @@ export default async function deployMain(progname, rawArgs, powers, opts) {
238
244
 
239
245
  const match = opts.hostport.match(/^(.*):(\d+)$/);
240
246
  const host = match ? match[1] : 'localhost';
241
- const port = match ? match[2] : '8000';
247
+ const port = match ? +match[2] : 8000;
242
248
 
243
249
  const wsurl = opts.hostport.includes('//')
244
250
  ? new URL(opts.hostport, 'ws://localhost:8000')
package/src/entrypoint.js CHANGED
@@ -2,8 +2,6 @@
2
2
  /* eslint-env node */
3
3
  // @jessie-check
4
4
 
5
- import '@endo/init/pre.js';
6
- import 'esm';
7
5
  import '@endo/init/legacy.js';
8
6
 
9
7
  import path from 'path';
@@ -23,6 +21,7 @@ const log = anylogger('agoric');
23
21
  const progname = path.basename(process.argv[1]);
24
22
 
25
23
  const stdout = str => process.stdout.write(str);
24
+ /** @type {(...args: ConstructorParameters<typeof WebSocket>) => WebSocket} */
26
25
  const makeWebSocket = (...args) => new WebSocket(...args);
27
26
 
28
27
  const rawArgs = process.argv.slice(2);
package/src/follow.js CHANGED
@@ -126,16 +126,17 @@ export default async function followerMain(progname, rawArgs, powers, opts) {
126
126
  });
127
127
  }
128
128
 
129
- const leaderOptions = makeLeaderOptions({
130
- sleep,
131
- jitter,
132
- log: verbose ? console.warn : () => undefined,
133
- });
134
-
135
129
  const [_cmd, ...specs] = rawArgs;
136
130
 
137
131
  verbose && console.warn('Creating leader for', bootstrap);
138
- const leader = makeLeader(bootstrap, leaderOptions);
132
+ const leader = makeLeader(
133
+ bootstrap,
134
+ makeLeaderOptions({
135
+ sleep,
136
+ jitter,
137
+ log: verbose ? console.warn : () => undefined,
138
+ }),
139
+ );
139
140
  const iterate = opts.lossy ? iterateLatest : iterateEach;
140
141
  await Promise.all(
141
142
  specs.map(async spec => {
package/src/helpers.js CHANGED
@@ -3,7 +3,8 @@
3
3
 
4
4
  /** @import { ChildProcess } from 'child_process' */
5
5
 
6
- export { getNetworkConfig } from './lib/network-config.js';
6
+ // Backwards compatibility
7
+ export { fetchEnvNetworkConfig as getNetworkConfig } from '@agoric/client-utils';
7
8
 
8
9
  export const getSDKBinaries = ({
9
10
  jsPfx = '../..',
package/src/install.js CHANGED
@@ -1,8 +1,10 @@
1
1
  /* eslint-env node */
2
2
  import path from 'path';
3
3
  import chalk from 'chalk';
4
+ import { execFileSync } from 'child_process';
4
5
  import { makePspawn } from './helpers.js';
5
6
  import DEFAULT_SDK_PACKAGE_NAMES from './sdk-package-names.js';
7
+ import { listWorkspaces } from './lib/packageManager.js';
6
8
 
7
9
  const REQUIRED_AGORIC_START_PACKAGES = [
8
10
  '@agoric/solo',
@@ -30,17 +32,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
30
32
  const rimraf = file => pspawn('rm', ['-rf', file]);
31
33
 
32
34
  async function getWorktreePackagePaths(cwd = '.', map = new Map()) {
33
- // run `yarn workspaces info` to get the list of directories to
34
- // use, instead of a hard-coded list
35
- const p = pspawn('yarn', ['workspaces', '--silent', 'info'], {
36
- cwd,
37
- stdio: ['inherit', 'pipe', 'inherit'],
38
- });
39
- const stdout = [];
40
- p.childProcess.stdout?.on('data', out => stdout.push(out));
41
- await p;
42
- const d = JSON.parse(Buffer.concat(stdout).toString('utf-8'));
43
- for (const [name, { location }] of Object.entries(d)) {
35
+ for (const { name, location } of listWorkspaces({ execFileSync }, cwd)) {
44
36
  map.set(name, path.resolve(cwd, location));
45
37
  }
46
38
  return map;
package/src/lib/chain.js CHANGED
@@ -2,9 +2,11 @@
2
2
  /* eslint-env node */
3
3
  import { normalizeBech32 } from '@cosmjs/encoding';
4
4
  import { execFileSync as execFileSyncAmbient } from 'child_process';
5
+ import { makeAgoricQueryClient } from '@agoric/client-utils';
5
6
 
6
7
  /**
7
8
  * @import {MinimalNetworkConfig} from '@agoric/client-utils';
9
+ * @import {Params, ParamsSDKType} from '@agoric/cosmic-proto/agoric/swingset/swingset.js';
8
10
  */
9
11
 
10
12
  const agdBinary = 'agd';
@@ -132,21 +134,12 @@ harden(execSwingsetTransaction);
132
134
  /**
133
135
  *
134
136
  * @param {MinimalNetworkConfig} net
137
+ * @returns {Promise<Params>}
135
138
  */
136
- // TODO fetch by HTTP instead of shelling out https://github.com/Agoric/agoric-sdk/issues/9200
137
- export const fetchSwingsetParams = net => {
138
- const { chainName, rpcAddrs } = net;
139
- const cmd = [
140
- `--node=${rpcAddrs[0]}`,
141
- `--chain-id=${chainName}`,
142
- 'query',
143
- 'swingset',
144
- 'params',
145
- '--output',
146
- 'json',
147
- ];
148
- const buffer = execFileSyncAmbient(agdBinary, cmd);
149
- return JSON.parse(buffer.toString());
139
+ export const fetchSwingsetParams = async net => {
140
+ const client = await makeAgoricQueryClient(net);
141
+ const { params } = await client.agoric.swingset.params();
142
+ return params;
150
143
  };
151
144
  harden(fetchSwingsetParams);
152
145
 
@@ -170,9 +163,8 @@ export const pollBlocks = opts => async lookup => {
170
163
  for (;;) {
171
164
  const sTxt = execFileSync(agdBinary, ['status', ...nodeArgs]);
172
165
  const status = JSON.parse(sTxt.toString());
173
- const {
174
- SyncInfo: { latest_block_time: time, latest_block_height: height },
175
- } = status;
166
+ const { latest_block_time: time, latest_block_height: height } =
167
+ status.sync_info || status.SyncInfo;
176
168
  try {
177
169
  // see await null above
178
170
  const result = await lookup({ time, height });
@@ -198,7 +190,7 @@ export const pollBlocks = opts => async lookup => {
198
190
  * }} opts
199
191
  */
200
192
  export const pollTx = async (txhash, opts) => {
201
- const { execFileSync, rpcAddrs, chainName } = opts;
193
+ const { execFileSync, rpcAddrs } = opts;
202
194
 
203
195
  const nodeArgs = [`--node=${rpcAddrs[0]}`];
204
196
  const outJson = ['--output', 'json'];
@@ -206,15 +198,8 @@ export const pollTx = async (txhash, opts) => {
206
198
  const lookup = async () => {
207
199
  const out = execFileSync(
208
200
  agdBinary,
209
- [
210
- 'query',
211
- 'tx',
212
- txhash,
213
- `--chain-id=${chainName}`,
214
- ...nodeArgs,
215
- ...outJson,
216
- ],
217
- { stdio: ['ignore', 'pipe', 'ignore'] },
201
+ ['query', 'tx', txhash, ...nodeArgs, ...outJson],
202
+ { stdio: ['ignore', 'pipe', 'pipe'] },
218
203
  );
219
204
  // XXX this type is defined in a .proto file somewhere
220
205
  /** @type {{ height: string, txhash: string, code: number, timestamp: string }} */
@@ -0,0 +1,7 @@
1
+ /** @file Utility library for use in other packages */
2
+
3
+ export * from './bundles.js';
4
+ export * from './casting.js';
5
+ export * from './chain.js';
6
+ export * from './format.js';
7
+ export * from './wallet.js';
@@ -0,0 +1,24 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @import { execFileSync } from 'child_process';
5
+ */
6
+
7
+ /**
8
+ * Omits the root
9
+ *
10
+ * @param {{ execFileSync: execFileSync }} io
11
+ * @param {string} [root]
12
+ * @returns {Array<{ location: string, name: string }>}
13
+ */
14
+ export const listWorkspaces = ({ execFileSync }, root) => {
15
+ const out = execFileSync('npm', ['query', '.workspace'], {
16
+ stdio: ['ignore', 'pipe', 'inherit'],
17
+ shell: true,
18
+ encoding: 'utf-8',
19
+ cwd: root,
20
+ });
21
+ /** @type {Array<{ location: string, name: string, description: string }>} */
22
+ const result = JSON.parse(out);
23
+ return result.filter(({ location }) => location !== '.');
24
+ };
package/src/lib/wallet.js CHANGED
@@ -149,7 +149,7 @@ export const coalesceWalletState = async (follower, invitationBrand) => {
149
149
  * fees?: string,
150
150
  * verbose?: boolean,
151
151
  * keyring?: {home?: string, backend: string},
152
- * stdout: Pick<import('stream').Writable, 'write'>,
152
+ * stdout?: Pick<import('stream').Writable, 'write'>,
153
153
  * execFileSync: typeof import('child_process').execFileSync,
154
154
  * delay: (ms: number) => Promise<void>,
155
155
  * dryRun?: boolean,