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.
added poll manager contract for storing the poll metadata
- Loading branch information
1 parent
a3f7cbc
commit 5ad74e3
Showing
4 changed files
with
506 additions
and
275 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ cache-zk | |
deployments/localhost | ||
|
||
zkeys | ||
coordinatorKeyPair.json |
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,102 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.10; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "./maci-contracts/MACI.sol"; | ||
import { Params } from "./maci-contracts/utilities/Params.sol"; | ||
import { DomainObjs } from "./maci-contracts/utilities/DomainObjs.sol"; | ||
|
||
contract PollManager is Ownable, Params, DomainObjs { | ||
struct PollContracts { | ||
address poll; | ||
address messageProcessor; | ||
address tally; | ||
address subsidy; | ||
} | ||
|
||
struct PollData { | ||
string name; | ||
bytes options; | ||
string ipfsHash; | ||
address creator; | ||
PollContracts pollContracts; | ||
uint256 endTime; | ||
uint256 numOfOptions; | ||
} | ||
|
||
uint256 public fees; | ||
|
||
mapping(uint256 => PollData) public polls; | ||
uint256 public totalPolls; | ||
uint256 public duration; | ||
|
||
MACI public maci; | ||
|
||
TreeDepths public treeDepths; | ||
PubKey public coordinatorPubKey; | ||
address public verifier; | ||
address public vkRegistry; | ||
bool public useSubsidy; | ||
|
||
constructor(MACI _maci) { | ||
fees = 0.01 ether; | ||
maci = _maci; | ||
duration = 600; | ||
} | ||
|
||
function setFees(uint256 _fees) public onlyOwner { | ||
fees = _fees; | ||
} | ||
|
||
function setNewVotingTime(uint256 _duration) public onlyOwner { | ||
duration = _duration; | ||
} | ||
|
||
function setConfig( | ||
TreeDepths memory _treeDepths, | ||
PubKey memory _coordinatorPubKey, | ||
address _verifier, | ||
address _vkRegistry, | ||
bool _useSubsidy | ||
) public onlyOwner { | ||
treeDepths = _treeDepths; | ||
coordinatorPubKey = _coordinatorPubKey; | ||
verifier = _verifier; | ||
vkRegistry = _vkRegistry; | ||
useSubsidy = _useSubsidy; | ||
} | ||
|
||
function createPoll( | ||
string calldata _name, | ||
bytes calldata _options, | ||
string calldata _ipfsHash, | ||
uint256 numOfOptions | ||
) public payable onlyOwner { | ||
require(msg.value == fees, "incorrect fees sent"); | ||
|
||
MACI.PollContracts memory c = maci.deployPoll( | ||
duration, | ||
treeDepths, | ||
coordinatorPubKey, | ||
verifier, | ||
vkRegistry, | ||
useSubsidy | ||
); | ||
|
||
// create poll | ||
polls[++totalPolls] = PollData({ | ||
name: _name, | ||
options: _options, | ||
ipfsHash: _ipfsHash, | ||
creator: msg.sender, | ||
endTime: block.timestamp + duration, | ||
pollContracts: PollContracts({ | ||
poll: c.poll, | ||
messageProcessor: c.messageProcessor, | ||
tally: c.tally, | ||
subsidy: c.subsidy | ||
}), | ||
numOfOptions: numOfOptions | ||
}); | ||
} | ||
} |
Oops, something went wrong.