From 6bc46a062c6c10b94f8a90795815692ac7aff921 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Thu, 23 Jun 2022 16:20:01 -0700 Subject: [PATCH] broken: use seatHandle rather than zoeSeatAdmin --- packages/zoe/src/contractFacet/zcfSeat.js | 21 ++++++++++---------- packages/zoe/src/contractFacet/zcfZygote.js | 12 ++++------- packages/zoe/src/internal-types.js | 6 +++--- packages/zoe/src/zoeService/startInstance.js | 10 ++++++++-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/zoe/src/contractFacet/zcfSeat.js b/packages/zoe/src/contractFacet/zcfSeat.js index 10acaaae0c48..6dbd033bc124 100644 --- a/packages/zoe/src/contractFacet/zcfSeat.js +++ b/packages/zoe/src/contractFacet/zcfSeat.js @@ -243,22 +243,21 @@ export const createSeatManager = ( const zcfSeatKindHandle = provideKindHandle(zcfBaggage, 'zcfSeat'); const makeZCFSeatInternal = defineDurableKind( zcfSeatKindHandle, - (proposal, zoeSeatAdmin, notifier) => ({ + (proposal, notifier) => ({ proposal, - zoeSeatAdmin, notifier, }), { getNotifier: ({ state }) => state.notifier, getProposal: ({ state }) => state.proposal, - exit: ({ state, self }, completion) => { + exit: ({ self }, completion) => { assertActive(self); assertNoStagedAllocation(self); doExitSeat(self); - E(state.zoeSeatAdmin).exit(completion); + E(zoeInstanceAdmin).exitSeat(zcfSeatToSeatHandle.get(self), completion); }, fail: ( - { state, self }, + { self }, reason = new Error( 'Seat exited with failure. Please check the log for more information.', ), @@ -272,7 +271,10 @@ export const createSeatManager = ( } if (!hasExited(self)) { doExitSeat(self); - E(state.zoeSeatAdmin).fail(harden(reason)); + E(zoeInstanceAdmin).failSeat( + zcfSeatToSeatHandle.get(self), + harden(reason), + ); } return reason; }, @@ -334,11 +336,8 @@ export const createSeatManager = ( hasStagedAllocation: ({ self }) => hasStagedAllocation(self), }, ); - const makeZCFSeat = ( - zoeSeatAdmin, - { proposal, notifier, initialAllocation, seatHandle }, - ) => { - const zcfSeat = makeZCFSeatInternal(proposal, zoeSeatAdmin, notifier); + const makeZCFSeat = (proposal, notifier, initialAllocation, seatHandle) => { + const zcfSeat = makeZCFSeatInternal(proposal, notifier); activeZCFSeats.init(zcfSeat, initialAllocation); zcfSeatToSeatHandle.init(zcfSeat, seatHandle); return zcfSeat; diff --git a/packages/zoe/src/contractFacet/zcfZygote.js b/packages/zoe/src/contractFacet/zcfZygote.js index 14bb832d00b0..b01e825660a9 100644 --- a/packages/zoe/src/contractFacet/zcfZygote.js +++ b/packages/zoe/src/contractFacet/zcfZygote.js @@ -95,9 +95,6 @@ export const makeZCFZygote = ( const initialAllocation = harden({}); const proposal = cleanProposal(harden({ exit }), getAssetKindByBrand); const { notifier, updater } = makeNotifierKit(); - /** @type {PromiseRecord} */ - const zoeSeatAdminPromiseKit = makePromiseKit(); - handlePKitWarning(zoeSeatAdminPromiseKit); const userSeatPromiseKit = makePromiseKit(); handlePKitWarning(userSeatPromiseKit); const seatHandle = makeSeatHandle(); @@ -108,15 +105,14 @@ export const makeZCFZygote = ( notifier, seatHandle, }); - const zcfSeat = makeZCFSeat(zoeSeatAdminPromiseKit.promise, seatData); + const zcfSeat = makeZCFSeat(seatData); const exitObj = makeExitObj(seatData.proposal, zcfSeat); E(zoeInstanceAdmin) .makeNoEscrowSeat(initialAllocation, proposal, exitObj, seatHandle) - .then(({ zoeSeatAdmin, notifier: zoeNotifier, userSeat }) => { + .then(({ notifier: zoeNotifier, userSeat }) => { observeNotifier(zoeNotifier, updater); - zoeSeatAdminPromiseKit.resolve(zoeSeatAdmin); userSeatPromiseKit.resolve(userSeat); }); @@ -333,8 +329,8 @@ export const makeZCFZygote = ( // added in offer(). ZCF responds with the exitObj and offerResult. /** @type {HandleOfferObj} */ const handleOfferObj = Far('handleOfferObj', { - handleOffer: (invitationHandle, zoeSeatAdmin, seatData) => { - const zcfSeat = makeZCFSeat(zoeSeatAdmin, seatData); + handleOffer: (invitationHandle, seatData) => { + const zcfSeat = makeZCFSeat(seatData); const offerHandler = takeOfferHandler(invitationHandle); const offerResultP = E(offerHandler)(zcfSeat, seatData.offerArgs).catch( reason => { diff --git a/packages/zoe/src/internal-types.js b/packages/zoe/src/internal-types.js index 7864a04c5a95..0724c781b006 100644 --- a/packages/zoe/src/internal-types.js +++ b/packages/zoe/src/internal-types.js @@ -89,7 +89,6 @@ * * @typedef {object} HandleOfferObj * @property {(invitationHandle: InvitationHandle, - * zoeSeatAdmin: ZoeSeatAdmin, * seatData: SeatData, * ) => HandleOfferResult} handleOffer */ @@ -115,6 +114,8 @@ * @property {ReplaceAllocations} replaceAllocations * @property {(completion: Completion) => void} exitAllSeats * @property {ShutdownWithFailure} failAllSeats + * @property {(seatHandle: SeatHandle, completion: Completion) => void} exitSeat + * @property {(seatHandle: SeatHandle, reason: Error) => void} failSeat * @property {() => void} stopAcceptingOffers */ @@ -148,7 +149,7 @@ * @param {ProposalRecord} proposal * @param {ExitObj} exitObj * @param {SeatHandle} seatHandle - * @returns {ZoeSeatAdminKit} + * @returns {{userSeat: UserSeat, notifier: Notifier}} */ /** @@ -248,7 +249,6 @@ /** * @callback MakeZCFSeat - * @param {ERef} zoeSeatAdmin * @param {SeatData} seatData * @returns {ZCFSeat} */ diff --git a/packages/zoe/src/zoeService/startInstance.js b/packages/zoe/src/zoeService/startInstance.js index c42b21e2a569..df73387134b4 100644 --- a/packages/zoe/src/zoeService/startInstance.js +++ b/packages/zoe/src/zoeService/startInstance.js @@ -142,7 +142,7 @@ export const makeStartInstance = ( zoeSeatAdmins.add(zoeSeatAdmin); E(handleOfferObjPromiseKit.promise) - .handleOffer(invitationHandle, zoeSeatAdmin, seatData) + .handleOffer(invitationHandle, seatData) .then(({ offerResultP, exitObj }) => { offerResultPromiseKit.resolve(offerResultP); exitObjPromiseKit.resolve(exitObj); @@ -167,7 +167,7 @@ export const makeStartInstance = ( ); zoeSeatAdmins.add(zoeSeatAdmin); seatHandleToZoeSeatAdmin.init(seatHandle, zoeSeatAdmin); - return { userSeat, notifier, zoeSeatAdmin }; + return { userSeat, notifier }; }, }); return instanceAdmin; @@ -192,6 +192,12 @@ export const makeStartInstance = ( makeNoEscrowSeat: instanceAdmin.makeNoEscrowSeat, exitAllSeats: completion => instanceAdmin.exitAllSeats(completion), failAllSeats: reason => instanceAdmin.failAllSeats(reason), + exitSeat: (seatHandle, completion) => { + seatHandleToZoeSeatAdmin.get(seatHandle).exit(completion); + }, + failSeat: (seatHandle, reason) => { + seatHandleToZoeSeatAdmin.get(seatHandle).fail(reason); + }, makeZoeMint: zoeInstanceStorageManager.makeZoeMint, registerFeeMint: zoeInstanceStorageManager.registerFeeMint, replaceAllocations: seatHandleAllocations => {