Skip to content

Commit

Permalink
Simplify code; drop unnecessary checks, in-line trivial functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jan 23, 2020
1 parent 83c3741 commit 5f6d335
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
37 changes: 10 additions & 27 deletions packages/SwingSet/src/kernel/vatAdmin/vatAdmin-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import harden from '@agoric/harden';
* root device. Selected vats that need to create new vats can be given access
* to the device.
*
* This code runs in the inner part of the device vat. It handles kernel objects
* in serialized format, and can use SO() to send messages to them. The only
* device object exposed to vats is the vat creator. The root objects for the
* new vats are returned as javascript objects.
* This code runs in the inner part of the device vat. The only device object
* exposed to vats is the vat creator. The root objects for the new vats are
* returned as javascript objects.
*
* We don't currently need to use SO, or to maintain state. All functionality is
* provided by calling kernel functions and passing in the VatID. The wrapper
Expand All @@ -26,40 +25,24 @@ export default function setup(syscall, state, helpers, endowments) {
// terminate: kernelTerminateFn,
} = endowments;

// call the registered kernel function to create a new vat, and receive a
// vatId in return. Clean up the outgoing and incoming arguments.
function callKernelVatCreation(src) {
return kernelVatCreationFn(`${src}`);
}

// Call the registered kernel function to request vat stats. Clean up the
// outgoing and incoming arguments.
function callKernelVatStats(vatId) {
if (!kernelVatStatsFn || typeof kernelVatStatsFn !== 'function') {
throw new Error(
`Attempted to request stats before registering kernel function`,
);
}
const cleanVatId = `${vatId}`;
return kernelVatStatsFn(cleanVatId);
}

// makeRootDevice is called with { _SO, _getDeviceState, _setDeviceState } as
// a parameter, but we don't need these, as discussed above.
// makeRootDevice is called with { SO, getDeviceState, setDeviceState } as
// parameters, but we don't need these, as discussed above.
function makeRootDevice() {
// The Root Device Node.
return harden({
// Called by the wrapper vat to create a new vat. Gets a new ID from the
// kernel's vat creator fn. Remember that the root object will arrive
// separately.
// separately. Clean up the outgoing and incoming arguments.
create(code) {
return callKernelVatCreation(code);
return kernelVatCreationFn(`${code}`);
},
terminate(_vatID) {
// TODO(hibbert)
},
// Call the registered kernel function to request vat stats. Clean up the
// outgoing and incoming arguments.
adminStats(vatID) {
return callKernelVatStats(vatID);
return kernelVatStatsFn(`${vatID}`);
},
});
}
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/test/vat-admin/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export default function setup(syscall, state, helpers) {
devices.vatAdmin,
);
const { adminNode } = await E(vatAdminSvc).createVat(src);
const stats = await E(adminNode).adminData();
log(stats);
log(await E(adminNode).adminData());
return;
}
default:
Expand Down

0 comments on commit 5f6d335

Please sign in to comment.