From 6fd8a582c2291be3512bb059319874d592c157d6 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Wed, 27 Dec 2023 16:20:11 -0800 Subject: [PATCH] chore: deduplicate Interface guards for zoeSeat and originalZoeSeat --- .../zoe/src/zoeService/originalZoeSeat.js | 30 +++++++----- packages/zoe/src/zoeService/zoeSeat.js | 49 +++++-------------- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/packages/zoe/src/zoeService/originalZoeSeat.js b/packages/zoe/src/zoeService/originalZoeSeat.js index 968dcf3412f..0187d07dcd3 100644 --- a/packages/zoe/src/zoeService/originalZoeSeat.js +++ b/packages/zoe/src/zoeService/originalZoeSeat.js @@ -17,7 +17,23 @@ import { const { Fail } = assert; -const OriginalZoeSeatIKit = harden({ +export const coreUserSeatMethods = harden({ + getProposal: M.call().returns(M.promise()), + getPayouts: M.call().returns(M.promise()), + getPayout: M.call(KeywordShape).returns(M.promise()), + getOfferResult: M.call().returns(M.promise()), + hasExited: M.call().returns(M.promise()), + numWantsSatisfied: M.call().returns(M.promise()), + getFinalAllocation: M.call().returns(M.promise()), + getExitSubscriber: M.call().returns(M.any()), +}); + +export const ZoeUserSeatShape = M.interface('UserSeat', { + ...coreUserSeatMethods, + tryExit: M.call().returns(M.promise()), +}); + +export const OriginalZoeSeatIKit = harden({ zoeSeatAdmin: M.interface('ZoeSeatAdmin', { replaceAllocation: M.call(AmountKeywordRecordShape).returns(), exit: M.call(M.any()).returns(), @@ -33,17 +49,7 @@ const OriginalZoeSeatIKit = harden({ M.promise(), ), }), - userSeat: M.interface('UserSeat', { - getProposal: M.call().returns(M.promise()), - getPayouts: M.call().returns(M.promise()), - getPayout: M.call(KeywordShape).returns(M.promise()), - getOfferResult: M.call().returns(M.promise()), - hasExited: M.call().returns(M.promise()), - tryExit: M.call().returns(M.promise()), - numWantsSatisfied: M.call().returns(M.promise()), - getFinalAllocation: M.call().returns(M.promise()), - getExitSubscriber: M.call().returns(M.any()), - }), + userSeat: ZoeUserSeatShape, }); const assertHasNotExited = (c, msg) => { diff --git a/packages/zoe/src/zoeService/zoeSeat.js b/packages/zoe/src/zoeService/zoeSeat.js index f76849f0b8c..363932fb89b 100644 --- a/packages/zoe/src/zoeService/zoeSeat.js +++ b/packages/zoe/src/zoeService/zoeSeat.js @@ -1,5 +1,5 @@ /* eslint @typescript-eslint/no-floating-promises: "warn" */ -import { prepareDurablePublishKit, SubscriberShape } from '@agoric/notifier'; +import { prepareDurablePublishKit } from '@agoric/notifier'; import { E } from '@endo/eventual-send'; import { M, prepareExoClassKit } from '@agoric/vat-data'; import { deeplyFulfilled } from '@endo/marshal'; @@ -9,27 +9,17 @@ import { satisfiesWant } from '../contractFacet/offerSafety.js'; import '../types.js'; import '../internal-types.js'; import { - AmountKeywordRecordShape, - ExitObjectShape, - KeywordShape, - PaymentPKeywordRecordShape, -} from '../typeGuards.js'; -import { declareOldZoeSeatAdminKind } from './originalZoeSeat.js'; + declareOldZoeSeatAdminKind, + OriginalZoeSeatIKit, + ZoeUserSeatShape, + coreUserSeatMethods, +} from './originalZoeSeat.js'; const { Fail } = assert; -// ZoeSeatAdmin has the implementation of these methods, but ZoeUserSeat is the -// facet shared with users. The latter transparently forwards to the former. -const coreUserSeatMethods = harden({ - getProposal: M.call().returns(M.promise()), - getPayouts: M.call().returns(M.promise()), - getPayout: M.call(KeywordShape).returns(M.promise()), - getOfferResult: M.call().returns(M.promise()), - hasExited: M.call().returns(M.promise()), - numWantsSatisfied: M.call().returns(M.promise()), - getFinalAllocation: M.call().returns(M.promise()), - getExitSubscriber: M.call().returns(M.any()), -}); +// ZoeSeatAdmin has the implementation of coreUserSeatMethods, but ZoeUserSeat +// is the facet shared with users. The latter transparently forwards to the +// former. const ZoeSeatAdmin = harden({ userSeatAccess: M.interface('UserSeatAccess', { @@ -37,28 +27,11 @@ const ZoeSeatAdmin = harden({ initExitObjectSetter: M.call(M.any()).returns(), assertHasNotExited: M.call(M.string()).returns(), }), - zoeSeatAdmin: M.interface('ZoeSeatAdmin', { - replaceAllocation: M.call(AmountKeywordRecordShape).returns(), - exit: M.call(M.any()).returns(), - fail: M.call(M.any()).returns(), - resolveExitAndResult: M.call({ - offerResultPromise: M.promise(), - exitObj: ExitObjectShape, - }).returns(), - getExitSubscriber: M.call().returns(SubscriberShape), - // The return promise is empty, but doExit relies on settlement as a signal - // that the payouts have settled. The exit publisher is notified after that. - finalPayouts: M.call(M.eref(PaymentPKeywordRecordShape)).returns( - M.promise(), - ), - }), + zoeSeatAdmin: OriginalZoeSeatIKit.zoeSeatAdmin, }); const ZoeUserSeat = harden({ - userSeat: M.interface('UserSeat', { - ...coreUserSeatMethods, - tryExit: M.call().returns(M.promise()), - }), + userSeat: ZoeUserSeatShape, exitObjSetter: M.interface('exitObjSetter', { setExitObject: M.call(M.or(M.remotable(), M.undefined())).returns(), }),