Skip to content

Commit

Permalink
Merge pull request #8339 from Agoric/markm-use-guard-getters
Browse files Browse the repository at this point in the history
refactor: use guard getters
  • Loading branch information
mergify[bot] authored Sep 16, 2023
2 parents 97cb715 + 99d901e commit b5a2ed1
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 20 deletions.
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
5 changes: 2 additions & 3 deletions 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 { getInterfaceMethodKeys } from '@endo/patterns';

const { Fail, quote: q } = assert;

Expand Down Expand Up @@ -314,9 +315,7 @@ harden(prepareAttenuator);
* @param {string} [opts.tag]
*/
export const prepareGuardedAttenuator = (zone, interfaceGuard, opts = {}) => {
// TODO: Handle symbolMethodGuards too?
const { methodGuards } = interfaceGuard;
const methodNames = ownKeys(methodGuards);
const methodNames = getInterfaceMethodKeys(interfaceGuard);
const makeAttenuator = prepareAttenuator(zone, methodNames, {
...opts,
interfaceGuard,
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(),
makeInvitation: M.call(InvitationHandleShape, M.string())
.optional(M.record(), M.pattern())
.returns(PaymentShape),
Expand Down

0 comments on commit b5a2ed1

Please sign in to comment.