-
Notifications
You must be signed in to change notification settings - Fork 157
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
refactor: user sdk #2064
base: dev
Are you sure you want to change the base?
refactor: user sdk #2064
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
@ctrlc03 thanks, just few comments.
And is this PR supposed to move tests?
It will be nice to have tests for sdk.
"dependencies": { | ||
"@commander-js/extra-typings": "^12.1.0", | ||
"@nomicfoundation/hardhat-toolbox": "^5.0.0", | ||
"commander": "^12.1.0", |
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.
Why do you need these (commander
, @commander-js/extra-typings
) dependencies for sdk?
|
||
const userMaciPubKey = PubKey.deserialize(maciPubKey); | ||
|
||
if (!(await contractExists(signer.provider!, maciAddress))) { |
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.
Let's move await call to a constant
export /** | ||
* Parse the poll joining events from the Poll contract | ||
*/ | ||
const parsePollJoinEvents = async ({ |
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.
export /** | |
* Parse the poll joining events from the Poll contract | |
*/ | |
const parsePollJoinEvents = async ({ | |
/** | |
* Parse the poll joining events from the Poll contract | |
*/ | |
export const parsePollJoinEvents = async ({ |
export /** | ||
* Parse the signup events from the MACI contract | ||
*/ | ||
const parseSignupEvents = async ({ |
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.
export /** | |
* Parse the signup events from the MACI contract | |
*/ | |
const parseSignupEvents = async ({ | |
/** | |
* Parse the signup events from the MACI contract | |
*/ | |
export const parseSignupEvents = async ({ |
publicKey, | ||
}: IParseSignupEventsArgs): Promise<{ stateIndex?: string }> => { | ||
// 1000 blocks at a time | ||
for (let block = startBlock; block <= currentBlock; block += 1000) { |
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.
Let's use constant for blocks increment.
); | ||
if (!isValid) { | ||
failedIndices.push(i); | ||
} |
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.
); | |
if (!isValid) { | |
failedIndices.push(i); | |
} | |
); | |
if (!isValid) { | |
failedIndices.push(i); | |
} |
const useQv = tallyData.isQuadratic; | ||
const maciContractAddress = tallyData.maci; | ||
|
||
if (!(await contractExists(signer.provider!, maciContractAddress))) { |
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.
Let's move await call to a constant
!(await tallyContract.verifySpentVoiceCredits( | ||
tallyData.totalSpentVoiceCredits.spent, | ||
tallyData.totalSpentVoiceCredits.salt, | ||
newResultsCommitment, | ||
newPerVOSpentVoiceCreditsCommitment ?? 0n, | ||
)) |
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.
The same here with moving to constant
if (useQv) { | ||
if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) { | ||
throw new Error("Wrong number of vote options."); | ||
} | ||
// verify per vote option voice credits on-chain | ||
const failedSpentCredits = await verifyPerVOSpentVoiceCredits( | ||
tallyContract, | ||
tallyData, | ||
voteOptionTreeDepth, | ||
newSpentVoiceCreditsCommitment, | ||
newResultsCommitment, | ||
); | ||
|
||
if (failedSpentCredits.length > 0) { | ||
throw new Error( | ||
`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join( | ||
", ", | ||
)}`, | ||
); | ||
} | ||
} |
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.
if (useQv) { | |
if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) { | |
throw new Error("Wrong number of vote options."); | |
} | |
// verify per vote option voice credits on-chain | |
const failedSpentCredits = await verifyPerVOSpentVoiceCredits( | |
tallyContract, | |
tallyData, | |
voteOptionTreeDepth, | |
newSpentVoiceCreditsCommitment, | |
newResultsCommitment, | |
); | |
if (failedSpentCredits.length > 0) { | |
throw new Error( | |
`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join( | |
", ", | |
)}`, | |
); | |
} | |
} | |
if (!useQv) { | |
return true; | |
} | |
if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) { | |
throw new Error("Wrong number of vote options."); | |
} | |
// verify per vote option voice credits on-chain | |
const failedSpentCredits = await verifyPerVOSpentVoiceCredits( | |
tallyContract, | |
tallyData, | |
voteOptionTreeDepth, | |
newSpentVoiceCreditsCommitment, | |
newResultsCommitment, | |
); | |
if (failedSpentCredits.length > 0) { | |
throw new Error( | |
`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join( | |
", ", | |
)}`, | |
); | |
} |
Description
Refactor user functions from the SDK
Confirmation
Important
We do not accept minor grammatical fixes (e.g., correcting typos, rewording sentences) unless they significantly improve clarity in technical documentation. These contributions, while appreciated, are not a priority for merging. If there is a grammatical error feel free to message the team.