Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions IP_LP3_Blockchain_Riya_Gupta_984/bs-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"server": {
"baseDir": ["./src", "./build/contracts"]
}
}
2,632 changes: 2,632 additions & 0 deletions IP_LP3_Blockchain_Riya_Gupta_984/build/contracts/Election.json

Large diffs are not rendered by default.

906 changes: 906 additions & 0 deletions IP_LP3_Blockchain_Riya_Gupta_984/build/contracts/Migrations.json

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions IP_LP3_Blockchain_Riya_Gupta_984/contracts/Election.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
pragma solidity ^0.5.16;

contract Election {
// Model a candidate
struct Candidate {
uint id;
string name;
uint voteCount;
}

mapping(address => bool) public voters;
// Store Candidates
// Fetch Candidate
mapping(uint => Candidate) public candidates;
// Store Candidates Count
uint public candidatesCount;

event votedEvent (
uint indexed _candidateId
);

constructor() public {
addCandidate(" Candidate 1");
addCandidate(" Candidate 2");
}

function addCandidate (string memory _name) private {
candidatesCount ++;
candidates[candidatesCount] = Candidate(candidatesCount, _name, 0);
}

function vote (uint _candidateId) public {
// require that they haven't voted before
require(!voters[msg.sender]);

// require a valid candidate
require(_candidateId > 0 && _candidateId <= candidatesCount);

// record that voter has voted
voters[msg.sender] = true;

// update candidate vote Count
candidates[_candidateId].voteCount ++;

// trigger voted event
emit votedEvent(_candidateId);
}
}
18 changes: 18 additions & 0 deletions IP_LP3_Blockchain_Riya_Gupta_984/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pragma solidity >=0.4.21 <0.7.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

modifier restricted() {
if (msg.sender == owner) _;
}

constructor() public {
owner = msg.sender;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}
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);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Election = artifacts.require("./Election.sol");

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