Skip to content

Commit

Permalink
fix: decrypting v1 vote errors (#265)
Browse files Browse the repository at this point in the history
Signed-off-by: david <[email protected]>
  • Loading branch information
daywiss authored May 17, 2023
1 parent 3b8b3ad commit 7c59fc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
25 changes: 16 additions & 9 deletions hooks/queries/votes/useDecryptedVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,25 @@ async function decryptVotes(
for await (const [uniqueKey, encryptedVote] of Object.entries(
encryptedVotes
)) {
let decryptedVote: DecryptedVoteT;
try {
let decryptedVote: DecryptedVoteT;

if (encryptedVote && privateKey) {
const decryptedVoteString = await decryptMessage(
privateKey,
encryptedVote
);
decryptedVote = JSON.parse(decryptedVoteString) as DecryptedVoteT;
if (encryptedVote && privateKey) {
const decryptedVoteString = await decryptMessage(
privateKey,
encryptedVote
);
decryptedVote = JSON.parse(decryptedVoteString) as DecryptedVoteT;

if (decryptedVote) {
decryptedVotes[uniqueKey] = decryptedVote;
if (decryptedVote) {
decryptedVotes[uniqueKey] = decryptedVote;
}
}
} catch (err) {
console.warn("Failed Decoding encrypted vote:", err, {
uniqueKey,
encryptedVote,
});
}
}

Expand Down
15 changes: 1 addition & 14 deletions web3/queries/votes/getEncryptedVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,16 @@ export async function getEncryptedVotes(
findRoundId?: number
) {
if (!address) return {};
const v1Filter = votingV1Contract.filters.EncryptedVote(address);
const v1Result = await votingV1Contract.queryFilter(v1Filter);

const v2Filter = votingContract.filters.EncryptedVote(address);
const v2Result = await votingContract.queryFilter(v2Filter);

const v1EventData = v1Result?.map(({ args }) => args);
const v2EventData = v2Result
?.map(({ args }) => args)
.filter(({ roundId }) => (findRoundId ? roundId === findRoundId : true));

const encryptedVotes: EncryptedVotesByKeyT = {};
// disable v1 events if a round id is specified, this means we are only looking for current rounds
if (findRoundId === undefined) {
v1EventData?.forEach(
({ encryptedVote, identifier, time, ancillaryData }) => {
const decodedIdentifier = decodeHexString(identifier);
encryptedVotes[
makeUniqueKeyForVote(decodedIdentifier, time, ancillaryData)
] = encryptedVote;
}
);
}

v2EventData?.forEach(({ encryptedVote, identifier, time, ancillaryData }) => {
const decodedIdentifier = decodeHexString(identifier);
encryptedVotes[
Expand Down

2 comments on commit 7c59fc1

@vercel
Copy link

@vercel vercel bot commented on 7c59fc1 May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 7c59fc1 May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.