diff --git a/packages/ERTP/src/issuer.js b/packages/ERTP/src/issuer.js index ac4d7d6d820..96ce415e7af 100644 --- a/packages/ERTP/src/issuer.js +++ b/packages/ERTP/src/issuer.js @@ -3,7 +3,7 @@ // @ts-check import { assert, details } from '@agoric/assert'; -import makeStore from '@agoric/weak-store'; +import { makeExternalStore } from '@agoric/store'; import { E } from '@agoric/eventual-send'; import { Remotable } from '@agoric/marshal'; import { isPromise } from '@agoric/promise-kit'; @@ -37,8 +37,20 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) { const amountMath = makeAmountMath(brand, amountMathKind); - const paymentLedger = makeStore('payment'); - const purseLedger = makeStore('purse'); + const { + makeInstance: makePayment, + makeWeakStore: makePaymentWeakStore, + } = makeExternalStore('payment', () => + Remotable(makeInterface(allegedName, ERTPKind.PAYMENT), undefined, { + getAllegedBrand: () => brand, + }), + ); + + /** @type {WeakStore} */ + const paymentLedger = makePaymentWeakStore(); + + /** @type {WeakStore} */ + let purseLedger; function assertKnownPayment(payment) { assert( @@ -47,11 +59,6 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) { ); } - const makePayment = () => - Remotable(makeInterface(allegedName, ERTPKind.PAYMENT), undefined, { - getAllegedBrand: () => brand, - }); - // Methods like deposit() have an optional second parameter `amount` // which, if present, is supposed to be equal to the balance of the // payment. This helper function does that check. @@ -67,7 +74,10 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) { /** * @returns {Purse} */ - const makePurse = () => { + const { + makeInstance: makePurse, + makeWeakStore: makePurseWeakStore, + } = makeExternalStore('purse', () => { /** @type {Purse} */ const purse = Remotable( makeInterface(allegedName, ERTPKind.PURSE), @@ -129,7 +139,9 @@ function makeIssuerKit(allegedName, amountMathKind = MathKind.NAT) { ); return purse; - }; + }); + + purseLedger = makePurseWeakStore(); const { add } = amountMath; const empty = amountMath.getEmpty();