diff --git a/lib/ag-solo/vats/bootstrap.js b/lib/ag-solo/vats/bootstrap.js index c8345dffb2c..dc828143511 100644 --- a/lib/ag-solo/vats/bootstrap.js +++ b/lib/ag-solo/vats/bootstrap.js @@ -47,6 +47,11 @@ export default function setup(syscall, state, helpers) { moolaMint: await E(vats.mints).getMint('moola'), simoleanMint: await E(vats.mints).getMint('simolean'), spawner, + http: { + registerCommandHandler(handler) { + return E(vats.http).registerCommandHandler(handler); + }, + }, wallet: await E(vats.wallet).getWallet(), }); } diff --git a/lib/ag-solo/vats/vat-http.js b/lib/ag-solo/vats/vat-http.js index 64ac8b1cabf..cadf7649037 100644 --- a/lib/ag-solo/vats/vat-http.js +++ b/lib/ag-solo/vats/vat-http.js @@ -36,6 +36,12 @@ function build(E, D) { const registeredHandlers = []; let canvasState; + // TODO: Don't leak memory. + async function registerCommandHandler(newHandler) { + const commandHandler = await E(newHandler).getCommandHandler(); + registeredHandlers.push(commandHandler); + } + return { setCommandDevice(d, ROLES) { commandDevice = d; @@ -118,10 +124,7 @@ function build(E, D) { } }, - async registerCommandHandler(newHandler) { - const commandHandler = await E(newHandler).getCommandHandler(); - registeredHandlers.push(commandHandler); - }, + registerCommandHandler, setProvisioner(p) { provisioner = p; @@ -171,8 +174,11 @@ function build(E, D) { res = await handler[type](obj); } else { // todo fixme avoid the loop - for (let i = 0; i < registeredHandlers.length; i++) { - res = await E(registeredHandlers[i]).processInbound(obj); + // For now, go from the end to beginning so that handlers + // override. + const hardObjects = harden({...homeObjects}); + for (let i = registeredHandlers.length - 1; i >= 0; i++) { + res = await E(registeredHandlers[i]).processInbound(obj, hardObjects); if (res) { break; }