-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Registrar 3188 #3299
Merged
Merged
Registrar 3188 #3299
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
96384e4
feat: add a committeeRegistrar
Chris-Hibbert d1380fb
refactor: more legibility
Chris-Hibbert d580ae0
refactor: closureRule renamed to closingRule
Chris-Hibbert 93e86ab
refactor: test and repair getOpenQuestions
Chris-Hibbert 319fd73
chore: more cleanup
Chris-Hibbert 8c87532
chore: review suggestions
Chris-Hibbert 44e223f
refactor: await all the promises, not just the last in a chain
Chris-Hibbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to take it or leave it:
{}
should work now that we don't treat empty objects as presences, but I thinkundefined
is clearerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the curly braces. It's easier for me to recognize those as empty terms.