Skip to content

Commit

Permalink
feat(api): deploy api handler to cosmic-swingset
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2019
1 parent b2f7d99 commit a778018
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Getting Started

```sh
npm install -g agoric
agoric init dapp
cd dapp
agoric install
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'chalk';
import parseArgs from 'minimist';
import fs from 'fs';

const VERSION = 'Agoric 0.1.0';
const VERSION = 'Agoric <some version>';
const STAMP = '.agservers';

const main = async (progname, rawArgs, privs) => {
Expand Down
6 changes: 3 additions & 3 deletions template/.agservers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion template/.agservers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "Agoric",
"license": "Apache-2.0",
"dependencies": {
"@agoric/cosmic-swingset": "^0.10.9"
"@agoric/cosmic-swingset": "^0.10.10"
}
}
11 changes: 8 additions & 3 deletions template/api/deploy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// Agoric Dapp api deployment script
export default async function deployApi(homeP, { bundleSource }) {
import fs from 'fs';
import harden from '@agoric/harden';

export default async function deployApi(homeP, { bundleSource, pathResolve }) {
const { source, moduleFormat } = await bundleSource('./handler.js');
const handlerInstall = homeP~.spawner~.install(source, moduleFormat);
handlerInstall~.spawn(homeP);
homeP~.registerCommandHandler(handler);
const cjson = await fs.promises.readFile(pathResolve('./contracts.json'));
const contracts = JSON.parse(cjson);
const handler = handlerInstall~.spawn(harden({ contracts }));
await homeP~.http~.registerCommandHandler(handler);
}
19 changes: 19 additions & 0 deletions template/api/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import harden from '@agoric/harden';

export default harden((terms, _inviteMaker) => {
const {contracts} = terms;
return harden({
getCommandHandler() {
return harden({
processInbound(obj, home) {
switch (obj.type) {
case '@DIR@Message': {
return harden({type: '@DIR@Response', orig: obj, contracts});
}
}
return undefined;
},
});
}
});
});
2 changes: 1 addition & 1 deletion template/contract/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function deployContract(homeP, { bundleSource, pathResolve
});

// Save the contractID somewhere where the UI can find it.
const cjfile = pathResolve(`../ui/contracts.json`);
const cjfile = pathResolve(`../api/contracts.json`);
console.log('writing', cjfile);
await fs.promises.writeFile(cjfile, contractsJson);
}

0 comments on commit a778018

Please sign in to comment.