Skip to content

Commit

Permalink
feat: just enough mechanism to support the provisioning transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 1, 2020
1 parent 30fcc4f commit 889a5db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ export default function setup(syscall, state, helpers) {
}),
);
}

if (bridgeMgr) {
// Register a provisioning handler over the bridge.
const handler = harden({
async fromBridge(_srcID, obj) {
switch (obj.type) {
case 'PLEASE_PROVISION': {
if (!packetSendersWhitelist.includes(obj.submitter)) {
throw Error('Permission denied');
}
const { nickname, address } = obj;
return E(vats.provisioning)
.pleaseProvision(nickname, address, PROVISIONER_INDEX)
.then(_ =>
bridgeMgr.toBridge('provision', {
type: 'PROVISIONED',
nickname,
address,
}),
);
}
default:
throw Error(`Unrecognized request ${obj.type}`);
}
},
});
bridgeMgr.register('provision', handler);
}
}

// objects that live in the client's solo vat. Some services should only
Expand Down Expand Up @@ -262,7 +290,7 @@ export default function setup(syscall, state, helpers) {
devices.bridge && makeBridgeManager(E, D, devices.bridge);
const [ROLE, bootAddress, additionalAddresses] = parseArgs(argv);

const pswl = [bootAddress];
const pswl = [bootAddress, ...additionalAddresses];

async function addRemote(addr) {
const { transmitter, setReceiver } = await E(vats.vattp).addRemote(
Expand All @@ -274,6 +302,7 @@ export default function setup(syscall, state, helpers) {
D(devices.mailbox).registerInboundHandler(vats.vattp);
await E(vats.vattp).registerMailboxDevice(devices.mailbox);
if (bootAddress) {
// FIXME: The old way: register egresses for the addresses.
await Promise.all(
[bootAddress, ...additionalAddresses].map(addr =>
addRemote(addr),
Expand Down Expand Up @@ -390,6 +419,13 @@ export default function setup(syscall, state, helpers) {
// bootAddress holds the pubkey of localclient
const chainBundler = await makeChainBundler(vats, devices.timer);

// Allow manual provisioning requests via `agoric cosmos`.
await E(vats.provisioning).register(
chainBundler,
vats.comms,
vats.vattp,
);

await registerNetworkProtocols(vats, bridgeManager, pswl);

const demoProvider = harden({
Expand Down
6 changes: 6 additions & 0 deletions packages/cosmic-swingset/lib/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const DELIVER_INBOUND = 'DELIVER_INBOUND';
const END_BLOCK = 'END_BLOCK';
const COMMIT_BLOCK = 'COMMIT_BLOCK';
const IBC_EVENT = 'IBC_EVENT';
const PLEASE_PROVISION = 'PLEASE_PROVISION';

export default function makeBlockManager({
deliverInbound,
Expand Down Expand Up @@ -51,6 +52,11 @@ export default function makeBlockManager({
break;
}

case PLEASE_PROVISION: {
p = doBridgeInbound('provision', action);
break;
}

case END_BLOCK:
p = Promise.resolve();
break;
Expand Down

0 comments on commit 889a5db

Please sign in to comment.