Skip to content

Commit

Permalink
feat(deploy-script-support): Publish bundles to chain if possible
Browse files Browse the repository at this point in the history
This change allows deploy-script-helpers to publish a bundle to the chain if the version of agoric-cli supports publishBundle. This also reconciles some differences with the version of this currently inlined in dapp-fungible-faucet to ensure continuity.
  • Loading branch information
kriskowal committed Sep 9, 2022
1 parent 1e8edba commit 5f354c6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
11 changes: 9 additions & 2 deletions packages/deploy-script-support/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ZOE_INVITE_PURSE_PETNAME = 'Default Zoe invite purse';
export const makeHelpers = async (homePromise, endowments) => {
const { zoe, wallet, scratch, board } = E.get(homePromise);

const { lookup } = endowments;
const { lookup, publishBundle, pathResolve } = endowments;

const walletAdmin = E(wallet).getAdminFacet();
const installationManager = E(walletAdmin).getInstallationManager();
Expand All @@ -36,7 +36,14 @@ export const makeHelpers = async (homePromise, endowments) => {

// Create the methods

const install = makeInstall(bundleSource, zoe, installationManager, board);
const install = makeInstall(
bundleSource,
zoe,
installationManager,
board,
publishBundle,
pathResolve,
);

const startInstance = makeStartInstance(
issuerManager,
Expand Down
45 changes: 36 additions & 9 deletions packages/deploy-script-support/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,49 @@ import { E } from '@endo/far';
* @param {ERef<ZoeService>} zoe
* @param {ERef<import('./startInstance.js').InstallationManager>} installationManager
* @param {ERef<any>} board
* @param {(bundle: any) => any} [publishBundle]
* @param {(path: string) => string} [pathResolve]
* @returns {InstallSaveAndPublish}
*/
export const makeInstall = (bundleSource, zoe, installationManager, board) => {
export const makeInstall = (
bundleSource,
zoe,
installationManager,
board,
publishBundle,
pathResolve,
) => {
/** @type {InstallSaveAndPublish} */
const install = async (resolvedPath, contractPetname) => {
console.log(`- Installing Contract Name: ${contractPetname}`);

const install = async (contractPath, contractPetname) => {
const resolvedPath = pathResolve ? pathResolve(contractPath) : contractPath;
const bundle = await bundleSource(resolvedPath);
const installation = await E(zoe).install(bundle);

console.log(`- Publishing Contract Name: ${contractPetname}`);
const hashedBundle = await (publishBundle ? publishBundle(bundle) : bundle);
console.log(`- Installing Contract Name: ${contractPetname}`);
const installation = await E(zoe).install(hashedBundle);
console.log(
`- Adding contract to installation manager: ${contractPetname}`,
);
await E(installationManager).add(contractPetname, installation);

console.log(`- Installed Contract Name: ${contractPetname}`);

// Let's share this installation with other people, so that
// they can run our contract code by making a contract
// instance (see the api deploy script in this repo to see an
// example of how to use the installation to make a new contract
// instance.)
// To share the installation, we're going to put it in the
// board. The board is a shared, on-chain object that maps
// strings to objects.
const id = await E(board).getId(installation);
return { installation, id };

console.log('- SUCCESS! contract code installed on Zoe');
console.log(`-- Contract Name: ${contractPetname}`);
console.log(`-- Installation Board Id: ${id}`);

return {
installation,
id,
};
};
return install;
};

0 comments on commit 5f354c6

Please sign in to comment.