diff --git a/packages/ERTP/src/issuer.js b/packages/ERTP/src/issuer.js index 490d70597230..e4c691e28256 100644 --- a/packages/ERTP/src/issuer.js +++ b/packages/ERTP/src/issuer.js @@ -1,7 +1,7 @@ -// Copyright (C) 2019 Agoric, under Apache License 2.0 - // @ts-check +/* global makeWeakStore */ + import { assert, details as X } from '@agoric/assert'; import { makeExternalStore } from '@agoric/store'; import { E } from '@agoric/eventual-send'; @@ -12,6 +12,7 @@ import { isPromise } from '@agoric/promise-kit'; import { makeAmountMath, MathKind } from './amountMath'; import { makeFarName, ERTPKind } from './interfaces'; import { coerceDisplayInfo } from './displayInfo'; +import { makePaymentMaker } from './payment'; import './types'; @@ -43,17 +44,10 @@ function makeIssuerKit( const { add } = amountMath; const empty = amountMath.getEmpty(); - const { - makeInstance: makePayment, - makeWeakStore: makePaymentWeakStore, - } = makeExternalStore('payment', () => - Far(makeFarName(allegedName, ERTPKind.PAYMENT), { - getAllegedBrand: () => brand, - }), - ); + const makePayment = makePaymentMaker(allegedName, brand); /** @type {WeakStore} */ - const paymentLedger = makePaymentWeakStore(); + const paymentLedger = makeWeakStore('payment'); function assertKnownPayment(payment) { assert(paymentLedger.has(payment), X`payment not found for ${allegedName}`); diff --git a/packages/ERTP/src/payment.js b/packages/ERTP/src/payment.js new file mode 100644 index 000000000000..943819a24c59 --- /dev/null +++ b/packages/ERTP/src/payment.js @@ -0,0 +1,24 @@ +/* global makeKind */ + +// @ts-check + +import { Far } from '@agoric/marshal'; +import { makeFarName, ERTPKind } from './interfaces'; + +export const makePaymentMaker = (allegedName, brand) => { + const paymentVOMaker = state => { + return { + init: b => (state.brand = b), + self: Far(makeFarName(allegedName, ERTPKind.PAYMENT), { + getAllegedBrand: () => state.brand, + }), + }; + }; + + const paymentMaker = makeKind(paymentVOMaker); + + const makePayment = () => paymentMaker(brand); + + return makePayment; +} +