Skip to content

Commit

Permalink
feat(start): implement solo mode
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2019
1 parent 6aa6e2a commit 71f1fb4
Show file tree
Hide file tree
Showing 7 changed files with 507 additions and 27 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
## Getting Started

```sh
# Install the agoric devtool.
npm install -g agoric
agoric init dapp
cd dapp
# Initialize your dapp project.
agoric init my-dapp
# Go to its directory.
cd my-dapp
# Install Javascript/Go dependencies.
agoric install
# Run the local vat machine.
agoric start
agoric deploy ./api/deploy.js ./contract/deploy.js
# Install your smart contract and web api (can be done separately)
agoric deploy ./contract/deploy.js ./api/deploy.js
# Navigate to http://localhost:8000/
```
19 changes: 0 additions & 19 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,5 @@ export default async function initMain(progname, rawArgs, priv) {
};
await recursiveTemplate(templateDir);

const agservers = `${DIR}/.agservers`;
const solo = `${agservers}/solo`;
const chain = `${agservers}/chain`;
await Promise.all([mkdir(solo), mkdir(chain)]);
const chainSolo = `${chain}/solo`;
const chainCosmos = `${chain}/cosmos`;
await Promise.all([mkdir(chainSolo), mkdir(chainCosmos)]);

// Create links to all the solo nodes' html directories.
await Promise.all([
mkdir(`${chainSolo}/html`),
mkdir(`${solo}/html`),
])

await Promise.all([
symlink('../../../ui/build', `${chainSolo}/dapp-html`),
symlink('../../ui/build', `${solo}/dapp-html`),
]);

console.log(chalk.bold.yellow(`Done initializing; you should 'cd ${DIR} && ${progname} install'`));
}
6 changes: 5 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import parseArgs from 'minimist';
import chalk from 'chalk';
import { spawn } from 'child_process';
import { promises as fs } from 'fs';
import { resolve } from 'any-promise';

export default async function installMain(progname, rawArgs, priv) {
const { console, error } = priv;
Expand All @@ -23,6 +22,7 @@ export default async function installMain(progname, rawArgs, priv) {
}
const pm = 'yarn';

// FIXME: Check for version 1.13.
const goRet = await pspawn('go', ['version']);
const goCmd = goRet === 0 && pspawn('npm', ['install'], { cwd: '.agservers', stdio: 'inherit' });

Expand All @@ -35,6 +35,10 @@ export default async function installMain(progname, rawArgs, priv) {

if (!goCmd) {
console.log(chalk.bold.yellow(`To run Agoric locally you will need to install Go and rerun '${progname} install'`));
} else {
// FIXME: Build the wallet
await pspawn(pm, ['install'], { cwd: '.agservers/node_modules/@agoric/wallet-frontend' });
await pspawn(pm, ['run', 'build'], { cwd: '.agservers/node_modules/@agoric/wallet-frontend' });
}
console.log(chalk.bold.green('Done installing'));
}
60 changes: 60 additions & 0 deletions lib/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import parseArgs from 'minimist';
import chalk from 'chalk';
import { spawn } from 'child_process';
import { promises as fs } from 'fs';

export default async function startMain(progname, rawArgs, priv) {
const { console, error } = priv;
const {
reset,
_: args,
} = parseArgs(rawArgs, {
boolean: ['reset'],
});

const pspawn = (...args) => new Promise((resolve, reject) => {
const cp = spawn(...args);
cp.on('exit', resolve);
cp.on('error', () => resolve(-1));
});

const exists = async file => {
try {
await fs.stat(file);
return true;
} catch (e) {
return false;
}
};

if (!await exists('.agservers/node_modules')) {
return error(`you must first run '${progname} install' with Go 1.12 or later`);
}

if (reset) {
console.log(chalk.green('removing .agservers/solo'));
await pspawn('rm', ['-rf', '.agservers/solo'], { stdio: 'inherit' });
}

// Run scenario3.
const css = 'node_modules/\@agoric/cosmic-swingset';
if (!await exists('.agservers/solo')) {
console.log(chalk.yellow('initializing solo'))
await pspawn(`${css}/bin/ag-solo`, ['init', 'solo', '--egresses=none'], {
stdio: 'inherit',
cwd: '.agservers',
});
}

console.log(chalk.green('linking html directories'));
const dappHtml = '.agservers/solo/dapp-html';
const htmlWallet = '.agservers/solo/html/wallet';
await Promise.allSettled([fs.unlink(dappHtml), fs.unlink(htmlWallet)]);
await Promise.allSettled([fs.symlink('../../ui/build', dappHtml),
fs.symlink('../../node_modules/@agoric/wallet-frontend/build', htmlWallet)]);

await pspawn(`../${css}/bin/ag-solo`, ['start', '--role=three_client'], {
stdio: 'inherit',
cwd: '.agservers/solo',
});
}
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
"ws": "^7.2.0"
},
"keywords": [],
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Agoric/agoric"
Expand Down
Loading

0 comments on commit 71f1fb4

Please sign in to comment.