Skip to content

Commit

Permalink
chore: payments are virtual objects.
Browse files Browse the repository at this point in the history
Unit tests do not have makeKind or makeWeakStore and Swingset tests fail with little information.
  • Loading branch information
katelynsills committed Feb 27, 2021
1 parent ab7bd28 commit 0133a3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/ERTP/src/issuer.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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<Payment, Amount>} */
const paymentLedger = makePaymentWeakStore();
const paymentLedger = makeWeakStore('payment');

function assertKnownPayment(payment) {
assert(paymentLedger.has(payment), X`payment not found for ${allegedName}`);
Expand Down
24 changes: 24 additions & 0 deletions packages/ERTP/src/payment.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 0133a3a

Please sign in to comment.