From 2be2939dc648988e7a8d7fdb7db9c7334c285f40 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Wed, 8 Dec 2021 20:45:13 -0600 Subject: [PATCH] feat(vats): boostrap-core connects vattp<->mailbox (WIP) REGRESSION: bootstrap.js is skipped! - provide bootstrap() method per swingset - avoid: deliverInboundMessages before registerInboundHandler - refactor(vats): factor out connectVattpWithMailbox --- packages/vats/decentral-config.json | 2 +- packages/vats/src/bootstrap-core.js | 43 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 packages/vats/src/bootstrap-core.js diff --git a/packages/vats/decentral-config.json b/packages/vats/decentral-config.json index c535bcecacc..74483efcb16 100644 --- a/packages/vats/decentral-config.json +++ b/packages/vats/decentral-config.json @@ -44,7 +44,7 @@ } }, "bootstrap": { - "sourceSpec": "./src/bootstrap.js" + "sourceSpec": "./src/bootstrap-core.js" } } } diff --git a/packages/vats/src/bootstrap-core.js b/packages/vats/src/bootstrap-core.js new file mode 100644 index 00000000000..4380733f6de --- /dev/null +++ b/packages/vats/src/bootstrap-core.js @@ -0,0 +1,43 @@ +// @ts-check +import { E, Far } from '@agoric/far'; + +/** + * @typedef { import('@agoric/eventual-send').EProxy } EProxy + * @typedef { ReturnType } MailboxDevice + * @typedef { ReturnType } VattpVat + */ + +/** + * Build root object of the bootstrap vat. + * + * @param {{ + * D: EProxy // approximately + * }} vatPowers + * @param {Record} _vatParameters + */ +export function buildRootObject(vatPowers, _vatParameters) { + const { D } = vatPowers; + + /** + * @param {VattpVat} vattp + * @param {MailboxDevice} mailbox + */ + const connectVattpWithMailbox = async (vattp, mailbox) => { + D(mailbox).registerInboundHandler(vattp); + await E(vattp).registerMailboxDevice(mailbox); + }; + + return Far('bootstrap', { + /** + * Bootstrap vats and devices. + * + * @param {{vattp: VattpVat }} vats + * @param {{mailbox: MailboxDevice}} devices + */ + bootstrap: async (vats, devices) => { + await connectVattpWithMailbox(vats.vattp, devices.mailbox); + }, + }); +}