Skip to content

Commit

Permalink
feat(vats): connectFaucet bootstrap behavior
Browse files Browse the repository at this point in the history
 - choose boostrap manifest based on ROLE
  • Loading branch information
dckc authored and michaelfig committed Jan 16, 2022
1 parent 4535c8d commit 9e53f4f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
23 changes: 21 additions & 2 deletions packages/vats/src/bootstrap-behaviors-sim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
import { E, Far } from '@agoric/far';
import {
bootstrapManifest,
installClientEgress,
Expand All @@ -13,6 +14,7 @@ export const simBootstrapManifest = harden({
},
workspace: true,
},
connectFaucet: { workspace: true },
...bootstrapManifest,
});

Expand All @@ -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';
26 changes: 26 additions & 0 deletions packages/vats/src/bootstrap-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});

/**
Expand All @@ -53,6 +57,7 @@ const connectVattpWithMailbox = ({
};

/**
* TODO: { dynamicVats: { bank: true }} thingy?
*
* @param {{
* vats: { vatAdmin: VatAdminVat },
Expand Down Expand Up @@ -182,13 +187,33 @@ 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,
buildZoe,
makeBoard,
makeAddressNameHubs,
installClientEgress,
makeClientBanks,
});
export {
connectVattpWithMailbox,
Expand All @@ -197,4 +222,5 @@ export {
makeBoard,
makeAddressNameHubs,
installClientEgress,
makeClientBanks,
};
12 changes: 10 additions & 2 deletions packages/vats/src/bootstrap-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const extract = (template, specimen) => {
}
};

const manifestByRole = {
'sim-chain': simBootstrapManifest,
};
/**
* Build root object of the bootstrap vat.
*
Expand All @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit 9e53f4f

Please sign in to comment.