From 9e53f4f6bcc5d19cabe1e44dea2e9f8bb374e475 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Thu, 6 Jan 2022 18:20:42 -0600 Subject: [PATCH] feat(vats): connectFaucet bootstrap behavior - choose boostrap manifest based on ROLE --- packages/vats/src/bootstrap-behaviors-sim.js | 23 +++++++++++++++-- packages/vats/src/bootstrap-behaviors.js | 26 ++++++++++++++++++++ packages/vats/src/bootstrap-core.js | 12 +++++++-- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/packages/vats/src/bootstrap-behaviors-sim.js b/packages/vats/src/bootstrap-behaviors-sim.js index b09978d7e22..627e926a6dd 100644 --- a/packages/vats/src/bootstrap-behaviors-sim.js +++ b/packages/vats/src/bootstrap-behaviors-sim.js @@ -1,4 +1,5 @@ // @ts-check +import { E, Far } from '@agoric/far'; import { bootstrapManifest, installClientEgress, @@ -13,6 +14,7 @@ export const simBootstrapManifest = harden({ }, workspace: true, }, + connectFaucet: { workspace: true }, ...bootstrapManifest, }); @@ -35,6 +37,23 @@ const installSimEgress = async ({ vatParameters, vats, workspace }) => { ); }; -harden({ installSimEgress }); -export { installSimEgress }; +const connectFaucet = async ({ workspace }) => { + const { zoe, client } = workspace; + workspace.bridgeManager = undefined; // no bridge in the sim chain + + const makeFaucet = async _address => { + const userFeePurse = await E(zoe).makeFeePurse(); + + return Far('faucet', { + tapFaucet: () => [], + // TODO: obsolete getFeePurse, now that zoe fees are gone? + getFeePurse: () => userFeePurse, + }); + }; + + return E(client).assignBundle({ faucet: makeFaucet }); +}; + +harden({ installSimEgress, connectFaucet }); +export { installSimEgress, connectFaucet }; export * from './bootstrap-behaviors.js'; diff --git a/packages/vats/src/bootstrap-behaviors.js b/packages/vats/src/bootstrap-behaviors.js index c0fcaea4d5e..b2f9b53cfbe 100644 --- a/packages/vats/src/bootstrap-behaviors.js +++ b/packages/vats/src/bootstrap-behaviors.js @@ -34,6 +34,10 @@ export const bootstrapManifest = harden({ workspace: { vatAdminSvc: true, client: true }, }, makeAddressNameHubs: { workspace: true }, + makeClientBanks: { + // TODO: separate workspace read / write powers + workspace: true, + }, }); /** @@ -53,6 +57,7 @@ const connectVattpWithMailbox = ({ }; /** + * TODO: { dynamicVats: { bank: true }} thingy? * * @param {{ * vats: { vatAdmin: VatAdminVat }, @@ -182,6 +187,25 @@ const installClientEgress = async (addr, { vats, workspace }) => { }); }; +/** + * @param {{ workspace: { + * vatAdminSvc: VatAdminSvc, + * client: any, // TODO + * bridgeManager: import('./bridge').BridgeManager + * bankManager: unknown, + * }}} powers + */ +const makeClientBanks = async ({ workspace }) => { + const { vatAdminSvc, client, bridgeManager } = workspace; + const { root: bankVat } = await E(vatAdminSvc).createVatByName('bank'); + const settledBridge = await bridgeManager; + const bankManager = E(bankVat).makeBankManager(settledBridge); + workspace.bankManager = bankManager; + return E(client).assignBundle({ + bank: address => E(bankManager).getBankForAddress(address), + }); +}; + harden({ connectVattpWithMailbox, makeVatAdminService, @@ -189,6 +213,7 @@ harden({ makeBoard, makeAddressNameHubs, installClientEgress, + makeClientBanks, }); export { connectVattpWithMailbox, @@ -197,4 +222,5 @@ export { makeBoard, makeAddressNameHubs, installClientEgress, + makeClientBanks, }; diff --git a/packages/vats/src/bootstrap-core.js b/packages/vats/src/bootstrap-core.js index d0752d0091b..a3dec349002 100644 --- a/packages/vats/src/bootstrap-core.js +++ b/packages/vats/src/bootstrap-core.js @@ -75,6 +75,9 @@ const extract = (template, specimen) => { } }; +const manifestByRole = { + 'sim-chain': simBootstrapManifest, +}; /** * Build root object of the bootstrap vat. * @@ -88,6 +91,12 @@ const extract = (template, specimen) => { const buildRootObject = (vatPowers, vatParameters) => { const workspace = makePromiseSpace(); + const { ROLE } = vatParameters.argv; + console.debug(`${ROLE} bootstrap starting`); + + const manifest = manifestByRole[ROLE]; + assert(manifest, X`no manifest for ${ROLE}`); + return Far('bootstrap', { /** * Bootstrap vats and devices. @@ -97,8 +106,7 @@ const buildRootObject = (vatPowers, vatParameters) => { */ bootstrap: (vats, devices) => Promise.all( - // TODO: choose simBootstrapManifest based on runtime config - entries(simBootstrapManifest).map(([name, permit]) => + entries(manifest).map(([name, permit]) => Promise.resolve().then(() => { const endowments = extract(permit, { vatPowers,