Skip to content

Commit

Permalink
feat(zoe!):add a config facet to Zoe so the zcfBundle can be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jun 22, 2023
1 parent b8f88d7 commit 9b24615
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/vats/src/vat-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ const BUILD_PARAMS_KEY = 'buildZoeParams';
export function buildRootObject(vatPowers, _vatParams, zoeBaggage) {
const shutdownZoeVat = vatPowers.exitVatWithFailure;

let zoeConfigFacet;

if (zoeBaggage.has(BUILD_PARAMS_KEY)) {
const { feeIssuerConfig, zcfSpec } = zoeBaggage.get(BUILD_PARAMS_KEY);
makeDurableZoeKit({
({ zoeConfigFacet } = makeDurableZoeKit({
// For now Zoe will rewire vatAdminSvc on its own
shutdownZoeVat,
feeIssuerConfig,
zcfSpec,
zoeBaggage,
});
}));
}

return Far('root', {
Expand Down Expand Up @@ -44,5 +46,6 @@ export function buildRootObject(vatPowers, _vatParams, zoeBaggage) {
feeMintAccess,
});
},
getZoeConfigFacet: () => zoeConfigFacet,
});
}
23 changes: 22 additions & 1 deletion packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../internal-types.js';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { makeScalarBigMapStore, prepareExo } from '@agoric/vat-data';
import { M } from '@agoric/store';

import { makeZoeStorageManager } from './zoeStorageManager.js';
import { makeStartInstance } from './startInstance.js';
Expand All @@ -32,7 +33,7 @@ import { ZoeServiceI } from '../typeGuards.js';
const { Fail } = assert;

/**
* Create an durable instance of Zoe.
* Create a durable instance of Zoe.
*
* @param {object} options
* @param {Baggage} options.zoeBaggage - the baggage for Zoe durability. Must be provided by caller
Expand All @@ -52,6 +53,7 @@ const makeDurableZoeKit = ({
feeIssuerConfig = defaultFeeIssuerConfig,
zcfSpec = { name: 'zcf' },
}) => {
/** @type {BundleCap} */
let zcfBundleCap;

const saveBundleCap = () => {
Expand Down Expand Up @@ -168,6 +170,24 @@ const makeDurableZoeKit = ({
});
};

const ZoeConfigI = M.interface('ZoeConfigFacet', {
updateZcfBundleId: M.call(M.string()).returns(),
});

const zoeConfigFacet = prepareExo(zoeBaggage, 'ZoeConfigFacet', ZoeConfigI, {
updateZcfBundleId(bundleId) {
E.when(
getZcfBundleCap({ id: bundleId }, vatAdminSvc),
bundleCap => {
zcfBundleCap = bundleCap;
},
e => {
console.warn(`unable to update ZCF Bundle: `, e);
},
);
},
});

/** @type {ZoeService} */
const zoeService = prepareExo(zoeBaggage, 'ZoeService', ZoeServiceI, {
install(bundleId, bundleLabel) {
Expand Down Expand Up @@ -223,6 +243,7 @@ const makeDurableZoeKit = ({

return harden({
zoeService,
zoeConfigFacet,
/** @type {FeeMintAccess} */
// @ts-expect-error cast
feeMintAccess: feeMintKit.feeMintAccess,
Expand Down

0 comments on commit 9b24615

Please sign in to comment.