Skip to content

Commit

Permalink
refactor: imporved API for passing governedContract facets
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Sep 16, 2021
1 parent 7498e76 commit afd01b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
15 changes: 7 additions & 8 deletions packages/governance/src/contractGovernor.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const start = async (zcf, privateArgs) => {
governed: {
issuerKeywordRecord: governedIssuerKeywordRecord,
terms: governedTerms,
privateArgs: privateContractArgs,
},
} = zcf.getTerms();

Expand All @@ -105,6 +106,7 @@ const start = async (zcf, privateArgs) => {
governedContractInstallation,
governedIssuerKeywordRecord,
augmentedTerms,
privateContractArgs,
),
E(zoe).getInvitationDetails(poserInvitation),
]);
Expand All @@ -125,13 +127,6 @@ const start = async (zcf, privateArgs) => {
timer,
);

const governedContractCreatorFacet = Far('governedContract', {
voteOnParamChange,
getCreatorFacet: () => limitedCreatorFacet,
getInstance: () => governedInstance,
getPublicFacet: () => governedPF,
});

const validateVoteCounter = async voteCounter => {
const created = await E(createdQuestion)(voteCounter);
assert(created, X`VoteCounter was not created by this contractGovernor`);
Expand All @@ -156,8 +151,12 @@ const start = async (zcf, privateArgs) => {
});
};

/** @type {GovernedContractFacetAccess} */
const creatorFacet = Far('governor creatorFacet', {
getGovernedCreatorFacet: () => governedContractCreatorFacet,
voteOnParamChange,
getCreatorFacet: () => limitedCreatorFacet,
getInstance: () => governedInstance,
getPublicFacet: () => governedPF,
});

/** @type {GovernorPublic} */
Expand Down
12 changes: 4 additions & 8 deletions packages/governance/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
/**
* @callback SubmitVote
* @param {Handle<'Voter'>} voterHandle
* @param {[Position]} chosenPositions
* @param {Position[]} chosenPositions
* @param {bigint=} weight
*/

Expand Down Expand Up @@ -450,7 +450,7 @@
*/

/**
* @typedef {Object} GovernedContractCreatorFacet
* @typedef {Object} GovernedContractFacetAccess
* @property {VoteOnParamChange} voteOnParamChange
* @property {() => Promise<LimitedCreatorFacet>} getCreatorFacet - creator
* facet of the governed contract, without the tightly held ability to change
Expand All @@ -467,12 +467,8 @@
*/

/**
* @callback StartGovernedContract
* @param {RegistrarCreatorFacet} registrarCreatorFacet
* @param {Installation} governedContractInstallation
* @param {IssuerKeywordRecord} issuerKeywordRecord
* @param {Terms} customTerms
* @returns {GovernedContractCreatorFacet}
* @typedef {Object} ParamManagerRetriever
* @property {(paramSpec: ParamSpecification) => ParamManagerFull} get
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const { quote: q } = assert;
* @param {ERef<ZoeService>} zoe
* @param {(string:string) => undefined} log
* @param {Record<string,Installation>} installations
* @param {ERef<GovernedContractCreatorFacet>} contractCreatorFacet
* @param {ERef<GovernedContractFacetAccess>} contractFacetAccess
* @returns {Promise<*>}
*/
const contractGovernorStart = async (
zoe,
log,
installations,
contractCreatorFacet,
contractFacetAccess,
) => {
const { details, instance, outcomeOfUpdate } = await E(
contractCreatorFacet,
contractFacetAccess,
).voteOnParamChange(
{ key: 'main', parameterName: 'MalleableNumber' },
299792458n,
Expand Down Expand Up @@ -178,19 +178,13 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {
const { creatorFacet: governor, instance: governorInstance } = await E(
zoe,
).startInstance(installations.contractGovernor, {}, terms, privateArgs);
const governedCreatorFacet = E(governor).getGovernedCreatorFacet();
const governedInstance = E(governedCreatorFacet).getInstance();
const governedInstance = E(governor).getInstance();

const [testName] = argv;
switch (testName) {
case 'contractGovernorStart': {
const votersP = createVoters(registrarCreatorFacet, voterCreator);
const detailsP = contractGovernorStart(
zoe,
log,
installations,
governedCreatorFacet,
);
const detailsP = contractGovernorStart(zoe, log, installations, governor);
await votersVote(detailsP, votersP, [0, 1, 1, 0, 0]);

await oneVoterValidate(
Expand Down

0 comments on commit afd01b5

Please sign in to comment.