@@ -3,16 +3,22 @@ pragma solidity ^0.8.0;
3
3
4
4
import "hardhat/console.sol " ;
5
5
6
-
6
+ // TODO: Ensure options count from one
7
7
contract Voting {
8
8
// structs
9
+ struct VoteOptions {
10
+ string name;
11
+ }
9
12
struct Poll {
10
13
address owner;
11
14
string name;
12
15
string description;
13
16
uint start_time;
14
17
uint end_time;
15
18
uint fee;
19
+ uint option_count; // Number of options
20
+ mapping (uint => VoteOptions ) options; // mapping of index+1(option_id) to options (should start from 1)
21
+ mapping (address => uint ) votes; // mapping of address to option_id (should start from 1)
16
22
}
17
23
18
24
// Variables
@@ -35,14 +41,27 @@ contract Voting {
35
41
}
36
42
37
43
// Public Functions
38
- function createPoll () public {
44
+ function createPoll (string memory name , string memory description , uint start_time , uint end_time , uint fee ) public {
39
45
// check end time after start time
40
- emit createPollEvt (polls_created, msg .sender , "Default Name " , "Default Description " , 0 , 100 , 0 );
41
- polls[polls_created] = Poll (msg .sender , "Default Name " , "Default Description " , 0 , 100 , 0 );
46
+ // Check more than one option
47
+ emit createPollEvt (polls_created, msg .sender , name, description, start_time, end_time, fee);
48
+ Poll storage newPoll = polls[polls_created];
49
+ newPoll.owner = msg .sender ;
50
+ newPoll.name = name;
51
+ newPoll.description = description;
52
+ newPoll.start_time = start_time;
53
+ newPoll.end_time = end_time;
54
+ newPoll.fee = fee;
55
+
56
+ // Increment poll id
42
57
polls_created++ ;
43
58
console.log ("New pollId is '%s' " , polls_created);
44
59
}
45
60
61
+ function getUser () public view returns (string memory username ) {
62
+ return address_to_username[msg .sender ];
63
+ }
64
+
46
65
function createUser (string memory username ) public {
47
66
// Make checks to ensure user name is not empty && not taken && address not registered
48
67
address_to_username[msg .sender ] = username;
1 commit comments
vercel[bot] commentedon Aug 6, 2021
Successfully deployed to the following URLs: