Skip to content

Commit b306c41

Browse files
committedAug 6, 2021
smart contract updated
1 parent b918894 commit b306c41

File tree

4 files changed

+9903
-10800
lines changed

4 files changed

+9903
-10800
lines changed
 

‎contracts/Voting.sol

+23-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@ pragma solidity ^0.8.0;
33

44
import "hardhat/console.sol";
55

6-
6+
// TODO: Ensure options count from one
77
contract Voting {
88
// structs
9+
struct VoteOptions{
10+
string name;
11+
}
912
struct Poll {
1013
address owner;
1114
string name;
1215
string description;
1316
uint start_time;
1417
uint end_time;
1518
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)
1622
}
1723

1824
// Variables
@@ -35,14 +41,27 @@ contract Voting {
3541
}
3642

3743
// Public Functions
38-
function createPoll() public {
44+
function createPoll(string memory name, string memory description, uint start_time, uint end_time, uint fee) public {
3945
// 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
4257
polls_created++;
4358
console.log("New pollId is '%s'", polls_created);
4459
}
4560

61+
function getUser() public view returns(string memory username) {
62+
return address_to_username[msg.sender];
63+
}
64+
4665
function createUser(string memory username) public{
4766
// Make checks to ensure user name is not empty && not taken && address not registered
4867
address_to_username[msg.sender] = username;

‎next.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const withImages = require('next-images');
21
module.exports = {
32
reactStrictMode: true,
4-
withImages
5-
}
3+
};

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "voting-dapp",
2+
"name": "votechain",
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
@@ -14,7 +14,6 @@
1414
"axios": "^0.21.1",
1515
"ipfs-http-client": "^51.0.1",
1616
"next": "11.0.1",
17-
"next-images": "^1.8.1",
1817
"react": "17.0.2",
1918
"react-dom": "17.0.2",
2019
"react-feather": "^2.0.9",

‎yarn.lock

+9,878-10,791
Large diffs are not rendered by default.

1 commit comments

Comments
 (1)

vercel[bot] commented on Aug 6, 2021

@vercel[bot]
Please sign in to comment.