Skip to content

Commit

Permalink
file base structure added
Browse files Browse the repository at this point in the history
Signed-off-by: Sparsh Kesari <[email protected]>
  • Loading branch information
SparshKesari committed Oct 11, 2021
1 parent 1388773 commit 4280138
Show file tree
Hide file tree
Showing 6 changed files with 20,656 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"env": {
"browser": true,
"es6": true,
"jquery": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"never"
]
}
}
19 changes: 19 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Migrations {
address public owner = msg.sender;
uint public last_completed_migration;

modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
111 changes: 111 additions & 0 deletions contracts/voting.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
pragma solidity 0.6.1;
pragma experimental ABIEncoderV2;

contract Electioncreation {
address[] public deployedBallots;

function startelec(
string[][] memory candidates,
string[][] memory party,
string[] memory district,
uint256 hour
) public {
for (uint256 i = 0; i < district.length; i++) {
Ballot newBallot = new Ballot(
candidates[i],
party[i],
district[i],
msg.sender,
hour
);
// a = newBallot.getAddress();
deployedBallots.push(address(newBallot));
}
}

function getsDeployedBallots() public view returns (address[] memory) {
return deployedBallots;
}
}

contract Ballot {
struct candidate {
string name;
string party;
uint256 voteCount;
uint256 creationDate;
uint256 expirationDate;
}

candidate[] public candidates;
address public manager;
string public votingDistrict;
mapping(address => bool) public voters;
modifier restricted() {
require(msg.sender == manager);
_;
}

constructor(
string[] memory candidateNames,
string[] memory candidateParty,
string memory district,
address creator,
uint256 amountofHours
) public {
manager = creator;
votingDistrict = district;
for (uint256 i = 0; i < candidateNames.length; i++) {
candidates.push(
candidate({
name: candidateNames[i],
party: candidateParty[i],
voteCount: 0,
creationDate: now,
expirationDate: now + amountofHours
})
);
}
//LogAddr(address(this));
}

function vote(uint256 index) public {
require(!voters[msg.sender]);
// if(now>candidates[index].expirationDate)
// {
// revert();
// }
candidates[index].voteCount += 1;
voters[msg.sender] = true;
}

function getCandidateName(uint256 index)
public
view
restricted
returns (string memory)
{
require(now > candidates[index].expirationDate);
return candidates[index].name;
}

function getCandidateParty(uint256 index)
public
view
restricted
returns (string memory)
{
require(now > candidates[index].expirationDate);
return candidates[index].party;
}

function getVoteCount(uint256 index)
public
view
restricted
returns (uint256)
{
//require(now>candidates[index].expirationDate);
return candidates[index].voteCount;
}
}
5 changes: 5 additions & 0 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Migrations = artifacts.require("Migrations");

module.exports = function (deployer) {
deployer.deploy(Migrations);
};
Loading

0 comments on commit 4280138

Please sign in to comment.