-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sparsh Kesari <[email protected]>
- Loading branch information
1 parent
1388773
commit 4280138
Showing
6 changed files
with
20,656 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
Oops, something went wrong.