Skip to content

Instantly share code, notes, and snippets.

@warner
Last active July 18, 2020 18:03
Show Gist options
  • Save warner/ee5168d1afc4679ef92ce5164cb982b7 to your computer and use it in GitHub Desktop.
Save warner/ee5168d1afc4679ef92ce5164cb982b7 to your computer and use it in GitHub Desktop.
make-vat-transcript
/* global harden */
import { E } from '@agoric/eventual-send';
import { producePromise } from '@agoric/produce-promise';
function ignore(p) {
p.then(() => 0, () => 0);
}
export function buildRootObject() {
const callbackObj = harden({
callback(arg1, arg2) {
console.log(`callback`, arg1, arg2);
return ['data', callbackObj]; // four, resolves pF
},
});
let precD = producePromise();
let precE = producePromise();
return harden({
bootstrap(_argv, vats) {
const pA = E(vats.target).zero(callbackObj, precD.promise, precE.promise);
const rp3 = E(vats.target).one();
precD.resolve(callbackObj); // two
precE.reject(Error('four')); // three
pA.then(([pB, pC]) => { ignore(pB); ignore(pC); });
},
});
}
# prepare:
# git clone https://github.com/Agoric/agoric-sdk
# cd agoric-sdk
# yarn
# git clone (this gist)
# cd make-vat-transcript
../packages/swingset-runner/bin/runner --filedb run
# if that complains about 'env' not recognizing the -S option, use this:
# node -r esm ../packages/swingset-runner/bin/runner --filedb run
../packages/swingset-runner/bin/kerneldump --filedb ./swingset-kernel-state | grep v1.t |sort
# ditto
# that last command emits the transcript for vat-target
v1.t.0 :: {"d":["deliver","o+0","zero",{"body":"[{\"@qclass\":\"slot\",\"index\":0},{\"@qclass\":\"slot\",\"index\":1},{\"@qclass\":\"slot\",\"index\":2}]","slots":["o-50","p-60","p-61"]},"p-62"],"syscalls":[{"d":["subscribe","p-60"],"response":null},{"d":["subscribe","p-61"],"response":null},{"d":["send","o-50","callback",{"body":"[11,12]","slots":[]},"p+5"],"response":null},{"d":["subscribe","p+5"],"response":null},{"d":["fulfillToData","p-62",{"body":"[{\"@qclass\":\"slot\",\"index\":0},{\"@qclass\":\"slot\",\"index\":1}]","slots":["p+6","p+7"]}],"response":null}],"crankNumber":2}
v1.t.1 :: {"d":["deliver","o+0","one",{"body":"[]","slots":[]},"p-63"],"syscalls":[{"d":["fulfillToPresence","p+6","o-50"],"response":null},{"d":["reject","p+7",{"body":"{\"@qclass\":\"error\",\"name\":\"Error\",\"message\":\"oops\"}","slots":[]}],"response":null},{"d":["fulfillToData","p-63",{"body":"1","slots":[]}],"response":null}],"crankNumber":3}
v1.t.2 :: {"d":["notifyFulfillToPresence","p-60","o-50"],"syscalls":[],"crankNumber":4}
v1.t.3 :: {"d":["notifyReject","p-61",{"body":"{\"@qclass\":\"error\",\"name\":\"Error\",\"message\":\"four\"}","slots":[]}],"syscalls":[],"crankNumber":5}
v1.t.4 :: {"d":["notifyFulfillToData","p+5",{"body":"[\"data\",{\"@qclass\":\"slot\",\"index\":0}]","slots":["o-50"]}],"syscalls":[],"crankNumber":9}
v1.t.nextID :: 5
/* global harden */
import { E } from '@agoric/eventual-send';
import { producePromise } from '@agoric/produce-promise';
function ignore(p) {
p.then(() => 0, () => 0);
}
// We arrange for this vat, 'vat-target', to receive a specific set of
// inbound events ('dispatch'), which will provoke a set of outbound events
// ('syscall'), that cover the full range of the dispatch/syscall interface
export function buildRootObject() {
let precB = producePromise();
let precC = producePromise();
let callbackObj;
// zero: dispatch.deliver(target, method="one", result=pA, args=[callbackObj, pD, pE])
// syscall.subscribe(pD)
// syscall.subscribe(pE)
// syscall.send(callbackObj, method="callback", result=rp2, args=[11, 12]);
// syscall.subscribe(rp2)
// syscall.fulfillToData(pA, [pB, pC]);
function zero(obj, pD, pE) {
callbackObj = obj;
const pF = E(callbackObj).callback(11,12); // syscall.send
ignore(pD);
ignore(pE);
return [precB.promise, precC.promise]; // syscall.fulfillToData
}
// one: dispatch.deliver(target, method="two", result=rp3, args=[])
// syscall.fulfillToPresence(pB, callbackObj)
// syscall.reject(pC, Error('oops'))
// syscall.fulfillToData(rp3, 1)
function one() {
precB.resolve(callbackObj); // syscall.fulfillToPresence
precC.reject(Error('oops')); // syscall.reject
return 1;
}
// two: dispatch.notifyFulfillToPresence(pD, callbackObj)
// three: dispatch.notifyReject(pE, Error('four'))
// four: dispatch.notifyFulfillToData(pF, ['data', callbackObj])
const target = harden({
zero, one,
});
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment