Skip to content

Commit

Permalink
fix: tweak more types, make getVatAdmin into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jul 27, 2020
1 parent fe20aa4 commit 8c1e9d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
16 changes: 9 additions & 7 deletions packages/zoe/src/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { assert, details, q } from '@agoric/assert';
import { E } from '@agoric/eventual-send';
import { isOfferSafe } from './offerSafety';
import { areRightsConserved } from './rightsConservation';
import { assertKeywordName, cleanProposal, getKeywords } from './cleanProposal';
import { assertKeywordName, getKeywords } from './cleanProposal';
import { makeContractTables } from './state';
import { filterObj, filterFillAmounts, tuple } from './objArrayConversion';
import { evalContractBundle } from './evalContractCode';
Expand Down Expand Up @@ -39,7 +39,7 @@ export function buildRootObject(_vatPowers) {
'brandKeywordRecord',
);
/**
* @param {InstanceRecord} instanceRecord
* @param {InstanceRecord & ZcfInstanceRecord} instanceRecord
*/
const visibleInstanceRecord = instanceRecord =>
filterObj(instanceRecord, visibleInstanceRecordFields);
Expand All @@ -56,7 +56,7 @@ export function buildRootObject(_vatPowers) {
/** @param {OfferRecord} offerRecord */
const removeAmountsAndNotifier = offerRecord =>
filterObj(offerRecord, ['handle', 'instanceHandle', 'proposal']);
/** @param {IssuerRecord} issuerRecord */
/** @param {IssuerRecord&PrivateIssuerRecord} issuerRecord */
const removePurse = issuerRecord =>
filterObj(issuerRecord, ['issuer', 'brand', 'amountMath']);

Expand Down Expand Up @@ -172,6 +172,9 @@ export function buildRootObject(_vatPowers) {
* Create the contract-facing Zoe facet.
*
* @param {ZoeService} zoeService
* @param {InstanceRecord & ZcfInstanceRecord} instanceRecord
* @param {Issuer} inviteIssuer
* @param {ZoeForZcf} zoeForZcf
* @returns {ContractFacet}
*/
const makeContractFacet = (
Expand Down Expand Up @@ -240,7 +243,7 @@ export function buildRootObject(_vatPowers) {
getIssuerForBrand: brand => issuerTable.get(brand).issuer,
getBrandForIssuer: issuer => issuerTable.brandFromIssuer(issuer),
getAmountMath: getAmountMathForBrand,
getVatAdmin: instanceRecord.adminNode,
getVatAdmin: () => instanceRecord.adminNode,
};
return harden(contractFacet);
};
Expand All @@ -257,16 +260,15 @@ export function buildRootObject(_vatPowers) {
finish: () => {},
});

const cleanedProposal = cleanProposal(getAmountMathForBrand, proposal);
const offerRecord = {
instanceHandle,
proposal: cleanedProposal,
proposal,
currentAllocation: allocation,
notifier: undefined,
updater: ignoringUpdater,
};

const { exit } = cleanedProposal;
const { exit } = proposal;
const [exitKind] = Object.getOwnPropertyNames(exit);

/** @type {CompleteObj | undefined} */
Expand Down
10 changes: 8 additions & 2 deletions packages/zoe/src/internal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @typedef {Object} ZcfForZoe
* The facet ZCF presents to Zoe.
*
* @property {(offerHandle: OfferHandle, proposal: Proposal, allocation: Allocation) => (CompleteObj | undefined)} addOffer
* @property {(offerHandle: OfferHandle, proposal: ProposalRecord, allocation: Allocation) => (CompleteObj | undefined)} addOffer
* Add a single offer to this contract instance.
*/

Expand All @@ -40,7 +40,7 @@
* @typedef StartContractParams
* @property {ZoeService} zoeService - The canonical Zoe service in case the contract wants it
* @property {SourceBundle} bundle an object containing source code and moduleFormat
* @property {InstanceRecord} instanceData, fields for the instanceRecord
* @property {InstanceRecord&InternalInstanceRecord} instanceData, fields for the instanceRecord
* @property {ZoeForZcf} zoeForZcf - An inner facet of Zoe for the contractFacet's use
* @property {Issuer} inviteIssuer, Zoe's inviteIssuer, for the contract to use
*
Expand Down Expand Up @@ -73,6 +73,12 @@
* @property {Promise<ZcfForZoe>} zcfForZoe - the inner facet for Zoe to use
* @property {Set<OfferHandle>} offerHandles - the offer handles for this instance
*
* @typedef {Object} ZcfInstanceRecord
* @property {VatAdmin} adminNode
*
* @typedef {Object} PrivateIssuerRecord
* @property {Purse} purse
*
* @typedef {Object} PrivateOfferRecord
* @property {Allocation} currentAllocation - the allocation corresponding to this offer
* @property {import('@agoric/notifier').Notifier<Allocation>=} notifier - the notifier for allocation changes
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const makeIssuerTable = (withPurses = true) => {
/**
* TODO: make sure this validate function protects against malicious
* misshapen objects rather than just a general check.
* @type {Validator<IssuerRecord & { purse?: Purse }>}
* @type {Validator<IssuerRecord & PrivateIssuerRecord>}
*/
const validateSomewhat = makeValidateProperties(
withPurses
Expand Down
3 changes: 1 addition & 2 deletions packages/zoe/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
* when the issuer is added and ready.
* @param {Promise<Issuer>|Issuer} issuerP Promise for issuer
* @param {Keyword} keyword Keyword for added issuer
* @returns {Promise<Omit<IssuerRecord,'purse'>>} Issuer is added and ready
* @returns {Promise<IssuerRecord>} Issuer is added and ready
*
* @typedef {Record<string,function>} PublicAPI
*
Expand Down Expand Up @@ -342,7 +342,6 @@
* @typedef {Object} IssuerRecord
* @property {Brand} brand
* @property {Issuer} issuer
* @property {Purse} purse
* @property {AmountMath} amountMath
*
* @typedef {Object} InstallationRecord
Expand Down

0 comments on commit 8c1e9d2

Please sign in to comment.