diff --git a/contract/scripts/deploy-contract.js b/contract/scripts/deploy-contract.js index 460ad3fb..31877871 100755 --- a/contract/scripts/deploy-contract.js +++ b/contract/scripts/deploy-contract.js @@ -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 {{ @@ -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 ] [--eval ]... @@ -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); }; @@ -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) { diff --git a/contract/src/auto-deploy.template.js b/contract/src/auto-deploy.template.js new file mode 100644 index 00000000..0e018981 --- /dev/null +++ b/contract/src/auto-deploy.template.js @@ -0,0 +1,56 @@ +// @ts-check +import { allValues } from './objectTools.js'; +import { + AmountMath, + installContract, + startContract, +} from './platform-goals/start-contract.js'; + +const { Fail } = assert; + +const contractName = '_CONTRACT_NAME_'; // for pattern match +const IST_UNIT = 1_000_000n; + +/** + * 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;