Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
switch to Mark's "weird way to compose traits without giving up control"
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills committed Sep 26, 2019
1 parent ac67cb8 commit 4ff3341
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 166 deletions.
41 changes: 21 additions & 20 deletions core/config/noCustomization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
54 changes: 28 additions & 26 deletions core/config/seatConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
73 changes: 49 additions & 24 deletions core/issuers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 });

Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 4ff3341

Please sign in to comment.