Skip to content

Commit

Permalink
fix: move makeQueryInvitation back to the publicFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 5, 2020
1 parent a024867 commit b73733b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/exported.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
/**
* @typedef {Object} OraclePublicFacet the public methods accessible from the
* contract instance
* @property {(query: any) => ERef<Invitation>} makeQueryInvitation create an
* invitation for an oracle query
* @property {(query: any) => ERef<any>} query make an unpaid query
*/

Expand All @@ -152,8 +154,6 @@
* makeWithdrawInvitation create an invitation to withdraw fees
* @property {() => Promise<Invitation>} makeShutdownInvitation
* Make an invitation to withdraw all fees and shutdown
* @property {(query: any) => ERef<Invitation>} makeQueryInvitation create an
* invitation for an oracle query
*/

/**
Expand Down
46 changes: 23 additions & 23 deletions packages/zoe/src/contracts/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,6 @@ const start = async zcf => {
};
return zcf.makeInvitation(shutdown, 'shutdown');
},
async makeQueryInvitation(query) {
/** @type {OfferHandler} */
const doQuery = async querySeat => {
try {
const fee = querySeat.getAmountAllocated('Fee', feeBrand);
const { requiredFee, reply } = await E(handler).onQuery(query, fee);
if (requiredFee) {
trade(
zcf,
{ seat: querySeat, gains: {} },
{ seat: feeSeat, gains: { Fee: requiredFee } },
);
}
querySeat.exit();
E(handler).onReply(query, reply, requiredFee);
return reply;
} catch (e) {
E(handler).onError(query, e);
throw e;
}
};
return zcf.makeInvitation(doQuery, 'oracle query', { query });
},
};

const creatorFacet = {
Expand All @@ -99,6 +76,29 @@ const start = async zcf => {
throw e;
}
},
async makeQueryInvitation(query) {
/** @type {OfferHandler} */
const doQuery = async querySeat => {
try {
const fee = querySeat.getAmountAllocated('Fee', feeBrand);
const { requiredFee, reply } = await E(handler).onQuery(query, fee);
if (requiredFee) {
trade(
zcf,
{ seat: querySeat, gains: {} },
{ seat: feeSeat, gains: { Fee: requiredFee } },
);
}
querySeat.exit();
E(handler).onReply(query, reply, requiredFee);
return reply;
} catch (e) {
E(handler).onError(query, e);
throw e;
}
};
return zcf.makeInvitation(doQuery, 'oracle query', { query });
},
};

return harden({ creatorFacet, publicFacet });
Expand Down
14 changes: 7 additions & 7 deletions packages/zoe/test/unitTests/contracts/test-oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ test.before(

const feeAmount = link.amountMath.make(1000);
/**
* @param {ExecutionContext} t
* @param {ExecutionContext} _t
* @returns {Promise<OracleKit>}
*/
const makePingOracle = async t => {
const makePingOracle = async _t => {
/** @type {OracleHandler} */
const oracleHandler = harden({
async onQuery(query, fee) {
Expand Down Expand Up @@ -111,10 +111,10 @@ test('single oracle', /** @param {ExecutionContext} t */ async t => {
const query4 = { kind: 'Paid', data: 'bot' };

const freeReply = E(publicFacet).query({ hello: 'World' });
const invitation1 = E(pingCreator).makeQueryInvitation(query1);
const invitation2 = E(pingCreator).makeQueryInvitation(query2);
const invitation3 = E(pingCreator).makeQueryInvitation(query3);
const invitation4 = E(pingCreator).makeQueryInvitation(query4);
const invitation1 = E(publicFacet).makeQueryInvitation(query1);
const invitation2 = E(publicFacet).makeQueryInvitation(query2);
const invitation3 = E(publicFacet).makeQueryInvitation(query3);
const invitation4 = E(publicFacet).makeQueryInvitation(query4);

// Ensure all three are real Zoe invitations.
t.truthy(await E(invitationIssuer).isLive(invitation1));
Expand Down Expand Up @@ -215,7 +215,7 @@ test('single oracle', /** @param {ExecutionContext} t */ async t => {
t.deepEqual(kvals, [['Fee', link.amountMath.make(799)]]);
});

const badInvitation = E(pingCreator).makeQueryInvitation({
const badInvitation = E(publicFacet).makeQueryInvitation({
hello: 'nomore',
});
const badOffer = E(zoe).offer(badInvitation);
Expand Down

0 comments on commit b73733b

Please sign in to comment.