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

refactor: use guard getters #8339

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 packages/ERTP/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@endo/far": "^0.2.21",
"@endo/marshal": "^0.8.8",
"@endo/nat": "^4.1.30",
"@endo/patterns": "^0.2.5",
"@endo/promise-kit": "^0.2.59"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/ERTP/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @jessie-check

import { M, matches } from '@agoric/store';
import { M, matches, getInterfaceGuardPayload } from '@endo/patterns';

export const BrandShape = M.remotable('Brand');
export const IssuerShape = M.remotable('Issuer');
Expand Down Expand Up @@ -212,7 +212,7 @@ export const makeIssuerInterfaces = (
});

const DepositFacetI = M.interface('DepositFacet', {
receive: PurseI.methodGuards.deposit,
receive: getInterfaceGuardPayload(PurseI).methodGuards.deposit,
});

const PurseIKit = harden({
Expand Down
8 changes: 5 additions & 3 deletions packages/base-zone/tools/greeter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { M } from '@endo/patterns';
import { M, getInterfaceGuardPayload } from '@endo/patterns';

/**
* @template {{}} T
Expand Down Expand Up @@ -33,8 +33,8 @@ export const adminFacet = {
};

export const GreeterWithAdminI = M.interface('GreeterWithAdmin', {
...GreeterI.methodGuards,
...GreeterAdminI.methodGuards,
...getInterfaceGuardPayload(GreeterI).methodGuards,
...getInterfaceGuardPayload(GreeterAdminI).methodGuards,
});

/**
Expand All @@ -44,6 +44,7 @@ export const GreeterWithAdminI = M.interface('GreeterWithAdmin', {
*/
export const prepareGreeterSingleton = (zone, label, nick) => {
const myThis = Object.freeze({ state: { nick } });
// @ts-expect-error Until https://github.com/endojs/endo/pull/1771
return zone.exo(label, GreeterWithAdminI, {
...bindAllMethodsTo(greetFacet, myThis),
...bindAllMethodsTo(adminFacet, myThis),
Expand All @@ -54,6 +55,7 @@ export const prepareGreeterSingleton = (zone, label, nick) => {
* @param {import('../src/types.js').Zone} zone
*/
export const prepareGreeter = zone =>
// @ts-expect-error Until https://github.com/endojs/endo/pull/1771
zone.exoClass('Greeter', GreeterWithAdminI, nick => ({ nick }), {
...greetFacet,
...adminFacet,
Expand Down
3 changes: 2 additions & 1 deletion packages/internal/src/callback.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { E } from '@endo/far';
import { isObject, isPassableSymbol } from '@endo/marshal';
import { getInterfaceGuardPayload } from '@endo/patterns';

const { Fail, quote: q } = assert;

Expand Down Expand Up @@ -315,7 +316,7 @@ harden(prepareAttenuator);
*/
export const prepareGuardedAttenuator = (zone, interfaceGuard, opts = {}) => {
// TODO: Handle symbolMethodGuards too?
const { methodGuards } = interfaceGuard;
const { methodGuards } = getInterfaceGuardPayload(interfaceGuard);
const methodNames = ownKeys(methodGuards);
erights marked this conversation as resolved.
Show resolved Hide resolved
const makeAttenuator = prepareAttenuator(zone, methodNames, {
...opts,
Expand Down
8 changes: 5 additions & 3 deletions packages/notifier/src/publish-kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { canBeDurable, prepareExoClassKit } from '@agoric/vat-data';
import { E, Far } from '@endo/far';
import { M } from '@endo/patterns';
import { M, getInterfaceGuardPayload } from '@endo/patterns';
import { makePromiseKit } from '@endo/promise-kit';

import './types-ambient.js';
Expand Down Expand Up @@ -46,14 +46,16 @@ export const ForkableAsyncIterableIteratorShape = M.interface(
);

export const IterableEachTopicI = M.interface('IterableEachTopic', {
subscribeAfter: SubscriberI.methodGuards.subscribeAfter,
subscribeAfter:
getInterfaceGuardPayload(SubscriberI).methodGuards.subscribeAfter,
[Symbol.asyncIterator]: M.call().returns(
M.remotable('ForkableAsyncIterableIterator'),
),
});

export const IterableLatestTopicI = M.interface('IterableLatestTopic', {
getUpdateSince: SubscriberI.methodGuards.getUpdateSince,
getUpdateSince:
getInterfaceGuardPayload(SubscriberI).methodGuards.getUpdateSince,
[Symbol.asyncIterator]: M.call().returns(
M.remotable('ForkableAsyncIterableIterator'),
),
Expand Down
1 change: 1 addition & 0 deletions packages/vats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@endo/import-bundle": "^0.4.1",
"@endo/marshal": "^0.8.8",
"@endo/nat": "^4.1.30",
"@endo/patterns": "^0.2.5",
"@endo/promise-kit": "^0.2.59",
"import-meta-resolve": "^2.2.1",
"jessie.js": "^0.3.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/vats/src/nameHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { assert, NonNullish } from '@agoric/assert';
import { E } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
import { M } from '@agoric/store';
import { M, getInterfaceGuardPayload } from '@endo/patterns';

import './types.js';
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const NameHubIKit = harden({
/** @param {import('@agoric/zone').Zone} zone */
export const prepareMixinMyAddress = zone => {
const MixinI = M.interface('MyAddressNameAdmin', {
...NameHubIKit.nameAdmin.methodGuards,
...getInterfaceGuardPayload(NameHubIKit.nameAdmin).methodGuards,
getMyAddress: M.call().returns(M.string()),
});
/**
Expand Down
9 changes: 6 additions & 3 deletions packages/vats/src/vat-bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
prepareDurablePublishKit,
subscribeEach,
} from '@agoric/notifier';
import { M, provideLazy } from '@agoric/store';
import { M, getInterfaceGuardPayload } from '@endo/patterns';
import { provideLazy } from '@agoric/store';
import { makeDurableZone } from '@agoric/zone/durable.js';
import { E, Far } from '@endo/far';
import { makeAtomicProvider } from '@agoric/store/src/stores/store-utils.js';
Expand All @@ -26,8 +27,10 @@ const { Fail } = assert;
const { VirtualPurseControllerI } = makeVirtualPurseKitIKit();

const BridgeChannelI = M.interface('BridgeChannel', {
fromBridge: BridgeScopedManagerI.methodGuards.fromBridge,
toBridge: BridgeScopedManagerI.methodGuards.toBridge,
fromBridge:
getInterfaceGuardPayload(BridgeScopedManagerI).methodGuards.fromBridge,
toBridge:
getInterfaceGuardPayload(BridgeScopedManagerI).methodGuards.toBridge,
});

/**
Expand Down
7 changes: 4 additions & 3 deletions packages/vats/src/virtual-purse.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

import '@agoric/ertp/exported.js';
import '@agoric/notifier/exported.js';
import { getInterfaceGuardPayload } from '@endo/patterns';

const { Fail } = assert;

Expand Down Expand Up @@ -48,7 +49,7 @@ export const makeVirtualPurseKitIKit = (
});

const DepositFacetI = M.interface('DepositFacet', {
receive: VirtualPurseI.methodGuards.deposit,
receive: getInterfaceGuardPayload(VirtualPurseI).methodGuards.deposit,
});

const RetainRedeemI = M.interface('RetainRedeem', {
Expand All @@ -57,8 +58,8 @@ export const makeVirtualPurseKitIKit = (
});

const UtilsI = M.interface('Utils', {
retain: RetainRedeemI.methodGuards.retain,
redeem: RetainRedeemI.methodGuards.redeem,
retain: getInterfaceGuardPayload(RetainRedeemI).methodGuards.retain,
redeem: getInterfaceGuardPayload(RetainRedeemI).methodGuards.redeem,
recoverableClaim: M.callWhen(M.await(PaymentShape))
.optional(amountShape)
.returns(PaymentShape),
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const InstanceStorageManagerIKit = harden({
InstanceHandleShape,
M.remotable('instanceAdmin'),
).returns(M.promise()),
deleteInstanceAdmin: M.call(InstanceAdminI).returns(),
deleteInstanceAdmin: M.call(InstanceAdminShape).returns(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This bug was only caught by seeing #8340 fail , because it uses the stricter endojs/endo#1712

Copy link
Member Author

Choose a reason for hiding this comment

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

See #8341

makeInvitation: M.call(InvitationHandleShape, M.string())
.optional(M.record(), M.pattern())
.returns(PaymentShape),
Expand Down
Loading