diff --git a/packages/hardhat/contracts/PollManager.sol b/packages/hardhat/contracts/PollManager.sol
index 6dbf923..b121c15 100644
--- a/packages/hardhat/contracts/PollManager.sol
+++ b/packages/hardhat/contracts/PollManager.sol
@@ -14,6 +14,7 @@ contract PollManager is Params, DomainObjs {
}
struct PollData {
+ uint256 id;
string name;
bytes encodedOptions;
string ipfsHash;
@@ -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;
@@ -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
);
@@ -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
);
}
diff --git a/packages/nextjs/abi/Poll.json b/packages/nextjs/abi/Poll.json
new file mode 100644
index 0000000..671177b
--- /dev/null
+++ b/packages/nextjs/abi/Poll.json
@@ -0,0 +1,966 @@
+[
+ {
+ "inputs": [
+ {
+ "internalType": "uint256",
+ "name": "_duration",
+ "type": "uint256"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "maxMessages",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "maxVoteOptions",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct Params.MaxValues",
+ "name": "_maxValues",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint8",
+ "name": "intStateTreeDepth",
+ "type": "uint8"
+ },
+ {
+ "internalType": "uint8",
+ "name": "messageTreeSubDepth",
+ "type": "uint8"
+ },
+ {
+ "internalType": "uint8",
+ "name": "messageTreeDepth",
+ "type": "uint8"
+ },
+ {
+ "internalType": "uint8",
+ "name": "voteOptionTreeDepth",
+ "type": "uint8"
+ }
+ ],
+ "internalType": "struct Params.TreeDepths",
+ "name": "_treeDepths",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.PubKey",
+ "name": "_coordinatorPubKey",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "contract IMACI",
+ "name": "maci",
+ "type": "address"
+ },
+ {
+ "internalType": "contract AccQueue",
+ "name": "messageAq",
+ "type": "address"
+ },
+ {
+ "internalType": "contract TopupCredit",
+ "name": "topupCredit",
+ "type": "address"
+ }
+ ],
+ "internalType": "struct Params.ExtContracts",
+ "name": "_extContracts",
+ "type": "tuple"
+ }
+ ],
+ "stateMutability": "payable",
+ "type": "constructor"
+ },
+ {
+ "inputs": [],
+ "name": "InvalidBatchLength",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "InvalidMessage",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "MaciPubKeyLargerThanSnarkFieldSize",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "PollAlreadyInit",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "StateAqAlreadyMerged",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "StateAqSubtreesNeedMerge",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "TooManyMessages",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "VotingPeriodNotOver",
+ "type": "error"
+ },
+ {
+ "inputs": [],
+ "name": "VotingPeriodOver",
+ "type": "error"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": false,
+ "internalType": "uint256",
+ "name": "_stateRoot",
+ "type": "uint256"
+ },
+ {
+ "indexed": false,
+ "internalType": "uint256",
+ "name": "_numSignups",
+ "type": "uint256"
+ }
+ ],
+ "name": "MergeMaciStateAq",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": false,
+ "internalType": "uint256",
+ "name": "_numSrQueueOps",
+ "type": "uint256"
+ }
+ ],
+ "name": "MergeMaciStateAqSubRoots",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": false,
+ "internalType": "uint256",
+ "name": "_messageRoot",
+ "type": "uint256"
+ }
+ ],
+ "name": "MergeMessageAq",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": false,
+ "internalType": "uint256",
+ "name": "_numSrQueueOps",
+ "type": "uint256"
+ }
+ ],
+ "name": "MergeMessageAqSubRoots",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "indexed": true,
+ "internalType": "address",
+ "name": "previousOwner",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "internalType": "address",
+ "name": "newOwner",
+ "type": "address"
+ }
+ ],
+ "name": "OwnershipTransferred",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256[10]",
+ "name": "data",
+ "type": "uint256[10]"
+ }
+ ],
+ "indexed": false,
+ "internalType": "struct DomainObjs.Message",
+ "name": "_message",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "indexed": false,
+ "internalType": "struct DomainObjs.PubKey",
+ "name": "_encPubKey",
+ "type": "tuple"
+ }
+ ],
+ "name": "PublishMessage",
+ "type": "event"
+ },
+ {
+ "anonymous": false,
+ "inputs": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256[10]",
+ "name": "data",
+ "type": "uint256[10]"
+ }
+ ],
+ "indexed": false,
+ "internalType": "struct DomainObjs.Message",
+ "name": "_message",
+ "type": "tuple"
+ }
+ ],
+ "name": "TopupMessage",
+ "type": "event"
+ },
+ {
+ "inputs": [],
+ "name": "MESSAGE_DATA_LENGTH",
+ "outputs": [
+ {
+ "internalType": "uint8",
+ "name": "",
+ "type": "uint8"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "coordinatorPubKey",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "coordinatorPubKeyHash",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "currentSbCommitment",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "extContracts",
+ "outputs": [
+ {
+ "internalType": "contract IMACI",
+ "name": "maci",
+ "type": "address"
+ },
+ {
+ "internalType": "contract AccQueue",
+ "name": "messageAq",
+ "type": "address"
+ },
+ {
+ "internalType": "contract TopupCredit",
+ "name": "topupCredit",
+ "type": "address"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "getDeployTimeAndDuration",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "pollDeployTime",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "pollDuration",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256[2]",
+ "name": "array",
+ "type": "uint256[2]"
+ }
+ ],
+ "name": "hash2",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "result",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256[3]",
+ "name": "array",
+ "type": "uint256[3]"
+ }
+ ],
+ "name": "hash3",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "result",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256[4]",
+ "name": "array",
+ "type": "uint256[4]"
+ }
+ ],
+ "name": "hash4",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "result",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256[5]",
+ "name": "array",
+ "type": "uint256[5]"
+ }
+ ],
+ "name": "hash5",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "result",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256",
+ "name": "left",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "right",
+ "type": "uint256"
+ }
+ ],
+ "name": "hashLeftRight",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "result",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256[10]",
+ "name": "data",
+ "type": "uint256[10]"
+ }
+ ],
+ "internalType": "struct DomainObjs.Message",
+ "name": "_message",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.PubKey",
+ "name": "_encPubKey",
+ "type": "tuple"
+ }
+ ],
+ "name": "hashMessageAndEncPubKey",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "msgHash",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.PubKey",
+ "name": "pubKey",
+ "type": "tuple"
+ },
+ {
+ "internalType": "uint256",
+ "name": "voiceCreditBalance",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "timestamp",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.StateLeaf",
+ "name": "_stateLeaf",
+ "type": "tuple"
+ }
+ ],
+ "name": "hashStateLeaf",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "ciphertext",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "init",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "maxValues",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "maxMessages",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "maxVoteOptions",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256",
+ "name": "_pollId",
+ "type": "uint256"
+ }
+ ],
+ "name": "mergeMaciStateAq",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256",
+ "name": "_numSrQueueOps",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "_pollId",
+ "type": "uint256"
+ }
+ ],
+ "name": "mergeMaciStateAqSubRoots",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "mergeMessageAq",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256",
+ "name": "_numSrQueueOps",
+ "type": "uint256"
+ }
+ ],
+ "name": "mergeMessageAqSubRoots",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "mergedStateRoot",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "numMessages",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "numSignUpsAndMessages",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "numSUps",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "numMsgs",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "numSignups",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "owner",
+ "outputs": [
+ {
+ "internalType": "address",
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256[2]",
+ "name": "dataToPad",
+ "type": "uint256[2]"
+ },
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ }
+ ],
+ "name": "padAndHashMessage",
+ "outputs": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256[10]",
+ "name": "data",
+ "type": "uint256[10]"
+ }
+ ],
+ "internalType": "struct DomainObjs.Message",
+ "name": "message",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.PubKey",
+ "name": "padKey",
+ "type": "tuple"
+ },
+ {
+ "internalType": "uint256",
+ "name": "msgHash",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256[10]",
+ "name": "data",
+ "type": "uint256[10]"
+ }
+ ],
+ "internalType": "struct DomainObjs.Message",
+ "name": "_message",
+ "type": "tuple"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.PubKey",
+ "name": "_encPubKey",
+ "type": "tuple"
+ }
+ ],
+ "name": "publishMessage",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "msgType",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256[10]",
+ "name": "data",
+ "type": "uint256[10]"
+ }
+ ],
+ "internalType": "struct DomainObjs.Message[]",
+ "name": "_messages",
+ "type": "tuple[]"
+ },
+ {
+ "components": [
+ {
+ "internalType": "uint256",
+ "name": "x",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "y",
+ "type": "uint256"
+ }
+ ],
+ "internalType": "struct DomainObjs.PubKey[]",
+ "name": "_encPubKeys",
+ "type": "tuple[]"
+ }
+ ],
+ "name": "publishMessageBatch",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "renounceOwnership",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256[]",
+ "name": "array",
+ "type": "uint256[]"
+ }
+ ],
+ "name": "sha256Hash",
+ "outputs": [
+ {
+ "internalType": "uint256",
+ "name": "result",
+ "type": "uint256"
+ }
+ ],
+ "stateMutability": "pure",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "stateAqMerged",
+ "outputs": [
+ {
+ "internalType": "bool",
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "uint256",
+ "name": "stateIndex",
+ "type": "uint256"
+ },
+ {
+ "internalType": "uint256",
+ "name": "amount",
+ "type": "uint256"
+ }
+ ],
+ "name": "topup",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ {
+ "internalType": "address",
+ "name": "newOwner",
+ "type": "address"
+ }
+ ],
+ "name": "transferOwnership",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [],
+ "name": "treeDepths",
+ "outputs": [
+ {
+ "internalType": "uint8",
+ "name": "intStateTreeDepth",
+ "type": "uint8"
+ },
+ {
+ "internalType": "uint8",
+ "name": "messageTreeSubDepth",
+ "type": "uint8"
+ },
+ {
+ "internalType": "uint8",
+ "name": "messageTreeDepth",
+ "type": "uint8"
+ },
+ {
+ "internalType": "uint8",
+ "name": "voteOptionTreeDepth",
+ "type": "uint8"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ }
+]
diff --git a/packages/nextjs/app/admin/page.tsx b/packages/nextjs/app/admin/page.tsx
index 4732447..dc7ebb5 100644
--- a/packages/nextjs/app/admin/page.tsx
+++ b/packages/nextjs/app/admin/page.tsx
@@ -59,7 +59,9 @@ export default function AdminPage() {
))}
-