diff --git a/core/config/noCustomization.js b/core/config/noCustomization.js index 8486318..b46cdea 100644 --- a/core/config/noCustomization.js +++ b/core/config/noCustomization.js @@ -6,27 +6,28 @@ import harden from '@agoric/harden'; // These methods must be paired with a mintKeeper and Assay to be a // full configuration that can be passed into `makeMint`. + +function* makePaymentTrait(_superPayment) { + yield harden({}); +} + +function* makePurseTrait(_superPurse) { + yield harden({}); +} + +function* makeMintTrait(_superMint) { + yield harden({}); +} + +function* makeIssuerTrait(_superIssuer) { + yield harden({}); +} + const noCustomization = harden({ - makeCustomPayment(superPayment) { - return harden({ - ...superPayment, - }); - }, - makeCustomPurse(superPurse) { - return harden({ - ...superPurse, - }); - }, - makeCustomMint(superMint) { - return harden({ - ...superMint, - }); - }, - makeCustomIssuer(superIssuer) { - return harden({ - ...superIssuer, - }); - }, + makePaymentTrait, + makePurseTrait, + makeMintTrait, + makeIssuerTrait, }); export { noCustomization }; diff --git a/core/config/seatConfig.js b/core/config/seatConfig.js index 288b78b..febee99 100644 --- a/core/config/seatConfig.js +++ b/core/config/seatConfig.js @@ -17,33 +17,35 @@ import { seatStrategy } from './strategies/seatStrategy'; */ function makeSeatConfigMaker(makeUseObjForPayment, makeUseObjForPurse) { function makeSeatConfig() { + function* makePaymentTrait(_superPayment, issuer) { + const payment = yield harden({ + // This creates a new use object which destroys the payment + unwrap: () => makeUseObjForPayment(issuer, payment), + }); + return payment; + } + + function* makePurseTrait(_superPurse, issuer) { + const purse = yield harden({ + // This creates a new use object which empties the purse + unwrap: () => makeUseObjForPurse(issuer, purse), + }); + return purse; + } + + function* makeMintTrait(_superMint) { + return yield harden({}); + } + + function* makeIssuerTrait(_superIssuer) { + return yield harden({}); + } + return harden({ - makeCustomPayment(superPayment, issuer) { - const payment = harden({ - ...superPayment, - // This creates a new use object which destroys the payment - unwrap: () => makeUseObjForPayment(issuer, payment), - }); - return payment; - }, - makeCustomPurse(superPurse, issuer) { - const purse = harden({ - ...superPurse, - // This creates a new use object which empties the purse - unwrap: () => makeUseObjForPurse(issuer, purse), - }); - return purse; - }, - makeCustomMint(superMint) { - return harden({ - ...superMint, - }); - }, - makeCustomIssuer(superIssuer) { - return harden({ - ...superIssuer, - }); - }, + makePaymentTrait, + makePurseTrait, + makeMintTrait, + makeIssuerTrait, makeMintKeeper: makeCoreMintKeeper, strategy: seatStrategy, }); diff --git a/core/issuers.js b/core/issuers.js index 76f5eee..0db9369 100644 --- a/core/issuers.js +++ b/core/issuers.js @@ -25,10 +25,10 @@ Description must be truthy: ${description}`; // Each of these methods is used below and must be defined (even in // a trivial way) in any configuration const { - makeCustomIssuer, - makeCustomPayment, - makeCustomPurse, - makeCustomMint, + makeIssuerTrait, + makePaymentTrait, + makePurseTrait, + makeMintTrait, makeMintKeeper, strategy, } = makeConfig(); @@ -65,10 +65,15 @@ Description must be truthy: ${description}`; }, }); - // makeCustomPayment is defined in the passed-in configuration and - // can add additional methods to (or even override, though this is - // firmly discouraged) the corePayment methods - const payment = makeCustomPayment(corePayment, issuer); + // makePaymentTrait is defined in the passed-in configuration and adds + // additional methods to corePayment + const makePaymentTraitIter = makePaymentTrait(corePayment, issuer); + const paymentTrait = makePaymentTraitIter.next().value; + const payment = harden({ + ...paymentTrait, + ...corePayment, + }); + makePaymentTraitIter.next(payment); // ///////////////// commit point ////////////////// // All queries above passed with no side effects. @@ -96,10 +101,15 @@ Description must be truthy: ${description}`; return name; }, }); - // makeCustomPayment is defined in the passed-in configuration and - // can add additional methods to (or even override, though this is - // firmly discouraged) the corePayment methods - const payment = makeCustomPayment(corePayment, issuer); + // makePaymentTrait is defined in the passed-in configuration and adds + // additional methods to corePayment + const makePaymentTraitIter = makePaymentTrait(corePayment, issuer); + const paymentTrait = makePaymentTraitIter.next().value; + const payment = harden({ + ...paymentTrait, + ...corePayment, + }); + makePaymentTraitIter.next(payment); // ///////////////// commit point ////////////////// // All queries above passed with no side effects. @@ -219,10 +229,15 @@ Description must be truthy: ${description}`; }, }); - // makeCustomIssuer is defined in the passed-in configuration and - // can add additional methods to (or even override, though this is - // firmly discouraged) the coreIssuer methods - const issuer = makeCustomIssuer(coreIssuer); + // makeIssuerTrait is defined in the passed-in configuration and adds + // additional methods to coreIssuer. + const makeIssuerTraitIter = makeIssuerTrait(coreIssuer); + const issuerTrait = makeIssuerTraitIter.next().value; + const issuer = harden({ + ...issuerTrait, + ...coreIssuer, + }); + makeIssuerTraitIter.next(issuer); const label = harden({ issuer, description }); @@ -289,20 +304,30 @@ Description must be truthy: ${description}`; }, }); - // makeCustomPurse is defined in the passed-in configuration and - // can add additional methods to (or even override, though this is - // firmly discouraged) the corePurse methods - const purse = makeCustomPurse(corePurse, issuer); + // makePurseTrait is defined in the passed-in configuration and + // adds additional methods to corePurse + const makePurseTraitIter = makePurseTrait(corePurse, issuer); + const purseTrait = makePurseTraitIter.next().value; + const purse = harden({ + ...purseTrait, + ...corePurse, + }); + makePurseTraitIter.next(purse); purseKeeper.recordNew(purse, initialBalance); return purse; }, }); - // makeCustomMint is defined in the passed-in configuration and - // can add additional methods to (or even override, though this is - // firmly discouraged) the coreMint methods - const mint = makeCustomMint(coreMint, issuer, assay, mintKeeper); + // makeMintTrait is defined in the passed-in configuration and + // adds additional methods to coreMint + const makeMintTraitIter = makeMintTrait(coreMint, issuer, assay, mintKeeper); + const mintTrait = makeMintTraitIter.next().value; + const mint = harden({ + ...mintTrait, + ...coreMint, + }); + makeMintTraitIter.next(mint); return mint; } diff --git a/more/pixels/pixelConfig.js b/more/pixels/pixelConfig.js index ec313f1..02cd1ff 100644 --- a/more/pixels/pixelConfig.js +++ b/more/pixels/pixelConfig.js @@ -58,103 +58,100 @@ function makePixelConfigMaker( return childIssuer.makeAmount(quantity); } - return harden({ - makeCustomPayment(superPayment, issuer) { - return harden({ - ...superPayment, - // This creates a new use object on every call. Please see - // the gallery for the definition of the use object that is - // created here by calling `makeUseObj` - getUse() { - return makeUseObj(issuer, superPayment); - }, - // Revoke all descendants of this payment and mint a new - // payment from the child mint with the same quantity as the - // original payment - claimChild() { - prepareChildMint(issuer); - const childAmount = getChildAmount( - issuer, - superPayment.getBalance(), - ); - // Remove the amount of this payment from the purses and - // payments of the childMint. Removes recursively down the - // chain until it fails to find a childMint. - childMint.revoke(childAmount); - const childPurse = childMint.mint(childAmount); - return childPurse.withdrawAll(); - }, - }); - }, - makeCustomPurse(superPurse, issuer) { - return harden({ - ...superPurse, - // This creates a new use object on every call. Please see - // the gallery for the definition of the use object that is - // created here by calling `makeUseObj` - getUse() { - return makeUseObj(issuer, superPurse); - }, - // Revoke all descendants of this purse and mint a new purse - // from the child mint with the same quantity as the - // original purse - claimChild() { - prepareChildMint(issuer); - const childAmount = getChildAmount(issuer, superPurse.getBalance()); - // Remove the amount of this payment from the purses and - // payments of the childMint. Removes recursively down the - // chain until it fails to find a childMint. - childMint.revoke(childAmount); - return childMint.mint(childAmount); - }, - }); - }, - makeCustomMint(superMint, issuer, assay, mintKeeper) { - return harden({ - ...superMint, - // revoke destroys the amount from this mint and calls - // revoke on the childMint with an amount of the same - // quantity. Destroying the amount depends on the fact that - // pixels are uniquely identifiable by their `x` and `y` - // coordinates. Therefore, destroy can look for purses and - // payments that include those particular pixels and remove - // the particular pixels from those purses or payments - revoke(amount) { - amount = assay.coerce(amount); + function* makePaymentTrait(superPayment, issuer) { + yield harden({ + // This creates a new use object on every call. Please see + // the gallery for the definition of the use object that is + // created here by calling `makeUseObj` + getUse() { + return makeUseObj(issuer, superPayment); + }, + // Revoke all descendants of this payment and mint a new + // payment from the child mint with the same quantity as the + // original payment + claimChild() { + prepareChildMint(issuer); + const childAmount = getChildAmount(issuer, superPayment.getBalance()); + // Remove the amount of this payment from the purses and + // payments of the childMint. Removes recursively down the + // chain until it fails to find a childMint. + childMint.revoke(childAmount); + const childPurse = childMint.mint(childAmount); + return childPurse.withdrawAll(); + }, + }); + } + function* makePurseTrait(superPurse, issuer) { + yield harden({ + // This creates a new use object on every call. Please see + // the gallery for the definition of the use object that is + // created here by calling `makeUseObj` + getUse() { + return makeUseObj(issuer, superPurse); + }, + // Revoke all descendants of this purse and mint a new purse + // from the child mint with the same quantity as the + // original purse + claimChild() { + prepareChildMint(issuer); + const childAmount = getChildAmount(issuer, superPurse.getBalance()); + // Remove the amount of this payment from the purses and + // payments of the childMint. Removes recursively down the + // chain until it fails to find a childMint. + childMint.revoke(childAmount); + return childMint.mint(childAmount); + }, + }); + } + function* makeMintTrait(_superMint, issuer, assay, mintKeeper) { + yield harden({ + // revoke destroys the amount from this mint and calls + // revoke on the childMint with an amount of the same + // quantity. Destroying the amount depends on the fact that + // pixels are uniquely identifiable by their `x` and `y` + // coordinates. Therefore, destroy can look for purses and + // payments that include those particular pixels and remove + // the particular pixels from those purses or payments + revoke(amount) { + amount = assay.coerce(amount); - mintKeeper.destroy(amount); - if (childMint !== undefined) { - childMint.revoke(getChildAmount(issuer, amount)); // recursively revoke child assets - } - }, - }); - }, - makeCustomIssuer(superIssuer) { - return harden({ - ...superIssuer, - // The parent issuer is one level up in the chain of - // issuers. - getParentIssuer() { - return parentIssuer; - }, - // The child issuer is one level down in the chain of issuers. - getChildIssuer() { - prepareChildMint(superIssuer); - return childIssuer; - }, - // Returns true if the alleged descendant issuer is either a - // child, grandchild, or any other kind of descendant - isDescendantIssuer(allegedDescendant) { - if (childIssuer === undefined) { - return false; - } - if (childIssuer === allegedDescendant) { - return true; - } - return childIssuer.isDescendantIssuer(allegedDescendant); - }, - }); - }, + mintKeeper.destroy(amount); + if (childMint !== undefined) { + childMint.revoke(getChildAmount(issuer, amount)); // recursively revoke child assets + } + }, + }); + } + function* makeIssuerTrait(superIssuer) { + yield harden({ + // The parent issuer is one level up in the chain of + // issuers. + getParentIssuer() { + return parentIssuer; + }, + // The child issuer is one level down in the chain of issuers. + getChildIssuer() { + prepareChildMint(superIssuer); + return childIssuer; + }, + // Returns true if the alleged descendant issuer is either a + // child, grandchild, or any other kind of descendant + isDescendantIssuer(allegedDescendant) { + if (childIssuer === undefined) { + return false; + } + if (childIssuer === allegedDescendant) { + return true; + } + return childIssuer.isDescendantIssuer(allegedDescendant); + }, + }); + } + return harden({ + makePaymentTrait, + makePurseTrait, + makeMintTrait, + makeIssuerTrait, makeMintKeeper: makePixelMintKeeper, strategy: makePixelStrategy(canvasSize), });