Skip to content

Commit

Permalink
added poll detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgo0018 committed Mar 26, 2024
1 parent d15f45d commit f666f11
Show file tree
Hide file tree
Showing 11 changed files with 1,345 additions and 60 deletions.
39 changes: 20 additions & 19 deletions packages/hardhat/contracts/PollManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract PollManager is Params, DomainObjs {
}

struct PollData {
uint256 id;
string name;
bytes encodedOptions;
string ipfsHash;
Expand All @@ -25,6 +26,7 @@ contract PollManager is Params, DomainObjs {
}

mapping(uint256 => PollData) internal polls;
mapping(address => uint256) public pollIdByAddress; // poll address => poll id
uint256 public totalPolls;

MACI public maci;
Expand All @@ -38,13 +40,10 @@ contract PollManager is Params, DomainObjs {
event PollCreated(
uint256 indexed pollId,
address indexed creator,
address indexed poll,
PollContracts pollContracts,
string name,
string[] options,
string ipfsHash,
address messageProcessor,
address tally,
address subsidy,
uint256 startTime,
uint256 endTime
);
Expand Down Expand Up @@ -97,37 +96,39 @@ contract PollManager is Params, DomainObjs {
// encode options to bytes for retrieval
bytes memory encodedOptions = abi.encode(_options);

uint256 startTime = block.timestamp;
uint256 endTime = block.timestamp + _duration;
uint256 pollId = ++totalPolls;

PollContracts memory pollContracts = PollContracts({
poll: c.poll,
messageProcessor: c.messageProcessor,
tally: c.tally,
subsidy: c.subsidy
});

pollIdByAddress[c.poll] = pollId;

// create poll
polls[++totalPolls] = PollData({
polls[pollId] = PollData({
id: pollId,
name: _name,
encodedOptions: encodedOptions,
numOfOptions: _options.length,
ipfsHash: _ipfsHash,
startTime: startTime,
startTime: block.timestamp,
endTime: endTime,
pollContracts: PollContracts({
poll: c.poll,
messageProcessor: c.messageProcessor,
tally: c.tally,
subsidy: c.subsidy
}),
pollContracts: pollContracts,
options: _options
});

emit PollCreated(
totalPolls,
pollId,
msg.sender,
c.poll,
pollContracts,
_name,
_options,
_ipfsHash,
c.messageProcessor,
c.tally,
c.subsidy,
startTime,
block.timestamp,
endTime
);
}
Expand Down
Loading

0 comments on commit f666f11

Please sign in to comment.