Skip to content

Commit

Permalink
fix: tally result id collision
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Jan 10, 2025
1 parent f0ad8f3 commit 6650a4b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/interface/src/server/api/routers/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export async function calculateMaciResults(
}

const results = tallyData.results.reduce((acc, tally, index) => {
const project = projects[index];
const [, id] = tally.id.split("-");
const projectIndex = id ? Number(id) : index;
const project = projects[projectIndex];
if (project) {
acc.set(project.id, { votes: Number(tally.result), voters: 0 });
}
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
```

3. Run `pnpm run build`. You can use env variables `NETWORK` and `VERSION` to switch config files.
4. Run `graph auth --studio {key}`. You can find the key in subgraph studio dashboard.
5. Run `pnpm run deploy` to deploy subgraph
4. Run `graph auth --studio {key}`. You can find the key in subgraph studio dashboard; if you're using alchemy graph, skip this step.
5. Run `pnpm run deploy-graph` to deploy subgraph; if you're using alchemy graph, run `pnpm run deploy-alchemy --deploy-key {key}` instead.
3 changes: 2 additions & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"generate:schema": "cp ./schemas/schema.${VERSION:-v1}.graphql schema.graphql",
"prebuild": "pnpm codegen",
"build": "graph build",
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ maci-subgraph",
"deploy-graph": "graph deploy --node https://api.studio.thegraph.com/deploy/ maci-subgraph",
"deploy-alchemy": "graph deploy maci-subgraph --node https://subgraphs.alchemy.com/api/subgraphs/deploy/ --ipfs https://ipfs.satsuma.xyz",
"create-local": "graph create --node http://localhost:8020/ maci-subgraph",
"remove-local": "graph remove --node http://localhost:8020/ maci-subgraph",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 maci-subgraph --network localhost",
Expand Down
6 changes: 4 additions & 2 deletions packages/subgraph/src/utils/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ export const createOrLoadClaim = (index: GraphBN, recipient: Bytes, amount: Grap
};

export const createOrLoadTallyResult = (index: GraphBN, result: GraphBN, tally: Bytes): TallyResult => {
let tallyResult = TallyResult.load(index.toString());
// Create composite key by combining tally address and index
const compositeId = `${tally.toHexString()}-${index.toString()}`;
let tallyResult = TallyResult.load(compositeId);

if (!tallyResult) {
tallyResult = new TallyResult(index.toString());
tallyResult = new TallyResult(compositeId);
tallyResult.result = result;
tallyResult.tally = tally;
tallyResult.save();
Expand Down

0 comments on commit 6650a4b

Please sign in to comment.