Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for #3663: move feePurse binding into zoe #3675

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 8 additions & 53 deletions packages/zoe/src/applyFeePurse.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,28 @@
// @ts-check

import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

/**
* @deprecated use `.bindDefaultFeePurse` directly
* Partially apply an already existing feePurse to Zoe methods.
*
* @param {ERef<ZoeServiceFeePurseRequired>} zoe
* @param {ERef<FeePurse>} defaultFeePurse
* @returns {ZoeService}
* @returns {ERef<ZoeService>}
*/
const applyFeePurse = (zoe, defaultFeePurse) => {
return Far('zoeService', {
makeFeePurse: (...args) => E(zoe).makeFeePurse(...args),

// A feePurse is required
install: (bundle, feePurse = defaultFeePurse) =>
E(zoe).install(bundle, feePurse),
startInstance: (
installation,
issuerKeywordRecord,
terms,
privateArgs,
feePurse = defaultFeePurse,
) =>
E(zoe).startInstance(
installation,
issuerKeywordRecord,
terms,
privateArgs,
feePurse,
),
offer: (
invitation,
proposal,
paymentKeywordRecord,
offerArgs,
feePurse = defaultFeePurse,
) =>
E(zoe).offer(
invitation,
proposal,
paymentKeywordRecord,
offerArgs,
feePurse,
),
getPublicFacet: (instance, feePurse = defaultFeePurse) =>
E(zoe).getPublicFacet(instance, feePurse),

// The functions below are getters only and have no impact on
// state within Zoe
getInvitationIssuer: () => E(zoe).getInvitationIssuer(),
getFeeIssuer: () => E(zoe).getFeeIssuer(),
getBrands: (...args) => E(zoe).getBrands(...args),
getIssuers: (...args) => E(zoe).getIssuers(...args),
getTerms: (...args) => E(zoe).getTerms(...args),
getInstance: (...args) => E(zoe).getInstance(...args),
getInstallation: (...args) => E(zoe).getInstallation(...args),
getInvitationDetails: (...args) => E(zoe).getInvitationDetails(...args),
getInstallationForInstance: (...args) =>
E(zoe).getInstallationForInstance(...args),
});
if ('bindDefaultFeePurse' in zoe) {
return zoe.bindDefaultFeePurse(defaultFeePurse);
}
return E(zoe).bindDefaultFeePurse(defaultFeePurse);
};

/**
* @deprecated use `.bindDefaultFeePurse` directly
* Make a new feePurse and then partially apply it to Zoe methods.
*
* @param {ZoeServiceFeePurseRequired} zoe
* @returns {{ zoeService: ZoeService, feePurse: Promise<FeePurse> }}
* @returns {{ zoeService: ERef<ZoeService>, feePurse: Promise<FeePurse> }}
*/
const makeAndApplyFeePurse = zoe => {
const feePurse = E(zoe).makeFeePurse();
Expand Down
9 changes: 9 additions & 0 deletions packages/zoe/src/zoeService/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* handle, and any custom properties specific to the contract.
* @property {GetFeeIssuer} getFeeIssuer
* @property {MakeFeePurse} makeFeePurse
* @property {BindDefaultFeePurse} bindDefaultFeePurse
*/

/**
Expand All @@ -61,6 +62,13 @@
* @returns {Promise<FeePurse>}
*/

/**
* @callback BindDefaultFeePurse
* // TODO Should this type be simply {FeePurse} without the ERef?
* @param {ERef<FeePurse>} defaultFeePurse
* @returns {ZoeService}
*/

/**
* @callback GetPublicFacet
* @param {Instance} instance
Expand Down Expand Up @@ -366,4 +374,5 @@
* @property {GetInvitationDetails} getInvitationDetails
* @property {GetFeeIssuer} getFeeIssuer
* @property {MakeFeePurse} makeFeePurse
* @property {BindDefaultFeePurse} bindDefaultFeePurse
*/
47 changes: 47 additions & 0 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,52 @@ const makeZoeKit = (

const { makeFeePurse, assertFeePurse } = setupMakeFeePurse(feeIssuer);

// TODO Maybe move into feePurse.js ?
const bindDefaultFeePurse = defaultFeePurse =>
Far('bound zoeService', {
// The functions from zoe not overridden below have no impact on
// state within Zoe
// eslint-disable-next-line no-use-before-define
...zoeService,

install: (bundle, feePurse = defaultFeePurse) =>
// eslint-disable-next-line no-use-before-define
zoeService.install(bundle, feePurse),
startInstance: (
installation,
issuerKeywordRecord,
terms,
privateArgs,
feePurse = defaultFeePurse,
) =>
// eslint-disable-next-line no-use-before-define
zoeService.startInstance(
installation,
issuerKeywordRecord,
terms,
privateArgs,
feePurse,
),
offer: (
invitation,
proposal,
paymentKeywordRecord,
offerArgs,
feePurse = defaultFeePurse,
) =>
// eslint-disable-next-line no-use-before-define
zoeService.offer(
invitation,
proposal,
paymentKeywordRecord,
offerArgs,
feePurse,
),
getPublicFacet: (instance, feePurse = defaultFeePurse) =>
// eslint-disable-next-line no-use-before-define
zoeService.getPublicFacet(instance, feePurse),
});

// This method contains the power to create a new ZCF Vat, and must
// be closely held. vatAdminSvc is even more powerful - any vat can
// be created. We severely restrict access to vatAdminSvc for this reason.
Expand Down Expand Up @@ -119,6 +165,7 @@ const makeZoeKit = (
startInstance,
offer,
makeFeePurse,
bindDefaultFeePurse,
getPublicFacet,

// The functions below are getters only and have no impact on
Expand Down
2 changes: 2 additions & 0 deletions packages/zoe/test/unitTests/test-applyFeePurse.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {

const zoe = Far('mockZoe', {
makeFeePurse: () => Far('feePurse', {}),
// TODO Not an adequate mock. Test broken.
bindDefaultFeePurse: feePurse => zoe,
// @ts-ignore Mocked for tests
install: (bundle, feePurse) => feePurse,
startInstance: (
Expand Down