Skip to content

Commit c3982b7

Browse files
committed
chore: payments are virtual objects.
Unit tests do not have makeKind or makeWeakStore and Swingset tests fail with little information.
1 parent 2c3c43a commit c3982b7

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

packages/ERTP/src/issuer.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Copyright (C) 2019 Agoric, under Apache License 2.0
2-
31
// @ts-check
42

3+
/* global makeWeakStore */
4+
55
import { assert, details as X } from '@agoric/assert';
66
import { makeExternalStore } from '@agoric/store';
77
import { E } from '@agoric/eventual-send';
@@ -12,6 +12,7 @@ import { isPromise } from '@agoric/promise-kit';
1212
import { makeAmountMath, MathKind } from './amountMath';
1313
import { makeFarName, ERTPKind } from './interfaces';
1414
import { coerceDisplayInfo } from './displayInfo';
15+
import { makePaymentMaker } from './payment';
1516

1617
import './types';
1718

@@ -43,17 +44,10 @@ function makeIssuerKit(
4344
const { add } = amountMath;
4445
const empty = amountMath.getEmpty();
4546

46-
const {
47-
makeInstance: makePayment,
48-
makeWeakStore: makePaymentWeakStore,
49-
} = makeExternalStore('payment', () =>
50-
Far(makeFarName(allegedName, ERTPKind.PAYMENT), {
51-
getAllegedBrand: () => brand,
52-
}),
53-
);
47+
const makePayment = makePaymentMaker(allegedName, brand);
5448

5549
/** @type {WeakStore<Payment, Amount>} */
56-
const paymentLedger = makePaymentWeakStore();
50+
const paymentLedger = makeWeakStore('payment');
5751

5852
function assertKnownPayment(payment) {
5953
assert(paymentLedger.has(payment), X`payment not found for ${allegedName}`);

packages/ERTP/src/payment.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* global makeKind */
2+
3+
// @ts-check
4+
5+
import { Far } from '@agoric/marshal';
6+
import { makeFarName, ERTPKind } from './interfaces';
7+
8+
export const makePaymentMaker = (allegedName, brand) => {
9+
const paymentVOMaker = state => {
10+
return {
11+
init: b => (state.brand = b),
12+
self: Far(makeFarName(allegedName, ERTPKind.PAYMENT), {
13+
getAllegedBrand: () => state.brand,
14+
}),
15+
};
16+
};
17+
18+
const paymentMaker = makeKind(paymentVOMaker);
19+
20+
const makePayment = () => paymentMaker(brand);
21+
22+
return makePayment;
23+
}
24+

0 commit comments

Comments
 (0)