Skip to content

Commit

Permalink
make the makeMint config more trait-like (Agoric#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills committed Aug 15, 2019
1 parent 6f45d73 commit 50c43ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
16 changes: 8 additions & 8 deletions core/config/noCustomization.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ 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`.
const noCustomization = harden({
makeCustomPayment(superPayment) {
return superPayment;
makePaymentTrait(_superPayment) {
return harden({});
},
makeCustomPurse(superPurse) {
return superPurse;
makePurseTrait(_superPurse) {
return harden({});
},
makeCustomMint(superMint) {
return superMint;
makeMintTrait(_superMint) {
return harden({});
},
makeCustomIssuer(superIssuer) {
return superIssuer;
makeIssuerTrait(_superIssuer) {
return harden({});
},
});

Expand Down
49 changes: 29 additions & 20 deletions core/issuers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,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,
makeAssay,
} = makeConfig();
Expand All @@ -52,10 +52,12 @@ Description must be truthy: ${description}`;
},
});

// makeCustomPayment is defined in the passed-in configuration and
// allows for the customization of the payment, including adding
// additional methods
const payment = makeCustomPayment(corePayment, issuer);
// makePaymentTrait is defined in the passed-in configuration and adds
// additional methods to corePayment
const payment = harden({
...makePaymentTrait(corePayment, issuer),
...corePayment,
});

// ///////////////// commit point //////////////////
// All queries above passed with no side effects.
Expand Down Expand Up @@ -115,10 +117,12 @@ Description must be truthy: ${description}`;
},
});

// makeCustomIssuer is defined in the passed-in configuration and
// allows for the customization of the issuer, including adding
// additional methods
const issuer = makeCustomIssuer(coreIssuer);
// makeIssuerTrait is defined in the passed-in configuration and adds
// additional methods to coreIssuer.
const issuer = harden({
...makeIssuerTrait(coreIssuer),
...coreIssuer,
});

const label = harden({ issuer, description });

Expand Down Expand Up @@ -189,19 +193,24 @@ Description must be truthy: ${description}`;
},
});

// makeCustomPurse is defined in the passed-in configuration and
// allows for the customization of the purse, including adding
// additional methods
const purse = makeCustomPurse(corePurse, issuer);
// makePurseTrait is defined in the passed-in configuration and
// adds additional methods to corePurse
const purse = harden({
...makePurseTrait(corePurse, issuer),
...corePurse,
});

purseKeeper.recordNew(purse, initialBalance);
return purse;
},
});

// makeCustomMint is defined in the passed-in configuration and
// allows for the customization of the mint, including adding
// additional methods
const mint = makeCustomMint(coreMint, issuer, assay, mintKeeper);
// makeMintTrait is defined in the passed-in configuration and
// adds additional methods to coreMint
const mint = harden({
...makeMintTrait(coreMint, issuer, assay, mintKeeper),
...coreMint,
});

return mint;
}
Expand Down
12 changes: 4 additions & 8 deletions more/pixels/pixelConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ function makePixelConfigMaker(
}

return harden({
makeCustomPayment(superPayment, issuer) {
makePaymentTrait(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`
Expand All @@ -88,9 +87,8 @@ function makePixelConfigMaker(
},
});
},
makeCustomPurse(superPurse, issuer) {
makePurseTrait(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`
Expand All @@ -111,9 +109,8 @@ function makePixelConfigMaker(
},
});
},
makeCustomMint(superMint, issuer, assay, mintKeeper) {
makeMintTrait(_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
Expand All @@ -131,9 +128,8 @@ function makePixelConfigMaker(
},
});
},
makeCustomIssuer(superIssuer) {
makeIssuerTrait(superIssuer) {
return harden({
...superIssuer,
// The parent issuer is one level up in the chain of
// issuers.
getParentIssuer() {
Expand Down

0 comments on commit 50c43ac

Please sign in to comment.