Skip to content

Commit

Permalink
fix: rearrange home into local and agoric
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 27, 2020
1 parent e87fecc commit 44ba391
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
21 changes: 9 additions & 12 deletions packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ export function buildRootObject(vatPowers) {
payments,
issuerInfo,
);
await E(vats.http).setPresences(
{ ...bundle, localTimerService },
localBundle,
);
await E(vats.http).setPresences(localBundle, bundle, {
localTimerService,
});
await setupWalletVat(localBundle.http, vats.http, vats.wallet);
break;
}
Expand Down Expand Up @@ -462,10 +461,9 @@ export function buildRootObject(vatPowers) {
payments,
issuerInfo,
);
await E(vats.http).setPresences(
{ ...bundle, localTimerService },
localBundle,
);
await E(vats.http).setPresences(localBundle, bundle, {
localTimerService,
});
await setupWalletVat(localBundle.http, vats.http, vats.wallet);
break;
}
Expand Down Expand Up @@ -496,10 +494,9 @@ export function buildRootObject(vatPowers) {
payments,
issuerInfo,
);
await E(vats.http).setPresences(
{ ...bundle, localTimerService: bundle.chainTimerService },
localBundle,
);
await E(vats.http).setPresences(localBundle, bundle, {
localTimerService: bundle.chainTimerService,
});

setupWalletVat(localBundle.http, vats.http, vats.wallet);
break;
Expand Down
12 changes: 7 additions & 5 deletions packages/cosmic-swingset/lib/ag-solo/vats/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function stringify(
return ret;
}

export function getReplHandler(homeObjects, send, vatPowers) {
export function getReplHandler(replObjects, send, vatPowers) {
// We use getInterfaceOf locally, and transformTildot is baked into the
// Compartment we use to evaluate REPL inputs. We provide getInterfaceOf
// and Remotable to REPL input code.
Expand Down Expand Up @@ -149,6 +149,10 @@ export function getReplHandler(homeObjects, send, vatPowers) {
});

replConsole.log(`Welcome to Agoric!`);

// TODO: Remove
const agentMakers = makeUIAgentMakers({ harden, console: replConsole });

const endowments = {
Remotable,
getInterfaceOf,
Expand All @@ -157,8 +161,9 @@ export function getReplHandler(homeObjects, send, vatPowers) {
HandledPromise,
commands,
history,
home: homeObjects,
harden,
agent: agentMakers, // TODO: Remove
...replObjects,
};
const modules = {};
const transforms = [];
Expand All @@ -170,9 +175,6 @@ export function getReplHandler(homeObjects, send, vatPowers) {
const options = { transforms };
const c = new Compartment(endowments, modules, options);

const agentMakers = makeUIAgentMakers({ harden, console: replConsole });
homeObjects.agent = agentMakers;

const handler = {
getHighestHistory() {
return { highestHistory };
Expand Down
49 changes: 39 additions & 10 deletions packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export function buildRootObject(vatPowers) {
loaded.rej = reject;
});
harden(loaded);
const homeObjects = { LOADING: loaded.p };
const replObjects = {
home: { LOADING: loaded.p }, // TODO: Remove
agoric: { LOADING: loaded.p },
local: {},
};
let isReady = false;
const readyForClient = {};
let exportedToCapTP = {
Expand Down Expand Up @@ -69,7 +73,7 @@ export function buildRootObject(vatPowers) {
if (ROLES.client) {
handler.readyForClient = () => readyForClient.p;

const replHandler = getReplHandler(homeObjects, send, vatPowers);
const replHandler = getReplHandler(replObjects, send, vatPowers);
registerURLHandler(replHandler, '/private/repl');

// Assign the captp handler.
Expand Down Expand Up @@ -116,16 +120,41 @@ export function buildRootObject(vatPowers) {
provisioner = p;
},

setPresences(ps, privateObjects) {
setPresences(
privateObjects,
decentralObjects = undefined,
handyObjects = undefined,
) {
exportedToCapTP = {
LOADING: loaded.p,
READY: exportedToCapTP.READY,
...ps,
...privateObjects,
...decentralObjects, // TODO: Remove; replaced by .agoric
...privateObjects, // TODO: Remove; replaced by .local
...handyObjects,
LOADING: loaded.p, // TODO: Remove; replaced by .agoric.LOADING
agoric: { decentralObjects, LOADING: loaded.p },
local: privateObjects,
};
Object.assign(homeObjects, ps, privateObjects);
loaded.res('chain bundle loaded');
delete homeObjects.LOADING;

// We need to mutate the repl subobjects instead of replacing them.
if (privateObjects) {
Object.assign(replObjects.local, privateObjects);
}

if (decentralObjects) {
loaded.res('chain bundle loaded');
Object.assign(replObjects.agoric, decentralObjects);
delete replObjects.agoric.LOADING;
}

// TODO: Remove; home object is deprecated.
if (decentralObjects) {
Object.assign(
replObjects.home,
decentralObjects,
privateObjects,
handyObjects,
);
delete replObjects.home.LOADING;
}
},

// devices.command invokes our inbound() because we passed to
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/test/unitTests/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function make() {
const send = m => sentMessages.push(m);
const transformTildot = makeTransform(babelParser, babelGenerate);
const vatPowers = { transformTildot };
const rh = getReplHandler(homeObjects, send, vatPowers);
const rh = getReplHandler({ home: homeObjects }, send, vatPowers);

const ch = rh.getCommandHandler();
function getHighestHistory() {
Expand Down

0 comments on commit 44ba391

Please sign in to comment.