Skip to content

Commit

Permalink
feat(vats): in sim-chain, delegate economy bootstrap to REPL user
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc authored and michaelfig committed Jan 26, 2022
1 parent 2c97f86 commit 116ccbd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
38 changes: 22 additions & 16 deletions packages/vats/src/core/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,29 @@ const buildRootObject = (vatPowers, vatParameters) => {
* @param {SwingsetDevices} devices
*/
bootstrap: (vats, devices) => {
const powers = {
vatPowers,
vatParameters,
vats,
devices,
produce,
consume,
/** @param { Record<string, Record<string, unknown>> } manifest */
const runBehaviors = manifest => {
const powers = {
vatPowers,
vatParameters,
vats,
devices,
produce,
consume,
runBehaviors,
};
return Promise.all(
entries(manifest).map(([name, permit]) =>
Promise.resolve().then(() => {
const endowments = extract(permit, powers);
console.info(`bootstrap: ${name}(${q(permit)})`);
return behaviors[name](endowments);
}),
),
);
};
return Promise.all(
entries(actualManifest).map(([name, permit]) =>
Promise.resolve().then(() => {
const endowments = extract(permit, powers);
console.info(`bootstrap: ${name}(${q(permit)})`);
return behaviors[name](endowments);
}),
),
);

return runBehaviors(actualManifest);
},
});
};
Expand Down
24 changes: 21 additions & 3 deletions packages/vats/src/core/sim-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { governanceActions } from './bootEconomy.js';
export const makeSimBootstrapManifest = bootstrapManifest =>
harden({
...bootstrapManifest,
...governanceActions,
installSimEgress: {
vatParameters: { argv: { hardcodedClientAddresses: true } },
vats: {
Expand All @@ -19,6 +18,10 @@ export const makeSimBootstrapManifest = bootstrapManifest =>
consume: { zoe: true, client: true },
produce: { bridgeManager: true },
},
grantRunBehaviors: {
runBehaviors: true,
consume: { client: true },
},
});

/**
Expand Down Expand Up @@ -68,7 +71,22 @@ const connectFaucet = async ({
return E(client).assignBundle({ faucet: makeFaucet });
};

harden({ installSimEgress, connectFaucet });
export { installSimEgress, connectFaucet };
/**
* @param {{
* runBehaviors: (manifest:unknown) => Promise<unknown>,
* consume: { client: ERef<ClientConfig> }
* }} powers
*/
const grantRunBehaviors = async ({ runBehaviors, consume: { client } }) => {
const makeBehaviors = _address =>
Far('behaviors', { run: manifest => runBehaviors(manifest) });
return E(client).assignBundle({
behaviors: makeBehaviors,
governanceActions: _address => governanceActions,
});
};

harden({ installSimEgress, connectFaucet, grantRunBehaviors });
export { installSimEgress, connectFaucet, grantRunBehaviors };
export * from './behaviors.js';
export * from './bootEconomy.js';

0 comments on commit 116ccbd

Please sign in to comment.