@agoric/swingset-vat 0.32.3-dev-f20cc05.0 → 0.32.3-dev-9f8a76e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/swingset-vat",
3
- "version": "0.32.3-dev-f20cc05.0+f20cc05",
3
+ "version": "0.32.3-dev-9f8a76e.0+9f8a76e",
4
4
  "description": "Vat/Container Launcher",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -27,16 +27,16 @@
27
27
  "@types/yargs-parser": "^21.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@agoric/assert": "0.6.1-dev-f20cc05.0+f20cc05",
31
- "@agoric/internal": "0.3.3-dev-f20cc05.0+f20cc05",
32
- "@agoric/store": "0.9.3-dev-f20cc05.0+f20cc05",
33
- "@agoric/swing-store": "0.9.2-dev-f20cc05.0+f20cc05",
34
- "@agoric/swingset-liveslots": "0.10.3-dev-f20cc05.0+f20cc05",
35
- "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-f20cc05.0+f20cc05",
36
- "@agoric/time": "0.3.3-dev-f20cc05.0+f20cc05",
37
- "@agoric/vat-data": "0.5.3-dev-f20cc05.0+f20cc05",
38
- "@agoric/xsnap": "0.14.3-dev-f20cc05.0+f20cc05",
39
- "@agoric/xsnap-lockdown": "0.14.1-dev-f20cc05.0+f20cc05",
30
+ "@agoric/assert": "0.6.1-dev-9f8a76e.0+9f8a76e",
31
+ "@agoric/internal": "0.3.3-dev-9f8a76e.0+9f8a76e",
32
+ "@agoric/store": "0.9.3-dev-9f8a76e.0+9f8a76e",
33
+ "@agoric/swing-store": "0.9.2-dev-9f8a76e.0+9f8a76e",
34
+ "@agoric/swingset-liveslots": "0.10.3-dev-9f8a76e.0+9f8a76e",
35
+ "@agoric/swingset-xsnap-supervisor": "0.10.3-dev-9f8a76e.0+9f8a76e",
36
+ "@agoric/time": "0.3.3-dev-9f8a76e.0+9f8a76e",
37
+ "@agoric/vat-data": "0.5.3-dev-9f8a76e.0+9f8a76e",
38
+ "@agoric/xsnap": "0.14.3-dev-9f8a76e.0+9f8a76e",
39
+ "@agoric/xsnap-lockdown": "0.14.1-dev-9f8a76e.0+9f8a76e",
40
40
  "@endo/base64": "^0.2.32",
41
41
  "@endo/bundle-source": "^2.5.2",
42
42
  "@endo/captp": "^3.1.2",
@@ -93,5 +93,5 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "f20cc0580a0a6cb947f3a5c1ef1281fccca879f0"
96
+ "gitHead": "9f8a76ee66bd74f028158b689c4b437921613f63"
97
97
  }
@@ -0,0 +1,126 @@
1
+ import { assert } from '@agoric/assert';
2
+ import { objectMap } from '@agoric/internal';
3
+ import { Far, E } from '@endo/far';
4
+ import { buildManualTimer } from './manual-timer.js';
5
+ import { makePassableEncoding } from './passableEncoding.js';
6
+
7
+ const { Fail, quote: q } = assert;
8
+
9
+ export const buildRootObject = () => {
10
+ const timer = buildManualTimer();
11
+ let vatAdmin;
12
+ const vatData = new Map();
13
+ const devicesByName = new Map();
14
+ const callLogsByRemotable = new Map();
15
+
16
+ const { encodePassable, decodePassable } = makePassableEncoding();
17
+
18
+ return Far('root', {
19
+ bootstrap: async (vats, devices) => {
20
+ vatAdmin = await E(vats.vatAdmin).createVatAdminService(devices.vatAdmin);
21
+ for (const [name, root] of Object.entries(vats)) {
22
+ if (name !== 'vatAdmin') {
23
+ vatData.set(name, { root });
24
+ }
25
+ }
26
+ for (const [name, device] of Object.entries(devices)) {
27
+ devicesByName.set(name, device);
28
+ }
29
+ },
30
+
31
+ getDevice: async deviceName =>
32
+ encodePassable(devicesByName.get(deviceName)),
33
+
34
+ getVatAdmin: async () => encodePassable(vatAdmin),
35
+
36
+ getTimer: async () => encodePassable(timer),
37
+
38
+ getVatRoot: async ({ name, rawOutput = false }) => {
39
+ const vat = vatData.get(name) || Fail`unknown vat name: ${q(name)}`;
40
+ const { root } = vat;
41
+ return rawOutput ? root : encodePassable(root);
42
+ },
43
+
44
+ createVat: async ({ name, bundleCapName, vatParameters = {} }) => {
45
+ const bcap = await E(vatAdmin).getNamedBundleCap(bundleCapName);
46
+ const options = { vatParameters };
47
+ const { adminNode, root } = await E(vatAdmin).createVat(bcap, options);
48
+ vatData.set(name, { adminNode, root });
49
+ return encodePassable(root);
50
+ },
51
+
52
+ upgradeVat: async ({ name, bundleCapName, vatParameters = {} }) => {
53
+ const vat = vatData.get(name) || Fail`unknown vat name: ${q(name)}`;
54
+ const bcap = await E(vatAdmin).getNamedBundleCap(bundleCapName);
55
+ const options = { vatParameters };
56
+ const incarnationNumber = await E(vat.adminNode).upgrade(bcap, options);
57
+ vat.incarnationNumber = incarnationNumber;
58
+ return incarnationNumber;
59
+ },
60
+
61
+ /**
62
+ * Derives a remotable from an object by mapping each object property into a method that returns the value.
63
+ * This function is intended to be called from testing code outside of the vat environment,
64
+ * but methods of the returned remotable are intended to be called from *inside* that environment
65
+ * and therefore do not perform argument/response translation.
66
+ *
67
+ * @param {string} label
68
+ * @param {Record<string, any>} encodedMethodReturnValues
69
+ */
70
+ makeRemotable: (label, encodedMethodReturnValues) => {
71
+ const callLogs = [];
72
+ const makeGetterFunction = (value, name) => {
73
+ const getValue = (...args) => {
74
+ callLogs.push([name, ...args]);
75
+ return value;
76
+ };
77
+ return getValue;
78
+ };
79
+ const methodReturnValues = decodePassable(encodedMethodReturnValues);
80
+ // `objectMap` hardens its result, but...
81
+ const methods = objectMap(methodReturnValues, makeGetterFunction);
82
+ // ... `Far` requires its methods argument not to be hardened.
83
+ const unhardenedMethods = { ...methods };
84
+ const remotable = Far(label, unhardenedMethods);
85
+ callLogsByRemotable.set(remotable, callLogs);
86
+ return encodePassable(remotable);
87
+ },
88
+
89
+ /**
90
+ * Returns a copy of a remotable's logs.
91
+ *
92
+ * @param {object} encodedRemotable
93
+ */
94
+ getLogForRemotable: encodedRemotable => {
95
+ const remotable = decodePassable(encodedRemotable);
96
+ const decodedLogs =
97
+ callLogsByRemotable.get(remotable) ||
98
+ Fail`logs not found for ${q(remotable)}`;
99
+ // Return a copy so that the original remains mutable.
100
+ return encodePassable(harden([...decodedLogs]));
101
+ },
102
+
103
+ messageVat: async ({ name, methodName, args = [] }) => {
104
+ const vat = vatData.get(name) || Fail`unknown vat name: ${q(name)}`;
105
+ const { root } = vat;
106
+ const decodedArgs = args.map(decodePassable);
107
+ const result = await E(root)[methodName](...decodedArgs);
108
+ return encodePassable(result);
109
+ },
110
+
111
+ messageVatObject: async ({ presence, methodName, args = [] }) => {
112
+ const object = decodePassable(presence);
113
+ const decodedArgs = args.map(decodePassable);
114
+ const result = await E(object)[methodName](...decodedArgs);
115
+ return encodePassable(result);
116
+ },
117
+
118
+ awaitVatObject: async ({ presence, path = [], rawOutput = false }) => {
119
+ let value = await decodePassable(presence);
120
+ for (const key of path) {
121
+ value = await value[key];
122
+ }
123
+ return rawOutput ? value : encodePassable(value);
124
+ },
125
+ });
126
+ };