Skip to content

Commit

Permalink
Merge branch 'master' into xs-config-default
Browse files Browse the repository at this point in the history
  • Loading branch information
warner authored Apr 29, 2021
2 parents 5a714e9 + a996afb commit d3873d0
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 41 deletions.
10 changes: 0 additions & 10 deletions packages/zoe/src/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,6 @@
* returns some statistics about the vat in which the contract is running.
*/

/**
* @callback GetAmountOfInvitationThen
* Get the amount of an invitation and then call the `onFulfilled`
* function. If the invitation is not a Zoe invitation, the promise
* rejects with a helpful error message and `onFulfilled` is not called.
* @param {ERef<Invitation>} invitationP
* @param {(amount: Amount) => any} onFulfilled
* @returns {any} the result of `onFulfilled`
*/

/**
* @callback GetMathKindByBrand
* Get the mathKind for a brand known by Zoe
Expand Down
38 changes: 38 additions & 0 deletions packages/zoe/src/zoeService/invitationQueries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @ts-check

import { assert, details as X } from '@agoric/assert';
import { E } from '@agoric/eventual-send';

export const makeInvitationQueryFns = invitationIssuer => {
/** @type {GetInvitationDetails} */
const getInvitationDetails = async invitationP => {
const onRejected = reason => {
const err = assert.error(
X`A Zoe invitation is required, not ${invitationP}`,
);
assert.note(err, X`Due to ${reason}`);
throw err;
};
return E.get(
E.get(
E(invitationIssuer)
.getAmountOf(invitationP)
.catch(onRejected),
).value,
)[0];
};

/** @type {GetInstance} */
const getInstance = invitation =>
E.get(getInvitationDetails(invitation)).instance;

/** @type {GetInstallation} */
const getInstallation = invitation =>
E.get(getInvitationDetails(invitation)).installation;

return harden({
getInstance,
getInstallation,
getInvitationDetails,
});
};
61 changes: 51 additions & 10 deletions packages/zoe/src/zoeService/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,57 @@
* @property {Install} install
* @property {StartInstance} startInstance
* @property {Offer} offer
* @property {(instance: Instance) => Object} getPublicFacet
* @property {(instance: Instance) => IssuerKeywordRecord} getIssuers
* @property {(instance: Instance) => BrandKeywordRecord} getBrands
* @property {(instance: Instance) => Object} getTerms
* @property {(invitation: ERef<Invitation>) => Promise<Instance>} getInstance
* @property {(invitation: ERef<Invitation>) => Promise<Installation>} getInstallation
* @property {(invitation: ERef<Invitation>) => Promise<InvitationDetails>}
* getInvitationDetails - return an object with the instance,
* installation, description, invitation handle, and any custom properties
* specific to the contract.
* @property {GetPublicFacet} getPublicFacet
* @property {GetIssuers} getIssuers
* @property {GetBrands} getBrands
* @property {GetTerms} getTerms
* @property {GetInstance} getInstance
* @property {GetInstallation} getInstallation
* @property {GetInvitationDetails} getInvitationDetails - return an
* object with the instance, installation, description, invitation
* handle, and any custom properties specific to the contract.
*/

/**
* @callback GetPublicFacet
* @param {Instance} instance
* @returns {Object}
*/

/**
* @callback GetIssuers
* @param {Instance} instance
* @returns {IssuerKeywordRecord}
*/

/**
* @callback GetBrands
* @param {Instance} instance
* @returns {BrandKeywordRecord}
*/

/**
* @callback GetTerms
* @param {Instance} instance
* @returns {Terms}
*/

/**
* @callback GetInstance
* @param {ERef<Invitation>} invitation
* @returns {Promise<Instance>}
*/

/**
* @callback GetInstallation
* @param {ERef<Invitation>} invitation
* @returns {Promise<Installation>}
*/

/**
* @callback GetInvitationDetails
* @param {ERef<Invitation>} invitation
* @returns {Promise<InvitationDetails>}
*/

/**
Expand Down
31 changes: 10 additions & 21 deletions packages/zoe/src/zoeService/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { makeIssuerStorage } from '../issuerStorage';
import { makeAndStoreInstanceRecord } from '../instanceRecordStorage';
import { makeIssuerRecord } from '../issuerRecord';
import { makeOffer } from './offer/offer';
import { makeInvitationQueryFns } from './invitationQueries';

/**
* Create an instance of Zoe.
Expand All @@ -47,6 +48,12 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
/** @type {WeakStore<SeatHandle, ZoeSeatAdmin>} */
const seatHandleToZoeSeatAdmin = makeNonVOWeakStore('seatHandle');

const {
getInstance,
getInstallation,
getInvitationDetails,
} = makeInvitationQueryFns(invitationKit.issuer);

const {
createPurse,
makeLocalPurse,
Expand All @@ -70,15 +77,6 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
getMathKindByBrand,
);

/** @type {GetAmountOfInvitationThen} */
const getAmountOfInvitationThen = async (invitationP, onFulfilled) => {
const onRejected = () =>
assert.fail(X`A Zoe invitation is required, not ${invitationP}`);
return E(invitationKit.issuer)
.getAmountOf(invitationP)
.then(onFulfilled, onRejected);
};

/** @type {ZoeService} */
const zoeService = Far('zoeService', {
getInvitationIssuer: () => invitationKit.issuer,
Expand All @@ -88,18 +86,9 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) {
getBrands: instance => instanceToInstanceAdmin.get(instance).getBrands(),
getIssuers: instance => instanceToInstanceAdmin.get(instance).getIssuers(),
getTerms: instance => instanceToInstanceAdmin.get(instance).getTerms(),
getInstance: invitation => {
const onFulfilled = amount => amount.value[0].instance;
return getAmountOfInvitationThen(invitation, onFulfilled);
},
getInstallation: invitation => {
const onFulfilled = amount => amount.value[0].installation;
return getAmountOfInvitationThen(invitation, onFulfilled);
},
getInvitationDetails: invitation => {
const onFulfilled = amount => amount.value[0];
return getAmountOfInvitationThen(invitation, onFulfilled);
},
getInstance,
getInstallation,
getInvitationDetails,
startInstance: async (
installationP,
uncleanIssuerKeywordRecord = harden({}),
Expand Down

0 comments on commit d3873d0

Please sign in to comment.