Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markm make exo not far #29

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@agoric/vats": "0.15.2-u14.0",
"@agoric/zoe": "^0.26.3-u14.0",
"@endo/bundle-source": "^2.8.0",
"@endo/exo": "^0.2.2",
"@endo/far": "^0.2.22",
"@endo/init": "^0.5.60",
"@endo/marshal": "^0.8.9",
Expand Down
40 changes: 25 additions & 15 deletions contract/src/fixHub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';

const { Fail } = assert;

Expand All @@ -11,20 +13,28 @@ const { Fail } = assert;
export const fixHub = async namesByAddressAdmin => {
assert(namesByAddressAdmin, 'no namesByAddressAdmin???');
/** @type {import('@agoric/vats').NameHub} */
const hub = Far('Hub work-around', {
lookup: async (addr, ...rest) => {
await E(namesByAddressAdmin).reserve(addr);
const addressAdmin = await E(namesByAddressAdmin).lookupAdmin(addr);
assert(addressAdmin, 'no admin???');
const addressHub = E(addressAdmin).readonly();
if (rest.length === 0) return addressHub;
await E(addressAdmin).reserve(rest[0]);
return E(addressHub).lookup(...rest);
const hub = makeExo(
'Hub work-around',
M.interface(
'Hub work-around',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{
lookup: async (addr, ...rest) => {
await E(namesByAddressAdmin).reserve(addr);
const addressAdmin = await E(namesByAddressAdmin).lookupAdmin(addr);
assert(addressAdmin, 'no admin???');
const addressHub = E(addressAdmin).readonly();
if (rest.length === 0) return addressHub;
await E(addressAdmin).reserve(rest[0]);
return E(addressHub).lookup(...rest);
},
has: _key => Fail`key space not well defined`,
entries: () => Fail`enumeration not supported`,
values: () => Fail`enumeration not supported`,
keys: () => Fail`enumeration not supported`,
},
has: _key => Fail`key space not well defined`,
entries: () => Fail`enumeration not supported`,
values: () => Fail`enumeration not supported`,
keys: () => Fail`enumeration not supported`,
});
);
return hub;
};
34 changes: 30 additions & 4 deletions contract/src/platform-goals/board-aux.core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';

const { Fail } = assert;

Expand Down Expand Up @@ -59,9 +61,33 @@ export const makeBoardAuxManager = (zone, marshalData, powers) => {
);

return harden({
brandAuxPublisher: Far('BrandAuxPublisher', { publishBrandInfo }),
boardAuxTOFU: Far('BoardAuxTOFU', { publishBrandInfo, init }),
boardAuxAdmin: Far('BoardAuxAdmin', { publishBrandInfo, init, update }),
brandAuxPublisher: makeExo(
'BrandAuxPublisher',
M.interface(
'BrandAuxPublisher',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{ publishBrandInfo },
),
boardAuxTOFU: makeExo(
'BoardAuxTOFU',
M.interface(
'BoardAuxTOFU',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{ publishBrandInfo, init },
),
boardAuxAdmin: makeExo(
'BoardAuxAdmin',
M.interface(
'BoardAuxAdmin',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{ publishBrandInfo, init, update },
),
});
};
/** @typedef {ReturnType<typeof makeBoardAuxManager>} BoardAuxManager */
Expand Down
19 changes: 12 additions & 7 deletions contract/src/postal-service.contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M, mustMatch } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js';

const { keys, values } = Object;
Expand Down Expand Up @@ -61,12 +62,16 @@ export const start = zcf => {
return zcf.makeInvitation(handleSend, 'send');
};

const publicFacet = Far('postalSvc', {
lookup: (...path) => E(namesByAddress).lookup(...path),
getDepositFacet,
sendTo,
makeSendInvitation,
});
const publicFacet = makeExo(
'postalSvc',
M.interface('postalSvc', {}, { defaultGuards: 'passable', sloppy: true }),
{
lookup: (...path) => E(namesByAddress).lookup(...path),
getDepositFacet,
sendTo,
makeSendInvitation,
},
);
return { publicFacet };
};
/** @typedef { typeof start } PostalServiceFn */
16 changes: 12 additions & 4 deletions contract/src/sell-concert-tickets.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
// @ts-check

import { Far } from '@endo/far';
import { M, getCopyBagEntries, makeCopyBag } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { AssetKind } from '@agoric/ertp/src/amountMath.js';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import '@agoric/zoe/exported.js';
Expand Down Expand Up @@ -209,9 +209,17 @@ export const start = async zcf => {
zcf.makeInvitation(tradeHandler, 'buy tickets', undefined, proposalShape);

// Mark the publicFacet Far, i.e. reachable from outside the contract
const publicFacet = Far('Tickets Public Facet', {
makeTradeInvitation,
});
const publicFacet = makeExo(
'Tickets Public Facet',
M.interface(
'Tickets Public Facet',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{
makeTradeInvitation,
},
);
return harden({ publicFacet });
};
harden(start);
27 changes: 18 additions & 9 deletions contract/src/swaparoo.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// @ts-check

import { M, matches, mustMatch } from '@endo/patterns';
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { makeExo } from '@endo/exo';
import '@agoric/zoe/exported.js';
import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
import '@agoric/zoe/src/contracts/exported.js';
Expand Down Expand Up @@ -198,15 +199,23 @@ export const start = async (zcf, privateArgs, baggage) => {
return firstInvitation;
};

const publicFacet = Far('Public', {
makeFirstInvitation,
...publicMixin,
});
const limitedCreatorFacet = Far('Creator', {
makeCollectFeesInvitation() {
return makeCollectFeesInvitation(zcf, feeSeat, feeBrand, 'Fee');
const publicFacet = makeExo(
'Public',
M.interface('Public', {}, { defaultGuards: 'passable', sloppy: true }),
{
makeFirstInvitation,
...publicMixin,
},
);
const limitedCreatorFacet = makeExo(
'Creator',
M.interface('Creator', {}, { defaultGuards: 'passable', sloppy: true }),
{
makeCollectFeesInvitation() {
return makeCollectFeesInvitation(zcf, feeSeat, feeBrand, 'Fee');
},
},
});
);
const { governorFacet } = makeDurableGovernorFacet(
baggage,
limitedCreatorFacet,
Expand Down
47 changes: 32 additions & 15 deletions contract/test/boot-tools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { makeNameHubKit, makePromiseSpace } from '@agoric/vats';
import { makeFakeBoard } from '@agoric/vats/tools/board-utils.js';
import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js';
Expand Down Expand Up @@ -95,7 +97,17 @@ export const mockBootstrapPowers = async (
spaces.issuer.produce.BLD.resolve(bldIssuerKit.issuer);
spaces.issuer.produce.IST.resolve(feeIssuer);
spaces.issuer.produce.Invitation.resolve(invitationIssuer);
produce.priceAuthority.resolve(Far('NullPriceAuthority', {}));
produce.priceAuthority.resolve(
makeExo(
Comment on lines -98 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest skipping everything under test/.

'NullPriceAuthority',
M.interface(
'NullPriceAuthority',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{},
),
);

/**
* @type {BootstrapPowers & import('../src/types').NonNullChainStorage}
Expand Down Expand Up @@ -212,20 +224,25 @@ export const makeMockTools = async (t, bundleCache) => {

// XXX marshal context is not fresh. hm.
const makeQueryTool = () => {
return Far('QT', {
toCapData: x => boardMarshaller.toCapData(x), // XXX remote???
fromCapData: d => boardMarshaller.fromCapData(d),
queryData: async path => {
const parts = path.split('.');
if (parts.shift() !== 'published') throw Error(`not found: ${path}`);
if (parts.shift() !== 'agoricNames') throw Error(`not found: ${path}`);
if (parts.length !== 1) throw Error(`not found: ${path}`);
const hub = E(agoricNames).lookup(parts[0]);
const kvs = await E(hub).entries();
boardMarshaller.toCapData(kvs); // remember object identities
return kvs;
return makeExo(
'QT',
M.interface('QT', {}, { defaultGuards: 'passable', sloppy: true }),
{
toCapData: x => boardMarshaller.toCapData(x), // XXX remote???
fromCapData: d => boardMarshaller.fromCapData(d),
queryData: async path => {
const parts = path.split('.');
if (parts.shift() !== 'published') throw Error(`not found: ${path}`);
if (parts.shift() !== 'agoricNames')
throw Error(`not found: ${path}`);
if (parts.length !== 1) throw Error(`not found: ${path}`);
const hub = E(agoricNames).lookup(parts[0]);
const kvs = await E(hub).entries();
boardMarshaller.toCapData(kvs); // remember object identities
return kvs;
},
},
});
);
};

return {
Expand Down
19 changes: 15 additions & 4 deletions contract/test/lib-gov-test/puppet-gov.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
// borrowed from https://github.com/Agoric/agoric-sdk/blob/master/packages/inter-protocol/test/supports.js
import { E, Far } from '@endo/far';
import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { makeExo } from '@endo/exo';
import { createRequire } from 'node:module';

const nodeRequire = createRequire(import.meta.url);
Expand Down Expand Up @@ -54,9 +56,18 @@ export const mockElectorate = async (zoe, bundleCache) => {
await bundleCache.load(assets.invitationMakerContract),
);
const arbInstance = await E(zoe).startInstance(installation);
const committeeCreatorFacet = Far('Electorate CF', {
getPoserInvitation: async () => E(arbInstance.publicFacet).makeInvitation(),
});
const committeeCreatorFacet = makeExo(
'Electorate CF',
M.interface(
'Electorate CF',
{},
{ defaultGuards: 'passable', sloppy: true },
),
{
getPoserInvitation: async () =>
E(arbInstance.publicFacet).makeInvitation(),
},
);
return { creatorFacet: committeeCreatorFacet };
};

Expand Down
4 changes: 3 additions & 1 deletion contract/test/test-bundle-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { E, passStyleOf } from '@endo/far';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';

const myRequire = createRequire(import.meta.url);
const contractPath = myRequire.resolve(`../src/sell-concert-tickets.contract.js`);
const contractPath = myRequire.resolve(
`../src/sell-concert-tickets.contract.js`,
);

test('bundleSource() bundles the contract for use with zoe', async t => {
const bundle = await bundleSource(contractPath);
Expand Down
Loading
Loading