Skip to content

Commit

Permalink
refactor(ertp): review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed May 10, 2023
1 parent c5b54db commit 2c74cfc
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions packages/ERTP/src/paymentLedger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* eslint-disable no-use-before-define */
import { isPromise } from '@endo/promise-kit';
import { mustMatch, M, keyEQ } from '@agoric/store';
import { provide } from '@agoric/vat-data';
import { AmountMath } from './amountMath.js';
import { preparePaymentKind } from './payment.js';
import { preparePurseKind } from './purse.js';
Expand Down Expand Up @@ -70,7 +69,7 @@ const amountShapeFromElementShape = (brand, assetKind, elementShape) => {
* payments. All minting and transfer authority originates here.
*
* @template {AssetKind} K
* @param {import('@agoric/zone').Zone} issuerZone
* @param {Zone} issuerZone
* @param {string} name
* @param {K} assetKind
* @param {DisplayInfo<K>} displayInfo
Expand Down Expand Up @@ -374,28 +373,21 @@ export const preparePaymentLedger = (
},
});

/**
* @template {any} V
* @param {Zone} zone
* @param {string} key
* @param {(k: string) => V} makeValue
* @returns {V}
*/
const provideFromZone = (zone, key, makeValue) => {
const map = zone.mapStore(`singleton_${key}_store`);
return provide(map, key, makeValue);
};
harden(provideFromZone);

/**
* Provides for the recovery of newly minted but not-yet-deposited payments.
*
* Because the `mintRecoveryPurse` is placed in baggage, even if the
* caller of `makeIssuerKit` drops it on the floor, it can still be
* recovered in an emergency upgrade.
*/
// Should be
// at-ts-expect-error checked cast
// but ran into the usual disagreement between local lint and IDE lint.
// Don't know yet about lint under CI.
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
const mintRecoveryPurse = /** @type {Purse<K>} */ (
provideFromZone(issuerZone, 'mintRecoveryPurse', () => makeEmptyPurse())
issuerZone.once('mintRecoveryPurse', () => makeEmptyPurse())
);

/** @type {Mint<K>} */
Expand Down

0 comments on commit 2c74cfc

Please sign in to comment.