-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
9,695 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,3 @@ | ||
node_modules/ | ||
.vscode/ | ||
build/ |
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,17 @@ | ||
# Boilerplate with Truffle and webpack for dApps built on Ethereum | ||
|
||
This boilerplate was made for this [blog post](https://medium.freecodecamp.org/developing-an-ethereum-decentralized-voting-application-a99de24992d9). | ||
### Dependencies: | ||
- [Nodejs 5.0+](https://nodejs.org/en/) | ||
- [Truffle](https://github.com/trufflesuite/truffle) | ||
- [Ganache](http://truffleframework.com/ganache/) | ||
|
||
## Setup | ||
``` | ||
npm install -g truffle | ||
git clone https://github.com/tko22/truffle-webpack-boilerplate.git | ||
cd truffle-webpack-boilerplate | ||
npm install | ||
npm run dev | ||
``` | ||
|
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,23 @@ | ||
pragma solidity ^0.4.2; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function Migrations() { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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,72 @@ | ||
pragma solidity ^0.4.18; | ||
// written for Solidity version 0.4.18 and above that doesnt break functionality | ||
|
||
contract Voting { | ||
event AddedCandidate(uint candidateID); | ||
|
||
// describes a Voter, which has an id and the ID of the candidate they voted for | ||
struct Voter { | ||
bytes32 uid; // bytes32 type are basically strings | ||
uint candidateIDVote; | ||
} | ||
// describes a Candidate | ||
struct Candidate { | ||
bytes32 name; | ||
bytes32 party; | ||
bool doesExist; | ||
} | ||
|
||
// These state variables are used keep track of the number of Candidates/Voters and used to as a way to index them | ||
uint numCandidates = 0; // declares a state variable - number Of Candidates | ||
uint numVoters; | ||
|
||
|
||
// Think of these as a hash table | ||
mapping (uint => Candidate) candidates; | ||
mapping (uint => Voter) voters; | ||
mapping (bytes32 => bool) public voted; | ||
|
||
constructor() public { | ||
addCandidate("Sandesh Chatarmal","BJP"); | ||
addCandidate("Ajay Khaple","Congress"); | ||
addCandidate("Jaydeep Patil","Shivsena"); | ||
} | ||
function addCandidate(bytes32 name, bytes32 party) public { | ||
uint candidateID = numCandidates++; | ||
// Create new Candidate Struct with name and saves it to storage. | ||
candidates[candidateID] = Candidate(name,party,true); | ||
AddedCandidate(candidateID); | ||
} | ||
|
||
function vote(bytes32 uid, uint candidateID) public { | ||
|
||
if (candidates[candidateID].doesExist == true) { | ||
uint voterID = numVoters++; //voterID is the return variable | ||
voters[voterID] = Voter(uid,candidateID); | ||
voted[uid] = true; | ||
} | ||
} | ||
|
||
|
||
// finds the total amount of votes for a specific candidate by looping through voters | ||
function totalVotes(uint candidateID) view public returns (uint) { | ||
uint numOfVotes = 0; // we will return this | ||
for (uint i = 0; i < numVoters; i++) { | ||
if (voters[i].candidateIDVote == candidateID) { | ||
numOfVotes++; | ||
} | ||
} | ||
return numOfVotes; | ||
} | ||
|
||
function getNumOfCandidates() public view returns(uint) { | ||
return numCandidates; | ||
} | ||
|
||
function getNumOfVoters() public view returns(uint) { | ||
return numVoters; | ||
} | ||
function getCandidate(uint candidateID) public view returns (uint,bytes32, bytes32) { | ||
return (candidateID,candidates[candidateID].name,candidates[candidateID].party); | ||
} | ||
} |
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 @@ | ||
var Migrations = artifacts.require("./Migrations.sol") | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Migrations) | ||
} |
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 @@ | ||
var Voting = artifacts.require("Voting") | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Voting).then(()=>console.warn(Voting.address)).then(()=>Voting.deployed()).then(_instance => console.log(_instance.address)) | ||
} |
Oops, something went wrong.