Skip to content

Commit

Permalink
fix(zcf): mint kind during reincarnation
Browse files Browse the repository at this point in the history
Co-Authored-By: Brian Warner <[email protected]>
  • Loading branch information
turadg and warner committed Apr 25, 2023
1 parent 5052aab commit d639f0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
42 changes: 19 additions & 23 deletions packages/zoe/src/contractFacet/zcfMint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import './types.js';

const { Fail } = assert;

export const makeZCFMintFactory = async (
zcfBaggage,
recordIssuer,
getAssetKindByBrand,
makeEmptySeatKit,
reallocator,
export const makeZCFMintFactory = (
/** @type {import('@agoric/vat-data').Baggage} */ zcfBaggage,
/** @type {{ (keyword: string, issuerRecord: IssuerRecord): void }} */ recordIssuer,
/** @type {GetAssetKindByBrand} */ getAssetKindByBrand,
/** @type { (exit?: undefined) => { zcfSeat: any; userSeat: Promise<UserSeat> }} */ makeEmptySeatKit,
/** @type {ZcfMintReallocator} */ reallocator,
) => {
/** @type {SetStore<ZCFMint>} The set of baggages for zcfMints */
/** @type {SetStore<import('@agoric/vat-data').Baggage>} The set of baggages for zcfMints */
const zcfMintBaggageSet = provideDurableSetStore(zcfBaggage, 'baggageSet');

/**
Expand All @@ -34,15 +34,14 @@ export const makeZCFMintFactory = async (
*
* @param {import('@agoric/vat-data').Baggage} zcfMintBaggage
*/
const provideDurableZcfMint = async zcfMintBaggage => {
const provideDurableZcfMint = zcfMintBaggage => {
const keyword = zcfMintBaggage.get('keyword');
const zoeMint = zcfMintBaggage.get('zoeMint');
const {
brand: mintyBrand,
issuer: mintyIssuer,
displayInfo: mintyDisplayInfo,
} = await E(zoeMint).getIssuerRecord();
// AWAIT
} = zcfMintBaggage.get('issuerRecord');
const mintyIssuerRecord = makeIssuerRecord(
mintyBrand,
mintyIssuer,
Expand Down Expand Up @@ -126,12 +125,6 @@ export const makeZCFMintFactory = async (
);
};

const makeDurableZcfMint = async (keyword, zoeMint, zcfMintBaggage) => {
zcfMintBaggage.init('keyword', keyword);
zcfMintBaggage.init('zoeMint', zoeMint);
return provideDurableZcfMint(zcfMintBaggage);
};

const ZCFMintFactoryI = M.interface('ZCFMintFactory', {
makeZCFMintInternal: M.call(M.string(), M.remotable('ZoeMint')).returns(
M.promise(),
Expand All @@ -150,21 +143,24 @@ export const makeZCFMintFactory = async (
ZCFMintFactoryI,
{
async makeZCFMintInternal(keyword, zoeMint) {
const issuerRecord = await E(zoeMint).getIssuerRecord();

const zcfMintBaggage = makeScalarBigMapStore('zcfMintBaggage', {
durable: true,
});
const zcfMint = await makeDurableZcfMint(
keyword,
zoeMint,
zcfMintBaggage,
);
zcfMintBaggageSet.add(zcfMint);
return zcfMint;

zcfMintBaggage.init('issuerRecord', issuerRecord);
zcfMintBaggage.init('keyword', keyword);
zcfMintBaggage.init('zoeMint', zoeMint);
zcfMintBaggageSet.add(zcfMintBaggage);

return provideDurableZcfMint(zcfMintBaggage);
},
},
);

for (const zcfMintBaggage of zcfMintBaggageSet.values()) {
// call for side-effect of redefining the kinds
provideDurableZcfMint(zcfMintBaggage);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/zoe/src/contractFacet/zcfZygote.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ export const makeZCFZygote = async (
// Make the instanceRecord
const makeInstanceRecord = makeInstanceRecordStorage(zcfBaggage);

const recordIssuer = (keyword, issuerRecord) => {
const recordIssuer = (
/** @type {string} */ keyword,
/** @type {IssuerRecord} */ issuerRecord,
) => {
getInstanceRecHolder().addIssuer(keyword, issuerRecord);
storeIssuerRecord(issuerRecord);
};
Expand Down Expand Up @@ -332,7 +335,7 @@ export const makeZCFZygote = async (
zcfBaggage,
));

zcfMintFactory = await makeZCFMintFactory(
zcfMintFactory = makeZCFMintFactory(
zcfBaggage,
recordIssuer,
getAssetKindByBrand,
Expand Down

0 comments on commit d639f0d

Please sign in to comment.