Skip to content

Commit

Permalink
fix: remove use of Data() from all packages
Browse files Browse the repository at this point in the history
Now that `harden({})` is pass-by-copy, we no longer need the Data() marker.

refs #2018
  • Loading branch information
warner committed Mar 16, 2021
1 parent 41748eb commit d8cee03
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 61 deletions.
3 changes: 1 addition & 2 deletions packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
passStyleOf,
REMOTE_STYLE,
getInterfaceOf,
Data,
} from '@agoric/marshal';

// TODO: assertSubset and assertKeysAllowed are copied from Zoe. Move
Expand Down Expand Up @@ -64,7 +63,7 @@ export const coerceDisplayInfo = allegedDisplayInfo => {
assert.equal(Reflect.ownKeys(allegedDisplayInfo).length, 0);
assert.equal(Object.getPrototypeOf(allegedDisplayInfo), Object.prototype);
assert.equal(getInterfaceOf(allegedDisplayInfo), undefined);
return Data({});
return harden({});
}
allegedDisplayInfo = pureCopy(allegedDisplayInfo);
assertDisplayInfo(allegedDisplayInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';

import { Far, Data } from '@agoric/marshal';
import { Far } from '@agoric/marshal';

import { amountMath as m, MathKind } from '../../../src';
import { mockBrand } from './mockBrand';
Expand Down Expand Up @@ -115,7 +115,7 @@ const runSetMathHelpersTests = (t, [a, b, c], a2 = undefined) => {
`m.isEmpty([]) is true`,
);
t.throws(
() => m.isEmpty({ brand: mockBrand, value: Data({}) }),
() => m.isEmpty({ brand: mockBrand, value: harden({}) }),
{ message: `value (an object) must be a Nat or an array` },
`m.isEmpty({}) throws`,
);
Expand Down
3 changes: 1 addition & 2 deletions packages/ERTP/test/unitTests/test-issuerObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';
import { E } from '@agoric/eventual-send';
import { Data } from '@agoric/marshal';
import { MathKind, makeIssuerKit, amountMath } from '../../src';

test('issuer.getBrand, brand.isMyIssuer', t => {
Expand Down Expand Up @@ -48,7 +47,7 @@ test('bad display info', t => {
});

test('empty display info', t => {
const displayInfo = Data({});
const displayInfo = harden({});
const { brand } = makeIssuerKit('fungible', MathKind.NAT, displayInfo);
t.deepEqual(brand.getDisplayInfo(), displayInfo);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/initializeKernel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-use-before-define */

import { makeMarshal, Far, Data } from '@agoric/marshal';
import { makeMarshal, Far } from '@agoric/marshal';
import { assert, details as X } from '@agoric/assert';
import { assertKnownOptions } from '../assertOptions';
import { insistVatID } from './id';
Expand Down Expand Up @@ -169,7 +169,7 @@ export function initializeKernel(config, hostStorage, verbose = false) {
const m = makeMarshal(convertValToSlot, undefined, {
marshalName: 'kernel:bootstrap',
});
const args = harden([Data(vatObj0s), Data(deviceObj0s)]);
const args = harden([vatObj0s, deviceObj0s]);
// queueToExport() takes kernel-refs (ko+NN, kd+NN) in s.slots
const rootSlot = makeVatRootObjectSlot();
const resultKpid = doQueueToExport(
Expand Down
3 changes: 1 addition & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// in its own makeHardener, etc.
import { makeCapTP } from '@agoric/captp/lib/captp';
import { E } from '@agoric/eventual-send';
import { Data } from '@agoric/marshal';

export const getCapTPHandler = (
send,
Expand All @@ -12,7 +11,7 @@ export const getCapTPHandler = (
const chans = new Map();
const doFallback = async (method, ...args) => {
if (!fallback) {
return Data({});
return harden({});
}
return E(fallback)[method](...args);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function buildRootObject(vatPowers) {
...decentralObjects, // TODO: Remove; replaced by .agoric
...privateObjects, // TODO: Remove; replaced by .local
...handyObjects,
agoric: { ...decentralObjects }, // TODO: maybe needs Data()???
agoric: { ...decentralObjects },
local: { ...privateObjects },
};

Expand Down
12 changes: 6 additions & 6 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeIssuerTable } from '@agoric/zoe/src/issuerTable';

import { E } from '@agoric/eventual-send';

import { makeMarshal, passStyleOf, Far, Data } from '@agoric/marshal';
import { makeMarshal, passStyleOf, Far } from '@agoric/marshal';
import { makeNotifierKit, observeNotifier } from '@agoric/notifier';
import { makePromiseKit } from '@agoric/promise-kit';

Expand Down Expand Up @@ -470,7 +470,7 @@ export function makeWallet({
// Payments are made for the keywords in proposal.give.
const keywords = [];

const paymentPs = Object.entries(proposal.give || Data({})).map(
const paymentPs = Object.entries(proposal.give || harden({})).map(
([keyword, amount]) => {
const purse = purseKeywordRecord[keyword];
assert(
Expand All @@ -491,7 +491,7 @@ export function makeWallet({
// for the offer.
const payments = await Promise.all(paymentPs);

const paymentKeywordRecord = Data(
const paymentKeywordRecord = harden(
Object.fromEntries(keywords.map((keyword, i) => [keyword, payments[i]])),
);

Expand Down Expand Up @@ -691,15 +691,15 @@ export function makeWallet({

const compileProposal = proposalTemplate => {
const {
want = Data({}),
give = Data({}),
want = harden({}),
give = harden({}),
exit = { onDemand: null },
} = proposalTemplate;

const purseKeywordRecord = {};

const compile = amountKeywordRecord => {
return Data(
return harden(
Object.fromEntries(
Object.entries(amountKeywordRecord).map(
([keyword, { pursePetname, value }]) => {
Expand Down
7 changes: 3 additions & 4 deletions packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import test from 'ava';
// eslint-disable-next-line import/no-extraneous-dependencies
import bundleSource from '@agoric/bundle-source';
import { makeIssuerKit, makeLocalAmountMath } from '@agoric/ertp';
import { Data } from '@agoric/marshal';

import { makeZoe } from '@agoric/zoe';
import fakeVatAdmin from '@agoric/zoe/src/contractFacet/fakeVatAdmin';
Expand Down Expand Up @@ -276,7 +275,7 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t

inviteHandleBoardId,

proposalTemplate: Data({}),
proposalTemplate: {},
});

const rawId = '1588645041696';
Expand Down Expand Up @@ -1201,7 +1200,7 @@ test('addOffer makeContinuingInvitation', async t => {
instance,
description: 'FirstThing',
},
proposalTemplate: Data({}),
proposalTemplate: harden({}),
};

await wallet.addOffer(offer);
Expand All @@ -1224,7 +1223,7 @@ test('addOffer makeContinuingInvitation', async t => {
priorOfferId: rawId,
description: 'SecondThing',
},
proposalTemplate: Data({}),
proposalTemplate: harden({}),
};

await wallet.addOffer(offer2);
Expand Down
6 changes: 3 additions & 3 deletions packages/swingset-runner/src/vat-launcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { E } from '@agoric/eventual-send';
import { Far, Data } from '@agoric/marshal';
import { Far } from '@agoric/marshal';

/*
* Vat to launch other vats.
Expand Down Expand Up @@ -41,14 +41,14 @@ export function buildRootObject(_vatPowers, vatParameters) {
// eslint-disable-next-line no-await-in-loop
const vat = await E(vatMaker).createVatByName(
bundleName,
{ metered: vatParameters.metered, vatParameters: Data(subvatParameters) },
{ metered: vatParameters.metered, vatParameters: harden(subvatParameters) },
);
vatRoots[vatName] = vat.root;
}
vatRoots.vatAdmin = vats.vatAdmin;
bootstrapRoot = vatRoots[vatParameters.config.bootstrap];
// prettier-ignore
return E(bootstrapRoot).bootstrap(Data(vatRoots), devices);
return E(bootstrapRoot).bootstrap(harden(vatRoots), devices);
},
runBenchmarkRound() {
return E(bootstrapRoot).runBenchmarkRound();
Expand Down
3 changes: 1 addition & 2 deletions packages/zoe/src/cleanProposal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assert, details as X, q } from '@agoric/assert';
import { mustBeComparable } from '@agoric/same-structure';
import { isNat } from '@agoric/nat';
import { Data } from '@agoric/marshal';

import '../exported';
import './internal-types';
Expand Down Expand Up @@ -111,7 +110,7 @@ export const cleanProposal = (getAmountMath, proposal) => {
assertKeysAllowed(rootKeysAllowed, proposal);

// We fill in the default values if the keys are undefined.
let { want = Data({}), give = Data({}) } = proposal;
let { want = harden({}), give = harden({}) } = proposal;
const { exit = harden({ onDemand: null }) } = proposal;

want = coerceAmountKeywordRecord(getAmountMath, want);
Expand Down
10 changes: 5 additions & 5 deletions packages/zoe/src/contractFacet/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { assert, details as X, q, makeAssert } from '@agoric/assert';
import { E } from '@agoric/eventual-send';
import { makeStore, makeWeakStore } from '@agoric/store';
import { Far, Data } from '@agoric/marshal';
import { Far } from '@agoric/marshal';

import { makeAmountMath, MathKind } from '@agoric/ertp';
import { makeNotifierKit, observeNotifier } from '@agoric/notifier';
Expand Down Expand Up @@ -148,7 +148,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
};

const makeEmptySeatKit = (exit = undefined) => {
const initialAllocation = Data({});
const initialAllocation = harden({});
const proposal = cleanProposal(getAmountMath, harden({ exit }));
const { notifier, updater } = makeNotifierKit();
/** @type {PromiseRecord<ZoeSeatAdmin>} */
Expand Down Expand Up @@ -252,7 +252,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
: amountToAdd;
return [seatKeyword, newAmount];
});
const newAllocation = Data({
const newAllocation = harden({
...oldAllocation,
...updates,
});
Expand Down Expand Up @@ -291,7 +291,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
return [seatKeyword, newAmount];
},
);
const newAllocation = Data({
const newAllocation = harden({
...oldAllocation,
...updates,
});
Expand Down Expand Up @@ -368,7 +368,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
makeInvitation: (
offerHandler = () => {},
description,
customProperties = Data({}),
customProperties = harden({}),
) => {
assert.typeof(
description,
Expand Down
6 changes: 3 additions & 3 deletions packages/zoe/src/contractFacet/seat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { E } from '@agoric/eventual-send';
import { assert, details as X } from '@agoric/assert';
import { Data, Far } from '@agoric/marshal';
import { Far } from '@agoric/marshal';

import { isOfferSafe } from './offerSafety';

Expand Down Expand Up @@ -88,7 +88,7 @@ export const makeZcfSeatAdminKit = (
},
isOfferSafe: newAllocation => {
assertExitedFalse();
const reallocation = Data({
const reallocation = harden({
...currentAllocation,
...newAllocation,
});
Expand All @@ -98,7 +98,7 @@ export const makeZcfSeatAdminKit = (
stage: newAllocation => {
assertExitedFalse();
// Check offer safety.
const allocation = Data({
const allocation = harden({
...currentAllocation,
...newAllocation,
});
Expand Down
3 changes: 1 addition & 2 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { E } from '@agoric/eventual-send';
import { makePromiseKit } from '@agoric/promise-kit';

import { MathKind } from '@agoric/ertp';
import { Data } from '@agoric/marshal';
import { satisfiesWant } from '../contractFacet/offerSafety';
import { objectMap } from '../objArrayConversion';

Expand Down Expand Up @@ -409,7 +408,7 @@ export async function withdrawFromSeat(zcf, seat, amounts) {
* @param {IssuerKeywordRecord} issuerKeywordRecord Issuers to save to
* ZCF
*/
export async function saveAllIssuers(zcf, issuerKeywordRecord = Data({})) {
export async function saveAllIssuers(zcf, issuerKeywordRecord = harden({})) {
const { issuers } = zcf.getTerms();
const issuersPSaved = Object.entries(issuerKeywordRecord).map(
([keyword, issuer]) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/otcDesk.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { E } from '@agoric/eventual-send';
import { assert } from '@agoric/assert';
import { Data, Far } from '@agoric/marshal';
import { Far } from '@agoric/marshal';
import {
trade,
offerTo,
Expand Down Expand Up @@ -125,7 +125,7 @@ const start = zcf => {
* @param {IssuerKeywordRecord=} issuerKeywordRecord
* @returns {Promise<Payment>}
*/
makeAddInventoryInvitation: async (issuerKeywordRecord = Data({})) => {
makeAddInventoryInvitation: async (issuerKeywordRecord = harden({})) => {
await saveAllIssuers(zcf, issuerKeywordRecord);
return zcf.makeInvitation(addInventory, 'addInventory');
},
Expand Down
5 changes: 2 additions & 3 deletions packages/zoe/src/objArrayConversion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check

import { Data } from '@agoric/marshal';
import { assert, details as X, q } from '@agoric/assert';

/**
Expand All @@ -23,7 +22,7 @@ export const arrayToObj = (array, keys) => {
/** @type {Record<U, T>} */
({});
keys.forEach((key, i) => (obj[key] = array[i]));
return Data(obj);
return harden(obj);
};

/**
Expand Down Expand Up @@ -88,5 +87,5 @@ export const assertSubset = (whole, part) => {
export const objectMap = (original, mapPairFn) => {
const ents = /** @type {[K, T][]} */ (Object.entries(original));
const mapEnts = ents.map(ent => mapPairFn(ent));
return /** @type {Record<K, U>} */ (Data(Object.fromEntries(mapEnts)));
return /** @type {Record<K, U>} */ (harden(Object.fromEntries(mapEnts)));
};
12 changes: 6 additions & 6 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { makeIssuerKit, MathKind } from '@agoric/ertp';
import '../../exported';
import '../internal-types';

import { Data, Far } from '@agoric/marshal';
import { Far } from '@agoric/marshal';
import { makeIssuerTable } from '../issuerTable';
import { makeZoeSeatAdminKit } from './zoeSeat';
import zcfContractBundle from '../../bundles/bundle-contractFacet';
Expand Down Expand Up @@ -97,8 +97,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
},
startInstance: async (
installationP,
uncleanIssuerKeywordRecord = Data({}),
customTerms = Data({}),
uncleanIssuerKeywordRecord = harden({}),
customTerms = harden({}),
) => {
/** @param {Issuer[]} issuers */
const initIssuers = issuers =>
Expand Down Expand Up @@ -356,7 +356,7 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
zoeService,
invitationIssuer,
zoeInstanceAdminForZcf,
Data({ ...instanceRecord }),
harden({ ...instanceRecord }),
);

addSeatObjPromiseKit.resolve(addSeatObj);
Expand Down Expand Up @@ -395,8 +395,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
},
offer: async (
invitation,
uncleanProposal = Data({}),
paymentKeywordRecord = Data({}),
uncleanProposal = harden({}),
paymentKeywordRecord = harden({}),
) => {
return invitationKit.issuer.burn(invitation).then(
invitationAmount => {
Expand Down
Loading

0 comments on commit d8cee03

Please sign in to comment.