agoric 0.18.4 → 0.18.5-dev-800c2bb.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/README.md +73 -0
- package/package.json +37 -30
- package/src/bin-agops.js +68 -6
- package/src/chain-config.js +19 -2
- package/src/commands/auction.js +170 -0
- package/src/commands/ec.js +314 -0
- package/src/commands/inter.js +626 -0
- package/src/commands/oracle.js +212 -0
- package/src/commands/perf.js +32 -22
- package/src/commands/psm.js +75 -210
- package/src/commands/reserve.js +98 -0
- package/src/commands/test-upgrade.js +109 -0
- package/src/commands/vaults.js +161 -0
- package/src/commands/wallet.js +85 -60
- package/src/cosmos.js +5 -9
- package/src/deploy.js +208 -334
- package/src/entrypoint.js +9 -2
- package/src/follow.js +40 -4
- package/src/init.js +11 -10
- package/src/install.js +25 -30
- package/src/json-http-client-node.js +2 -2
- package/src/json.js +1 -1
- package/src/lib/casting.js +4 -2
- package/src/lib/chain.js +147 -33
- package/src/lib/format.js +58 -43
- package/src/lib/rpc.js +106 -101
- package/src/lib/wallet.js +305 -10
- package/src/main-publish.js +3 -5
- package/src/main.js +74 -42
- package/src/open.js +3 -1
- package/src/publish.js +25 -23
- package/src/run.js +20 -0
- package/src/scripts.js +190 -0
- package/src/sdk-package-names.js +6 -2
- package/src/set-defaults.js +2 -2
- package/src/start.js +69 -35
- package/src/lib/psm.js +0 -82
package/src/main.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* global process */
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import path from 'path';
|
|
5
|
+
import url from 'url';
|
|
5
6
|
import { assert, details as X } from '@agoric/assert';
|
|
6
7
|
import {
|
|
7
8
|
DEFAULT_KEEP_POLLING_SECONDS,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
} from '@agoric/casting';
|
|
10
11
|
import cosmosMain from './cosmos.js';
|
|
11
12
|
import deployMain from './deploy.js';
|
|
13
|
+
import runMain from './run.js';
|
|
12
14
|
import publishMain from './main-publish.js';
|
|
13
15
|
import initMain from './init.js';
|
|
14
16
|
import installMain from './install.js';
|
|
@@ -24,7 +26,7 @@ const DEFAULT_DAPP_BRANCH = undefined;
|
|
|
24
26
|
|
|
25
27
|
const STAMP = '_agstate';
|
|
26
28
|
|
|
27
|
-
const filename =
|
|
29
|
+
const filename = url.fileURLToPath(import.meta.url);
|
|
28
30
|
const dirname = path.dirname(filename);
|
|
29
31
|
|
|
30
32
|
const main = async (progname, rawArgs, powers) => {
|
|
@@ -51,9 +53,7 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
51
53
|
);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const pj = await fs.readFile(`${dirname}/../package.json`);
|
|
56
|
+
const pj = await fs.readFile(path.join(dirname, '..', 'package.json'));
|
|
57
57
|
const pkg = JSON.parse(pj);
|
|
58
58
|
program.name(pkg.name).version(pkg.version);
|
|
59
59
|
|
|
@@ -72,11 +72,24 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
72
72
|
program
|
|
73
73
|
.command('cosmos <command...>')
|
|
74
74
|
.description('client for an Agoric Cosmos chain')
|
|
75
|
-
.action(async (command, cmd) => {
|
|
75
|
+
.action(async (command, _options, cmd) => {
|
|
76
76
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
77
77
|
return subMain(cosmosMain, ['cosmos', ...command], opts);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
const ibcSetup = path.join(
|
|
81
|
+
dirname,
|
|
82
|
+
'..',
|
|
83
|
+
'node_modules',
|
|
84
|
+
'.bin',
|
|
85
|
+
'ibc-setup',
|
|
86
|
+
);
|
|
87
|
+
program.command(
|
|
88
|
+
'ibc-setup <command...>',
|
|
89
|
+
'set up Inter Blockchain Communication',
|
|
90
|
+
{ executableFile: ibcSetup },
|
|
91
|
+
);
|
|
92
|
+
|
|
80
93
|
program
|
|
81
94
|
.command('open')
|
|
82
95
|
.description('launch the Agoric UI')
|
|
@@ -98,7 +111,7 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
98
111
|
return value;
|
|
99
112
|
},
|
|
100
113
|
)
|
|
101
|
-
.action(async cmd => {
|
|
114
|
+
.action(async (_options, cmd) => {
|
|
102
115
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
103
116
|
return subMain(walletMain, ['wallet'], opts);
|
|
104
117
|
});
|
|
@@ -121,7 +134,7 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
121
134
|
'use this branch instead of the repository HEAD',
|
|
122
135
|
DEFAULT_DAPP_BRANCH,
|
|
123
136
|
)
|
|
124
|
-
.action(async (project, cmd) => {
|
|
137
|
+
.action(async (project, _options, cmd) => {
|
|
125
138
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
126
139
|
return subMain(initMain, ['init', project], opts);
|
|
127
140
|
});
|
|
@@ -154,15 +167,30 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
154
167
|
'set the config.toml p2p.unconditional_peer_ids value',
|
|
155
168
|
'',
|
|
156
169
|
)
|
|
157
|
-
.action(async (prog, configDir, cmd) => {
|
|
170
|
+
.action(async (prog, configDir, _options, cmd) => {
|
|
158
171
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
159
172
|
return subMain(setDefaultsMain, ['set-defaults', prog, configDir], opts);
|
|
160
173
|
});
|
|
161
174
|
|
|
175
|
+
const ibcRelayer = path.join(
|
|
176
|
+
dirname,
|
|
177
|
+
'..',
|
|
178
|
+
'node_modules',
|
|
179
|
+
'.bin',
|
|
180
|
+
'ibc-relayer',
|
|
181
|
+
);
|
|
182
|
+
program.command(
|
|
183
|
+
'ibc-relayer',
|
|
184
|
+
'run an Inter Blockchain Communications relayer',
|
|
185
|
+
{
|
|
186
|
+
executableFile: ibcRelayer,
|
|
187
|
+
},
|
|
188
|
+
);
|
|
189
|
+
|
|
162
190
|
program
|
|
163
191
|
.command('install [force-sdk-version]')
|
|
164
192
|
.description('install Dapp dependencies')
|
|
165
|
-
.action(async (forceSdkVersion, cmd) => {
|
|
193
|
+
.action(async (forceSdkVersion, _options, cmd) => {
|
|
166
194
|
await isNotBasedir();
|
|
167
195
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
168
196
|
return subMain(installMain, ['install', forceSdkVersion], opts);
|
|
@@ -204,6 +232,10 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
204
232
|
},
|
|
205
233
|
DEFAULT_JITTER_SECONDS,
|
|
206
234
|
)
|
|
235
|
+
.option(
|
|
236
|
+
'-F, --first-value-only',
|
|
237
|
+
'only display the first value of each <path-spec>',
|
|
238
|
+
)
|
|
207
239
|
.option(
|
|
208
240
|
'-o, --output <format>',
|
|
209
241
|
'value output format',
|
|
@@ -237,7 +269,7 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
237
269
|
'show current block height when each value is reported',
|
|
238
270
|
)
|
|
239
271
|
.option('-B, --bootstrap <config>', 'network bootstrap configuration')
|
|
240
|
-
.action(async (pathSpecs, cmd) => {
|
|
272
|
+
.action(async (pathSpecs, _options, cmd) => {
|
|
241
273
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
242
274
|
return subMain(followMain, ['follow', ...pathSpecs], opts);
|
|
243
275
|
});
|
|
@@ -265,16 +297,15 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
265
297
|
'',
|
|
266
298
|
);
|
|
267
299
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
300
|
+
program
|
|
301
|
+
.command('run <script> [script-args...]')
|
|
302
|
+
.description(
|
|
303
|
+
'run a script with all your user privileges and some Agoric endowments',
|
|
304
|
+
)
|
|
305
|
+
.action(async (script, scriptArgs, _options, cmd) => {
|
|
306
|
+
const opts = { ...program.opts(), ...cmd.opts(), scriptArgs };
|
|
307
|
+
return subMain(runMain, ['run', script], opts);
|
|
308
|
+
});
|
|
278
309
|
|
|
279
310
|
addRunOptions(
|
|
280
311
|
program
|
|
@@ -287,31 +318,32 @@ const main = async (progname, rawArgs, powers) => {
|
|
|
287
318
|
.description(
|
|
288
319
|
'run multiple scripts with all your user privileges against the local Agoric VM',
|
|
289
320
|
),
|
|
290
|
-
).action(async (scripts, cmd) => {
|
|
321
|
+
).action(async (scripts, _options, cmd) => {
|
|
291
322
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
292
323
|
return subMain(deployMain, ['deploy', ...scripts], opts);
|
|
293
324
|
});
|
|
294
325
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
326
|
+
program
|
|
327
|
+
.command('publish [bundle...]')
|
|
328
|
+
.option(
|
|
329
|
+
'-c, --chain-id <chainID>',
|
|
330
|
+
'The ID of the destination chain',
|
|
331
|
+
'agoriclocal',
|
|
332
|
+
)
|
|
333
|
+
.option(
|
|
334
|
+
'-n, --node <rpcAddress>',
|
|
335
|
+
'A bare IPv4 address or fully qualified URL of an RPC node',
|
|
336
|
+
'http://localhost:26657',
|
|
337
|
+
)
|
|
338
|
+
.option(
|
|
339
|
+
'-h, --home <directory>',
|
|
340
|
+
"[required] Path to the directory containing ag-solo-mnemonic, for the publisher's wallet mnemonic",
|
|
341
|
+
)
|
|
342
|
+
.description('publish a bundle to a Cosmos chain')
|
|
343
|
+
.action(async (bundles, _options, cmd) => {
|
|
344
|
+
const opts = { ...program.opts(), ...cmd.opts() };
|
|
345
|
+
return subMain(publishMain, ['publish', ...bundles], opts);
|
|
346
|
+
});
|
|
315
347
|
|
|
316
348
|
program.addCommand(await makeWalletCommand());
|
|
317
349
|
|
|
@@ -349,7 +381,7 @@ agoric start local-solo [portNum] [provisionPowers] - local solo VM
|
|
|
349
381
|
'install the wallet from NPM package <package>',
|
|
350
382
|
'@agoric/wallet-frontend',
|
|
351
383
|
)
|
|
352
|
-
.action(async (profile, args, cmd) => {
|
|
384
|
+
.action(async (profile, args, _options, cmd) => {
|
|
353
385
|
await isNotBasedir();
|
|
354
386
|
const opts = { ...program.opts(), ...cmd.opts() };
|
|
355
387
|
return subMain(startMain, ['start', profile, ...args], opts);
|
package/src/open.js
CHANGED
|
@@ -53,8 +53,10 @@ export default async function walletMain(progname, rawArgs, powers, opts) {
|
|
|
53
53
|
}${suffix}#accessToken=${encodeURIComponent(walletAccessToken)}`;
|
|
54
54
|
|
|
55
55
|
process.stdout.write(`${walletUrl}\n`);
|
|
56
|
+
let p;
|
|
56
57
|
if (opts.browser) {
|
|
57
58
|
const browser = opener(walletUrl);
|
|
58
|
-
|
|
59
|
+
p = new Promise(resolve => browser.on('exit', resolve));
|
|
59
60
|
}
|
|
61
|
+
await p;
|
|
60
62
|
}
|
package/src/publish.js
CHANGED
|
@@ -13,7 +13,7 @@ import { DirectSecp256k1HdWallet, Registry } from '@cosmjs/proto-signing';
|
|
|
13
13
|
import { defaultRegistryTypes } from '@cosmjs/stargate';
|
|
14
14
|
import { stringToPath } from '@cosmjs/crypto';
|
|
15
15
|
import { Decimal } from '@cosmjs/math';
|
|
16
|
-
import {
|
|
16
|
+
import { fromBech32 } from '@cosmjs/encoding';
|
|
17
17
|
|
|
18
18
|
import { MsgInstallBundle } from '@agoric/cosmic-proto/swingset/msgs.js';
|
|
19
19
|
|
|
@@ -82,7 +82,7 @@ const registry = new Registry([
|
|
|
82
82
|
* @typedef {SourceBundle | HashBundle} Bundle
|
|
83
83
|
*/
|
|
84
84
|
|
|
85
|
-
const { details: X, quote: q } = assert;
|
|
85
|
+
const { details: X, quote: q, Fail } = assert;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* @template T
|
|
@@ -121,9 +121,7 @@ const assertHttpConnectionSpec = connectionSpec => {
|
|
|
121
121
|
X`Expected "port" number on "http" type connectionSpec, ${connectionSpec}`,
|
|
122
122
|
);
|
|
123
123
|
Number.isInteger(port) ||
|
|
124
|
-
|
|
125
|
-
X`Expected integer "port" on "http" type connectionSpec, ${connectionSpec}`,
|
|
126
|
-
);
|
|
124
|
+
Fail`Expected integer "port" on "http" type connectionSpec, ${connectionSpec}`;
|
|
127
125
|
};
|
|
128
126
|
|
|
129
127
|
// eslint-disable-next-line jsdoc/require-returns-check
|
|
@@ -198,7 +196,9 @@ export const makeHttpBundlePublisher = ({ jsonHttpCall, getAccessToken }) => {
|
|
|
198
196
|
'object',
|
|
199
197
|
X`Expected JSON object response body, got ${response}`,
|
|
200
198
|
);
|
|
201
|
-
|
|
199
|
+
if (!response) {
|
|
200
|
+
throw Fail`Expected non-null response body, got ${response}`;
|
|
201
|
+
}
|
|
202
202
|
const { ok } = response;
|
|
203
203
|
if (!ok) {
|
|
204
204
|
const { rej } = response;
|
|
@@ -207,7 +207,7 @@ export const makeHttpBundlePublisher = ({ jsonHttpCall, getAccessToken }) => {
|
|
|
207
207
|
'string',
|
|
208
208
|
X`Expected "rej" property on JSON response body with "ok": false, got ${response}`,
|
|
209
209
|
);
|
|
210
|
-
throw
|
|
210
|
+
throw Error(
|
|
211
211
|
`Cannot publish bundle, HTTP 200 OK, JSON well-formed, but error message from service: ${rej}`,
|
|
212
212
|
);
|
|
213
213
|
}
|
|
@@ -253,10 +253,12 @@ export const makeCosmosBundlePublisher = ({
|
|
|
253
253
|
|
|
254
254
|
const leader = makeLeaderFromRpcAddresses(rpcAddresses);
|
|
255
255
|
|
|
256
|
+
const file = await readFile(
|
|
257
|
+
pathResolve(homeDirectory, 'ag-solo-mnemonic'),
|
|
258
|
+
'ascii',
|
|
259
|
+
);
|
|
256
260
|
// AWAIT
|
|
257
|
-
const mnemonic = (
|
|
258
|
-
await readFile(pathResolve(homeDirectory, 'ag-solo-mnemonic'), 'ascii')
|
|
259
|
-
).trim();
|
|
261
|
+
const mnemonic = file.trim();
|
|
260
262
|
|
|
261
263
|
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
|
|
262
264
|
prefix: Agoric.Bech32MainPrefix,
|
|
@@ -267,7 +269,7 @@ export const makeCosmosBundlePublisher = ({
|
|
|
267
269
|
|
|
268
270
|
const installBundleMsg = {
|
|
269
271
|
bundle: JSON.stringify(bundle),
|
|
270
|
-
submitter:
|
|
272
|
+
submitter: fromBech32(from.address).data,
|
|
271
273
|
};
|
|
272
274
|
|
|
273
275
|
/** @type {Array<import('@cosmjs/proto-signing').EncodeObject>} */
|
|
@@ -289,7 +291,6 @@ export const makeCosmosBundlePublisher = ({
|
|
|
289
291
|
// AWAIT
|
|
290
292
|
// eslint-disable-next-line no-await-in-loop,@jessie.js/no-nested-await
|
|
291
293
|
const stargateClient = await connectWithSigner(endpoint, wallet, {
|
|
292
|
-
prefix: Agoric.Bech32MainPrefix,
|
|
293
294
|
gasPrice: Agoric.gasPrice,
|
|
294
295
|
registry,
|
|
295
296
|
});
|
|
@@ -377,7 +378,7 @@ export const makeCosmosBundlePublisher = ({
|
|
|
377
378
|
* @param {object} powers
|
|
378
379
|
* @param {PublishBundleCosmos} [powers.publishBundleCosmos]
|
|
379
380
|
* @param {PublishBundleHttp} [powers.publishBundleHttp]
|
|
380
|
-
* @param {() => ConnectionSpec} [powers.getDefaultConnection]
|
|
381
|
+
* @param {() => Promise<ConnectionSpec>} [powers.getDefaultConnection]
|
|
381
382
|
* @returns {Promise<Bundle>}
|
|
382
383
|
*/
|
|
383
384
|
const publishBundle = async (
|
|
@@ -419,12 +420,11 @@ const publishBundle = async (
|
|
|
419
420
|
endoZipBase64Sha512,
|
|
420
421
|
});
|
|
421
422
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
X`Unrecognized bundle format ${q(
|
|
423
|
+
if (hashBundle === undefined) {
|
|
424
|
+
throw Fail`Unrecognized bundle format ${q(
|
|
425
425
|
moduleFormat,
|
|
426
|
-
)}, publishBundle supports only "endoZipBase64" with "endoZipBase64Sha512"
|
|
427
|
-
|
|
426
|
+
)}, publishBundle supports only "endoZipBase64" with "endoZipBase64Sha512"`;
|
|
427
|
+
}
|
|
428
428
|
|
|
429
429
|
if (connectionSpec === undefined && getDefaultConnection !== undefined) {
|
|
430
430
|
connectionSpec = await getDefaultConnection();
|
|
@@ -435,24 +435,25 @@ const publishBundle = async (
|
|
|
435
435
|
'object',
|
|
436
436
|
X`Expected object for connectionSpec, got ${connectionSpec}`,
|
|
437
437
|
);
|
|
438
|
-
|
|
438
|
+
connectionSpec || Fail`Expected non-null connectionSpec`;
|
|
439
439
|
const { type } = connectionSpec;
|
|
440
440
|
assert.typeof(type, 'string', X`Expected string "type" on connectionSpec`);
|
|
441
441
|
|
|
442
|
+
let p;
|
|
442
443
|
if (type === 'http') {
|
|
443
444
|
assertHttpConnectionSpec(connectionSpec);
|
|
444
445
|
assert(
|
|
445
446
|
publishBundleHttp,
|
|
446
447
|
'HTTP installation transaction publisher required',
|
|
447
448
|
);
|
|
448
|
-
|
|
449
|
+
p = publishBundleHttp(bundle, connectionSpec);
|
|
449
450
|
} else if (type === 'chain-cosmos-sdk') {
|
|
450
451
|
assertCosmosConnectionSpec(connectionSpec);
|
|
451
452
|
assert(
|
|
452
453
|
publishBundleCosmos,
|
|
453
454
|
'Cosmos SDK installation transaction publisher required',
|
|
454
455
|
);
|
|
455
|
-
|
|
456
|
+
p = publishBundleCosmos(bundle, connectionSpec);
|
|
456
457
|
} else if (type === 'fake-chain') {
|
|
457
458
|
// For the purposes of submitting a bundle to an API like
|
|
458
459
|
// E(zoe).install(bundle), in the cases where the publication target does
|
|
@@ -462,9 +463,10 @@ const publishBundle = async (
|
|
|
462
463
|
// source bundles in-band.
|
|
463
464
|
return bundle;
|
|
464
465
|
} else {
|
|
465
|
-
throw
|
|
466
|
+
throw Error(`Unsupported connection type ${type}`);
|
|
466
467
|
}
|
|
467
468
|
|
|
469
|
+
await p;
|
|
468
470
|
return hashBundle;
|
|
469
471
|
};
|
|
470
472
|
|
|
@@ -474,7 +476,7 @@ const publishBundle = async (
|
|
|
474
476
|
* @param {(hostPort: string) => Promise<string>} [powers.getAccessToken]
|
|
475
477
|
* @param {PublishBundleCosmos} [powers.publishBundleCosmos]
|
|
476
478
|
* @param {PublishBundleHttp} [powers.publishBundleHttp]
|
|
477
|
-
* @param {() => ConnectionSpec} [powers.getDefaultConnection]
|
|
479
|
+
* @param {() => Promise<ConnectionSpec>} [powers.getDefaultConnection]
|
|
478
480
|
*/
|
|
479
481
|
export const makeBundlePublisher = powers => {
|
|
480
482
|
/**
|
package/src/run.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import makeScratchPad from '@agoric/internal/src/scratch.js';
|
|
2
|
+
import { makeScriptLoader } from './scripts.js';
|
|
3
|
+
|
|
4
|
+
export default async function runMain(progname, rawArgs, powers, opts) {
|
|
5
|
+
const { anylogger, fs, now } = powers;
|
|
6
|
+
const console = anylogger('agoric:run');
|
|
7
|
+
|
|
8
|
+
const endowments = {
|
|
9
|
+
now,
|
|
10
|
+
scriptArgs: opts.scriptArgs,
|
|
11
|
+
};
|
|
12
|
+
const script = rawArgs[1];
|
|
13
|
+
const runScript = makeScriptLoader(
|
|
14
|
+
[script],
|
|
15
|
+
{ progname, rawArgs: [script, ...opts.scriptArgs], endowments },
|
|
16
|
+
{ fs, console },
|
|
17
|
+
);
|
|
18
|
+
const homeP = Promise.resolve({ scratch: Promise.resolve(makeScratchPad()) });
|
|
19
|
+
return runScript({ home: homeP });
|
|
20
|
+
}
|
package/src/scripts.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/* global process */
|
|
3
|
+
import bundleSource from '@endo/bundle-source';
|
|
4
|
+
import { E } from '@endo/captp';
|
|
5
|
+
import { search as readContainingPackageDescriptor } from '@endo/compartment-mapper';
|
|
6
|
+
|
|
7
|
+
import createEsmRequire from 'esm';
|
|
8
|
+
import { createRequire } from 'module';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import url from 'url';
|
|
11
|
+
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
const esmRequire = createEsmRequire(/** @type {NodeModule} */ ({}));
|
|
14
|
+
|
|
15
|
+
const PATH_SEP_RE = new RegExp(`${path.sep.replace(/\\/g, '\\\\')}`, 'g');
|
|
16
|
+
|
|
17
|
+
export const makeLookup =
|
|
18
|
+
bootP =>
|
|
19
|
+
/**
|
|
20
|
+
* Recursively look up names in the context of the bootstrap
|
|
21
|
+
* promise, such as:
|
|
22
|
+
*
|
|
23
|
+
* ['agoricNames', 'oracleBrand', 'USD']
|
|
24
|
+
* ['namesByAddress']
|
|
25
|
+
* ['namesByAddress', 'agoric1...']
|
|
26
|
+
* ['namesByAddress', 'agoric1...', 'depositFacet']
|
|
27
|
+
* ['wallet', 'issuer', 'IST']
|
|
28
|
+
*
|
|
29
|
+
* @param {string[]} args
|
|
30
|
+
* @returns {Promise<any>}
|
|
31
|
+
*/
|
|
32
|
+
(...args) => {
|
|
33
|
+
/** @type {string[]} */
|
|
34
|
+
let namePath;
|
|
35
|
+
if (args.length === 1 && Array.isArray(args[0])) {
|
|
36
|
+
// Convert single array argument to a path.
|
|
37
|
+
namePath = args[0];
|
|
38
|
+
} else {
|
|
39
|
+
namePath = args;
|
|
40
|
+
}
|
|
41
|
+
if (namePath.length === 0) {
|
|
42
|
+
return bootP;
|
|
43
|
+
}
|
|
44
|
+
const [first, ...remaining] = namePath;
|
|
45
|
+
|
|
46
|
+
// The first part of the name path is a property on bootP.
|
|
47
|
+
const nextValue = E.get(bootP)[first];
|
|
48
|
+
if (remaining.length === 0) {
|
|
49
|
+
return nextValue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Any remaining paths go through the lookup method of the found
|
|
53
|
+
// object.
|
|
54
|
+
return E(nextValue).lookup(...remaining);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string[]} scripts
|
|
59
|
+
* @param {{ allowUnsafePlugins: boolean, progname: string, rawArgs: string[], endowments?: Record<string, any> }} opts
|
|
60
|
+
* @param {{ fs: import('fs/promises'), console: Console }} powers
|
|
61
|
+
*/
|
|
62
|
+
export const makeScriptLoader =
|
|
63
|
+
(
|
|
64
|
+
scripts,
|
|
65
|
+
{ allowUnsafePlugins, progname, rawArgs, endowments },
|
|
66
|
+
{ fs, console },
|
|
67
|
+
) =>
|
|
68
|
+
async ({ home: bootP }) => {
|
|
69
|
+
const pluginManager = await E.get(E.get(bootP).local).plugin.catch(_ => {});
|
|
70
|
+
const pluginDir = await E(pluginManager)
|
|
71
|
+
.getPluginDir()
|
|
72
|
+
.catch(_ => {});
|
|
73
|
+
|
|
74
|
+
if (allowUnsafePlugins && !pluginDir) {
|
|
75
|
+
throw Error(`Installing unsafe plugins disabled; no pluginDir detected`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for await (const script of scripts) {
|
|
79
|
+
const moduleFile = path.resolve(process.cwd(), script);
|
|
80
|
+
const pathResolve = (...paths) => {
|
|
81
|
+
const fileName = paths.pop();
|
|
82
|
+
try {
|
|
83
|
+
return require.resolve(fileName, {
|
|
84
|
+
paths: [
|
|
85
|
+
path.resolve(path.dirname(moduleFile), ...paths),
|
|
86
|
+
path.dirname(moduleFile),
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return path.resolve(path.dirname(moduleFile), ...paths, fileName);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
console.warn('running', moduleFile);
|
|
94
|
+
|
|
95
|
+
let installUnsafePlugin;
|
|
96
|
+
if (!allowUnsafePlugins) {
|
|
97
|
+
installUnsafePlugin = async (plugin, _opts = undefined) => {
|
|
98
|
+
throw Error(
|
|
99
|
+
`Installing unsafe plugin ${JSON.stringify(
|
|
100
|
+
pathResolve(plugin),
|
|
101
|
+
)} disabled; maybe you meant '--allow-unsafe-plugins'?`,
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
installUnsafePlugin = (plugin, pluginOpts = undefined) => {
|
|
106
|
+
const tryInstallUnsafePlugin = async () => {
|
|
107
|
+
const absPath = pathResolve(plugin);
|
|
108
|
+
const pluginName = absPath.replace(PATH_SEP_RE, '_');
|
|
109
|
+
const pluginFile = path.resolve(pluginDir, pluginName);
|
|
110
|
+
|
|
111
|
+
// Just create a little redirector for that path.
|
|
112
|
+
console.warn(`Installing unsafe plugin ${JSON.stringify(absPath)}`);
|
|
113
|
+
const content = `\
|
|
114
|
+
// ${pluginFile}
|
|
115
|
+
// AUTOMATICALLY GENERATED BY ${JSON.stringify(
|
|
116
|
+
[progname, ...rawArgs].join(' '),
|
|
117
|
+
)}
|
|
118
|
+
export { bootPlugin } from ${JSON.stringify(absPath)};
|
|
119
|
+
`;
|
|
120
|
+
await fs.writeFile(pluginFile, content);
|
|
121
|
+
|
|
122
|
+
// Return the bootstrap object for this plugin.
|
|
123
|
+
console.info(`Loading plugin ${JSON.stringify(pluginFile)}`);
|
|
124
|
+
return E.get(E(pluginManager).load(pluginName, pluginOpts))
|
|
125
|
+
.pluginRoot;
|
|
126
|
+
};
|
|
127
|
+
return tryInstallUnsafePlugin().catch(e => {
|
|
128
|
+
throw Error(`Cannot install unsafe plugin: ${(e && e.stack) || e}`);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Use a dynamic import to load the deploy script.
|
|
134
|
+
// It is unconfined.
|
|
135
|
+
|
|
136
|
+
// Use Node.js ESM support if package.json of template says "type":
|
|
137
|
+
// "module".
|
|
138
|
+
const read = async location => fs.readFile(url.fileURLToPath(location));
|
|
139
|
+
const { packageDescriptorText } = await readContainingPackageDescriptor(
|
|
140
|
+
read,
|
|
141
|
+
url.pathToFileURL(moduleFile).href,
|
|
142
|
+
).catch(cause => {
|
|
143
|
+
throw Error(
|
|
144
|
+
`Expected a package.json beside deploy script ${moduleFile}, ${cause}`,
|
|
145
|
+
{ cause },
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
const packageDescriptor = JSON.parse(packageDescriptorText);
|
|
149
|
+
const nativeEsm = packageDescriptor.type === 'module';
|
|
150
|
+
console.log(
|
|
151
|
+
`Deploy script will run with ${
|
|
152
|
+
nativeEsm ? 'Node.js ESM' : 'standardthings/esm emulation'
|
|
153
|
+
}`,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const modulePath = pathResolve(moduleFile);
|
|
157
|
+
let mainNS = await (nativeEsm && import(modulePath));
|
|
158
|
+
if (!mainNS) {
|
|
159
|
+
mainNS = esmRequire(modulePath);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const allEndowments = harden({
|
|
163
|
+
home: bootP,
|
|
164
|
+
bundleSource: (file, options = undefined) =>
|
|
165
|
+
bundleSource(pathResolve(file), options),
|
|
166
|
+
...endowments,
|
|
167
|
+
pathResolve,
|
|
168
|
+
installUnsafePlugin,
|
|
169
|
+
lookup: makeLookup(bootP),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const main = mainNS.main;
|
|
173
|
+
if (typeof main === 'function') {
|
|
174
|
+
await main(allEndowments);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const defaultMain = mainNS.default;
|
|
179
|
+
if (typeof defaultMain !== 'function') {
|
|
180
|
+
console.error(
|
|
181
|
+
`${moduleFile} does not have an "export main" nor "export default" function`,
|
|
182
|
+
);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Backward-compatibility: if the module doesn't export 'main', then
|
|
187
|
+
// assume it has a default export using the old 'deploy' API.
|
|
188
|
+
await defaultMain(allEndowments.home, allEndowments);
|
|
189
|
+
}
|
|
190
|
+
};
|
package/src/sdk-package-names.js
CHANGED
|
@@ -10,7 +10,6 @@ export default [
|
|
|
10
10
|
"@agoric/cosmic-swingset",
|
|
11
11
|
"@agoric/cosmos",
|
|
12
12
|
"@agoric/deploy-script-support",
|
|
13
|
-
"@agoric/deployment",
|
|
14
13
|
"@agoric/ertp",
|
|
15
14
|
"@agoric/eslint-config",
|
|
16
15
|
"@agoric/governance",
|
|
@@ -25,21 +24,26 @@ export default [
|
|
|
25
24
|
"@agoric/solo",
|
|
26
25
|
"@agoric/sparse-ints",
|
|
27
26
|
"@agoric/spawner",
|
|
27
|
+
"@agoric/ssh-node",
|
|
28
28
|
"@agoric/stat-logger",
|
|
29
29
|
"@agoric/store",
|
|
30
30
|
"@agoric/swing-store",
|
|
31
|
+
"@agoric/swingset-liveslots",
|
|
31
32
|
"@agoric/swingset-runner",
|
|
32
33
|
"@agoric/swingset-vat",
|
|
34
|
+
"@agoric/swingset-xsnap-supervisor",
|
|
33
35
|
"@agoric/telemetry",
|
|
36
|
+
"@agoric/time",
|
|
34
37
|
"@agoric/ui-components",
|
|
35
38
|
"@agoric/vat-data",
|
|
36
39
|
"@agoric/vats",
|
|
37
40
|
"@agoric/wallet",
|
|
38
41
|
"@agoric/wallet-backend",
|
|
39
42
|
"@agoric/wallet-connection",
|
|
40
|
-
"@agoric/wallet-ui",
|
|
41
43
|
"@agoric/web-components",
|
|
42
44
|
"@agoric/xsnap",
|
|
45
|
+
"@agoric/xsnap-lockdown",
|
|
43
46
|
"@agoric/zoe",
|
|
47
|
+
"@agoric/zone",
|
|
44
48
|
"agoric"
|
|
45
49
|
];
|
package/src/set-defaults.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { basename } from 'path';
|
|
2
|
-
import {
|
|
2
|
+
import { Fail } from '@agoric/assert';
|
|
3
3
|
import {
|
|
4
4
|
finishCosmosApp,
|
|
5
5
|
finishTendermintConfig,
|
|
@@ -12,7 +12,7 @@ export default async function setDefaultsMain(progname, rawArgs, powers, opts) {
|
|
|
12
12
|
|
|
13
13
|
const [prog, configDir] = rawArgs.slice(1);
|
|
14
14
|
prog === 'ag-chain-cosmos' ||
|
|
15
|
-
|
|
15
|
+
Fail`<prog> must currently be 'ag-chain-cosmos'`;
|
|
16
16
|
|
|
17
17
|
const { exportMetrics, enableCors } = opts;
|
|
18
18
|
|