-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add a committeeRegistrar update testing imports for issue 768 add minimal types better fix for test dependencies change jsconfig.json includes, update packages, change swingset test (#3300) update committeeRegistrar for relocation of voterFacet integrate with changes to ballot PR (3233) * refactor: more legibility make ballotCounter instance accessible from ballot add more to terms of ballotCounter (closureRule) add more to public facet of Registrar one registrar per contract/vat: details in terms use zcf.getInstance() to supply instances In tests voters look up their own positions voters cast ballots on notification * refactor: closureRule renamed to closingRule * refactor: test and repair getOpenQuestions * chore: more cleanup * chore: review suggestions move some dependencies to devDependencies expect promises for ballots allow voters to cast directly with registrar * refactor: await all the promises, not just the last in a chain add a test for multiple votes by a single electorate
- Loading branch information
1 parent
7a0bb8a
commit 7547357
Showing
10 changed files
with
717 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// @ts-check | ||
|
||
import { Far } from '@agoric/marshal'; | ||
import { makeNotifierKit } from '@agoric/notifier'; | ||
import { E } from '@agoric/eventual-send'; | ||
import { makeStore } from '@agoric/store'; | ||
import { allComparable } from '@agoric/same-structure'; | ||
|
||
// Each CommitteeRegistrar represents a particular set of voters. The number of | ||
// voters is visible in the terms. | ||
const start = zcf => { | ||
// Question => { voter, publicFacet } | ||
const allQuestions = makeStore('Question'); | ||
const { notifier, updater } = makeNotifierKit(); | ||
const invitations = []; | ||
|
||
const getOpenQuestions = async () => { | ||
const isOpenPQuestions = allQuestions.keys().map(key => { | ||
const { publicFacet } = allQuestions.get(key); | ||
return [E(publicFacet).isOpen(), key]; | ||
}); | ||
const isOpenQuestions = await allComparable(harden(isOpenPQuestions)); | ||
return isOpenQuestions | ||
.filter(([open, _key]) => open) | ||
.map(([_open, key]) => key); | ||
}; | ||
|
||
const makeCommitteeVoterInvitation = index => { | ||
const handler = voterSeat => { | ||
return Far(`voter${index}`, { | ||
castBallot: ballotp => { | ||
E.when(ballotp, ballot => { | ||
const { voter } = allQuestions.get(ballot.question); | ||
return E(voter).submitVote(voterSeat, ballot); | ||
}); | ||
}, | ||
castBallotFor: (question, positions) => { | ||
const { publicFacet: counter, voter } = allQuestions.get(question); | ||
const ballotTemplate = E(counter).getBallotTemplate(); | ||
const ballot = E(ballotTemplate).choose(positions); | ||
return E(voter).submitVote(voterSeat, ballot); | ||
}, | ||
}); | ||
}; | ||
|
||
return zcf.makeInvitation(handler, `Voter${index}`); | ||
}; | ||
|
||
const { committeeName, committeeSize } = zcf.getTerms(); | ||
for (let i = 0; i < committeeSize; i += 1) { | ||
invitations[i] = makeCommitteeVoterInvitation(i); | ||
} | ||
|
||
/** @type {AddQuestion} */ | ||
const addQuestion = async (voteCounter, questionDetailsShort) => { | ||
const questionDetails = { | ||
...questionDetailsShort, | ||
registrar: zcf.getInstance(), | ||
}; | ||
// facets of the ballot counter. Suppress creatorInvitation and adminFacet. | ||
const { creatorFacet, publicFacet, instance } = await E( | ||
zcf.getZoeService(), | ||
).startInstance(voteCounter, {}, questionDetails); | ||
const facets = { voter: E(creatorFacet).getVoterFacet(), publicFacet }; | ||
|
||
updater.updateState(questionDetails.question); | ||
allQuestions.init(questionDetails.question, facets); | ||
return { creatorFacet, publicFacet, instance }; | ||
}; | ||
|
||
const creatorFacet = Far('adminFacet', { | ||
addQuestion, | ||
getVoterInvitations: () => invitations, | ||
getQuestionNotifier: () => notifier, | ||
}); | ||
|
||
const publicFacet = Far('publicFacet', { | ||
getQuestionNotifier: () => notifier, | ||
getOpenQuestions, | ||
getName: () => committeeName, | ||
getInstance: zcf.getInstance, | ||
getDetails: name => | ||
E(E(allQuestions.get(name).publicFacet).getBallotTemplate()).getDetails(), | ||
getBallot: name => | ||
E(allQuestions.get(name).publicFacet).getBallotTemplate(), | ||
}); | ||
|
||
return { publicFacet, creatorFacet }; | ||
}; | ||
|
||
harden(start); | ||
export { start }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.