Skip to content

Commit

Permalink
feat: defer the wallet UI until the start process
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Aug 5, 2020
1 parent 5ba0229 commit 18ee099
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 53 deletions.
6 changes: 3 additions & 3 deletions packages/agoric-cli/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export default async function deployMain(progname, rawArgs, powers, opts) {
const console = anylogger('agoric:deploy');

const args = rawArgs.slice(1);
const deps = opts.need
const init = opts.provide
.split(',')
.map(dep => dep.trim())
.filter(dep => dep);

const init = opts.provide
const deps = opts.need
.split(',')
.map(dep => dep.trim())
.filter(dep => dep);
.filter(dep => dep && !init.includes(dep));

if (args.length === 0 && !init.length) {
console.error('you must specify at least one deploy.js (or --init=XXX)');
Expand Down
11 changes: 8 additions & 3 deletions packages/agoric-cli/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ const main = async (progname, rawArgs, powers) => {
.command('deploy [script...]')
.description('run a deployment script against the local Agoric VM')
.option(
'--hostport <HOST:PORT>',
'--hostport <host:port>',
'host and port to connect to VM',
'127.0.0.1:8000',
)
.option(
'--need <DEPENDENCIES>',
'--need <subsystems>',
'comma-separated names of subsystems to wait for',
'agoric,wallet',
)
.option(
'--provide <DEPENDENCIES>',
'--provide <subsystems>',
'comma-separated names of subsystems this script initializes',
'',
)
Expand All @@ -147,6 +147,11 @@ const main = async (progname, rawArgs, powers) => {
'--inspect-brk [host[:port]]',
'activate inspector on host:port and break at start of script (default: "127.0.0.1:9229")',
)
.option(
'--wallet <package>',
'install the wallet from NPM package <package>',
'@agoric/wallet-frontend',
)
.action(async (profile, args, cmd) => {
await isNotBasedir();
const opts = { ...program.opts(), ...cmd.opts() };
Expand Down
33 changes: 8 additions & 25 deletions packages/cosmic-swingset/lib/ag-solo/init-basedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import anylogger from 'anylogger';

const log = anylogger('ag-solo:init');

const DEFAULT_WALLET = '@agoric/wallet-frontend';

export default function initBasedir(
basedir,
webport,
webhost,
subdir,
egresses,
opts = {},
) {
const { wallet = DEFAULT_WALLET, ...options } = opts;
options.wallet = wallet;

const here = __dirname;
try {
fs.mkdirSync(basedir);
Expand All @@ -39,31 +45,8 @@ export default function initBasedir(
fs.copyFileSync(path.join(srcHtmldir, name), path.join(dstHtmldir, name));
});

// Symlink the wallet.
let agWallet;
try {
agWallet = path.resolve(__dirname, '../../../wallet-frontend');
let walletBuild = path.join(agWallet, 'build');
if (!fs.existsSync(agWallet)) {
const pjs = require.resolve('@agoric/wallet-frontend/package.json');
agWallet = path.dirname(pjs);
walletBuild = path.join(agWallet, 'build');
fs.statSync(walletBuild);
}
fs.symlinkSync(walletBuild, `${dstHtmldir}/wallet`);
} catch (e) {
console.warn(
`${agWallet} does not exist; you may want to run 'yarn build' in 'wallet-frontend'`,
);
}

const walletDeploy = path.join(agWallet, 'wallet-deploy.js');
try {
fs.statSync(walletDeploy);
fs.symlinkSync(walletDeploy, path.join(basedir, 'wallet-deploy.js'));
} catch (e) {
console.warn(`${walletDeploy} does not exist; cannot autodeploy wallet`);
}
// Save the configuration options.
fs.writeFileSync(path.join(basedir, 'options.json'), JSON.stringify(options));

// Save our version codes.
const pj = 'package.json';
Expand Down
61 changes: 39 additions & 22 deletions packages/cosmic-swingset/lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const fsWrite = promisify(fs.write);
const fsClose = promisify(fs.close);
const rename = promisify(fs.rename);
const unlink = promisify(fs.unlink);
const symlink = promisify(fs.symlink);

async function atomicReplaceFile(filename, contents) {
const info = await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -301,14 +302,43 @@ export default async function start(basedir, argv) {
// Start timer here!
startTimer(1200);

// Remove wallet traces.
await unlink('html/wallet').catch(_ => {});

log.info(`swingset running`);
swingSetRunning = true;
deliverOutbound();

if (hostport) {
const agoricCli = require.resolve('.bin/agoric');
if (!hostport) {
return;
}

const { wallet } = JSON.parse(fs.readFileSync('options.json', 'utf-8'));

const makeHandler = (onSuccess = undefined) => (err, _stdout, stderr) => {
// Symlink the wallet.
const pjs = require.resolve(`${wallet}/package.json`);
const {
'agoric-wallet': {
htmlBasedir = 'ui/build',
deploy = ['contract/deploy.js', 'api/deploy.js'],
} = {},
} = JSON.parse(fs.readFileSync(pjs, 'utf-8'));

const agWallet = path.dirname(pjs);
const agWalletHtml = path.resolve(agWallet, htmlBasedir);

const deploys = typeof deploy === 'string' ? [deploy] : deploy;
// TODO: Shell-quote the deploy list.
const agWalletDeploy = deploys
.map(dep => path.resolve(agWallet, dep))
.join(' ');

const agoricCli = require.resolve('.bin/agoric');

// Launch the agoric wallet deploys (if any).
exec(
`${agoricCli} deploy --provide=wallet --hostport=${hostport} ${agWalletDeploy}`,
(err, _stdout, stderr) => {
if (err) {
console.error(err);
return;
Expand All @@ -317,23 +347,10 @@ export default async function start(basedir, argv) {
// Report the error.
process.stderr.write(stderr);
}
onSuccess && onSuccess();
};

if (fs.existsSync('./wallet-deploy.js')) {
// Install the wallet.
// Launch the agoric deploy, letting it synchronize with the chain but not wait
// until open for business.
exec(
`${agoricCli} deploy --need=agoric --provide=wallet --hostport=${hostport} ./wallet-deploy.js`,
makeHandler(),
);
} else {
// No need to wait for the wallet, just open for business.
exec(
`${agoricCli} deploy --need= --provide=wallet --hostport=${hostport}`,
makeHandler(),
);
}
}
// Now that the deploy is done, link the wallet!
symlink(agWalletHtml, 'html/wallet').catch(e => {
console.error('Cannot link html/wallet:', e);
});
},
);
}
4 changes: 4 additions & 0 deletions packages/wallet-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"author": "Agoric",
"license": "Apache-2.0",
"homepage": ".",
"agoric-wallet": {
"htmlBasedir": "./build",
"deploy": "./wallet-deploy.js"
},
"scripts": {
"clean": "rimraf ./build",
"lint-check": "exit 0",
Expand Down

0 comments on commit 18ee099

Please sign in to comment.