Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on feat: deploy contract without custom code (WIP) #61

Draft
wants to merge 3 commits into
base: dev/no-custom-core-eval
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions contract/scripts/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const options = {
service: { type: 'string', default: 'agd' },
workdir: { type: 'string', default: '/workspace/contract' },
deploy: { type: 'string', multiple: true },
deploygen: { type: 'string', multiple: true },
};
/**
* @typedef {{
Expand All @@ -27,10 +28,11 @@ const options = {
* service: string,
* workdir: string,
* deploy: string[],
* deploygen?: string[],
* }} DeployOptions
*/

//TODo make help test
// TODo make help test
const Usage = `
deploy-contract [options] [--install <contract>] [--eval <proposal>]...

Expand Down Expand Up @@ -72,7 +74,7 @@ const generateDeployArtifact = async (path, name, { readFile, writeFile }) => {
// string replace for contract name
const finalFile = hideImportExpr(template.replace('_CONTRACT_NAME_', name));

//write result to bundles/deploy-name.js
// write result to bundles/deploy-name.js
return writeFile(`bundles/deploy-${name}.js`, finalFile);
};

Expand Down Expand Up @@ -120,6 +122,15 @@ const main = async (bundleDir = 'bundles') => {

const stem = path => basename(path).replace(/\..*/, '');

if (flags.deploygen) {
for (const contractEntry of flags.deploygen) {
const name = stem(contractEntry);
const generatedCoreEval = `bundles/deploy-${name}-entry.js`;
// TODO: fix
await generateDeployArtifact(generatedCoreEval, name, fsp);
}
}

// deploy in one step
if (flags.deploy) {
for await (const contractEntry of flags.deploy) {
Expand Down
56 changes: 56 additions & 0 deletions contract/src/auto-deploy.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// @ts-check
import { allValues } from './objectTools.js';

Check failure on line 2 in contract/src/auto-deploy.template.js

View workflow job for this annotation

GitHub Actions / unit

'allValues' is defined but never used. Allowed unused vars must match /^_/u
import {
AmountMath,

Check failure on line 4 in contract/src/auto-deploy.template.js

View workflow job for this annotation

GitHub Actions / unit

'AmountMath' is defined but never used. Allowed unused vars must match /^_/u
installContract,
startContract,
} from './platform-goals/start-contract.js';

const { Fail } = assert;

const contractName = '_CONTRACT_NAME_'; // for pattern match
const IST_UNIT = 1_000_000n;

Check failure on line 12 in contract/src/auto-deploy.template.js

View workflow job for this annotation

GitHub Actions / unit

'IST_UNIT' is assigned a value but never used. Allowed unused vars must match /^_/u

/**
* Core eval script to start contract
*
* @param {BootstrapPowers } permittedPowers
* @param {*} config
*
*/
export const deployContract = async (permittedPowers, config) => {
console.log('core eval for', contractName);
const {
// must be supplied by caller or template-replaced
bundleID = Fail`no bundleID`,
} = config?.options?.[contractName] ?? {};

const installation = await installContract(permittedPowers, {
name: contractName,
bundleID,
});

await startContract(permittedPowers, {
name: contractName,
startArgs: {
installation,
},
});

console.log(contractName, '(re)started');
};

/** @type { import("@agoric/vats/src/core/lib-boot.js").BootstrapManifestPermit } */
export const permit = harden({
consume: {
startUpgradable: true, // to start contract and save adminFacet
},
installation: {
consume: { [contractName]: true },
produce: { [contractName]: true },
},
instance: { produce: { [contractName]: true } },
// generate issuer/brand
});

export const main = deployContract;
Loading