generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af70db4
commit c70fbaa
Showing
27 changed files
with
6,905 additions
and
98 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 |
---|---|---|
@@ -1,7 +1,56 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { coordinator } from "~~/utils/coordinator"; | ||
"use server"; | ||
|
||
export const POST = async (req: NextRequest, { params: { id } }: { params: { id: string } }) => { | ||
coordinator.closePoll(parseInt(id)); | ||
return NextResponse.json({ message: "Hello, World!" }); | ||
}; | ||
import { NextResponse } from "next/server"; | ||
|
||
// import { execSync } from "child_process"; | ||
// import fs from "fs"; | ||
// import { pollManagerContract } from "~~/constants"; | ||
// import { mergeMessages } from "~~/utils/mergeMessages"; | ||
// import { mergeSignups } from "~~/utils/mergeSignups"; | ||
|
||
export async function POST(req: Request) { | ||
let pollId: string; | ||
try { | ||
pollId = (await req.json()).pollId; | ||
} catch (err) { | ||
return NextResponse.json({ error: "invalid body" }, { status: 409 }); | ||
} | ||
|
||
if (!pollId) { | ||
return NextResponse.json({ error: "invalid body" }, { status: 409 }); | ||
} | ||
|
||
// try { | ||
// const poll = await pollManagerContract.read.fetchPoll([BigInt(pollId)]); | ||
|
||
// await mergeSignups({ pollContractAddress: poll.pollContracts.poll }); | ||
// await mergeMessages({ pollContractAddress: poll.pollContracts.poll }); | ||
|
||
// const cliDirectory = "/Users/yash/Development/buidlguidl/maci/cli"; | ||
// const dataFile = `${cliDirectory}/tally-${poll.maciPollId.toString()}.json`; | ||
// execSync( | ||
// `node ${cliDirectory}/build/ts/index.js genProofs \ | ||
// --privkey ${process.env.COORDINATOR_PRIVATE_KEY} \ | ||
// --poll-id ${poll.maciPollId.toString()} \ | ||
// --process-zkey ${cliDirectory}/zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey \ | ||
// --tally-zkey ${cliDirectory}/zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey \ | ||
// --tally-file ${dataFile} \ | ||
// --output proofs1/ \ | ||
// -tw ${cliDirectory}/zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test_js/TallyVotes_10-1-2_test.wasm \ | ||
// -pw ${cliDirectory}/zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test_js/ProcessMessages_10-2-1-2_test.wasm \ | ||
// -w true`, | ||
// { encoding: "utf-8" }, | ||
// ); // the default is 'buffer' | ||
|
||
// const data = JSON.parse(fs.readFileSync(dataFile).toString("utf-8")); | ||
|
||
// const votesSerialized = JSON.stringify(data.results.tally.slice(0, 10).map((v: any) => (v ? parseInt(v) || 0 : 0))); | ||
|
||
// console.log(votesSerialized); | ||
// } catch (err) { | ||
// console.log(err); | ||
// return NextResponse.json({ error: "something went wrong" }, { status: 500 }); | ||
// } | ||
|
||
return NextResponse.json({ message: "finalized the poll successfully" }); | ||
} |
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,36 @@ | ||
"use server"; | ||
|
||
import deployedContracts from "./contracts/deployedContracts"; | ||
import scaffoldConfig from "./scaffold.config"; | ||
import { createPublicClient, createWalletClient, getContract, http } from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
|
||
export const chain = scaffoldConfig.targetNetworks[0]; | ||
|
||
export const publicClient = createPublicClient({ chain, transport: http() }); | ||
|
||
console.log(process.env.SERVER_PRIVATE_KEY as `0x${string}`); | ||
|
||
export const serverAccount = privateKeyToAccount(process.env.SERVER_PRIVATE_KEY as `0x${string}`); | ||
export const serverWalletClient = createWalletClient({ | ||
chain: chain, | ||
transport: http(), | ||
key: process.env.SERVER_PRIVATE_KEY, | ||
account: serverAccount, | ||
}); | ||
|
||
export const pollManagerContract = getContract({ | ||
abi: deployedContracts[chain.id].PollManager.abi, | ||
address: deployedContracts[chain.id].PollManager.address, | ||
publicClient: publicClient, | ||
walletClient: serverWalletClient, | ||
}); | ||
|
||
export const maciContract = getContract({ | ||
abi: deployedContracts[chain.id].MACI.abi, | ||
address: deployedContracts[chain.id].MACI.address, | ||
publicClient: publicClient, | ||
walletClient: serverWalletClient, | ||
}); | ||
|
||
export const deploymentBlock = BigInt(deployedContracts[chain.id].MACI.deploymentBlockNumber); |
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
Oops, something went wrong.