Skip to content
Snippets Groups Projects
Commit 7f4b9e20 authored by Miguel Braidot's avatar Miguel Braidot
Browse files

Haciendo dinámica la lectura de proposals

parent 0b1ec723
No related branches found
No related tags found
No related merge requests found
...@@ -101,7 +101,7 @@ contract Ballot ...@@ -101,7 +101,7 @@ contract Ballot
{ {
// May only be called by chairman. // May only be called by chairman.
require( msg.sender == ballotChairman ); require( msg.sender == ballotChairman );
require( ballotVoteBefore < now ); require( ballotVoteBefore > now );
uint len = voters.length; uint len = voters.length;
uint i = 0; uint i = 0;
while ( i < len ) while ( i < len )
...@@ -147,8 +147,8 @@ contract Ballot ...@@ -147,8 +147,8 @@ contract Ballot
public public
{ {
require( proposal < proposalList.length ); require( proposal < proposalList.length );
require( ballotVoteStarts >= now ); require( ballotVoteStarts <= now );
require( ballotVoteBefore < now ); require( ballotVoteBefore > now );
int idx = getVoterIdx( msg.sender ); int idx = getVoterIdx( msg.sender );
require( idx > -1 ); require( idx > -1 );
uint uidx = uint( idx ); uint uidx = uint( idx );
......
...@@ -2,292 +2,306 @@ ...@@ -2,292 +2,306 @@
var abiBallot = [ var abiBallot = [
{ {
"name": "vote", "constant": false,
"type": "function", "inputs": [
"payable": false, {
"constant": false, "name": "voters",
"stateMutability": "nonpayable", "type": "address[]"
"inputs": [ }
{ ],
"name": "proposal", "name": "giveRightToVote",
"type": "uint256" "outputs": [],
} "payable": false,
], "stateMutability": "nonpayable",
"outputs": [] "type": "function"
}, },
{ {
"name": "ballotPercentOfRegisteredVotersReqToBeValid", "constant": false,
"type": "function", "inputs": [],
"payable": false, "name": "uncreate",
"constant": true, "outputs": [],
"inputs": [], "payable": false,
"stateMutability": "view", "stateMutability": "nonpayable",
"outputs": [ "type": "function"
{ },
"name": "", {
"type": "uint256" "constant": false,
} "inputs": [
] {
}, "name": "proposal",
{ "type": "uint256"
"name": "voterMap", }
"type": "function", ],
"payable": false, "name": "vote",
"constant": true, "outputs": [],
"stateMutability": "view", "payable": false,
"inputs": [ "stateMutability": "nonpayable",
{ "type": "function"
"name": "", },
"type": "address" {
} "inputs": [
], {
"outputs": [ "name": "title",
{ "type": "string"
"name": "", },
"type": "uint256" {
} "name": "voteStarts",
] "type": "uint256"
}, },
{ {
"name": "getVoterIdx", "name": "voteBefore",
"type": "function", "type": "uint256"
"payable": false, },
"constant": true, {
"stateMutability": "view", "name": "percentOfRegisteredVotersReqToBeValid",
"inputs": [ "type": "uint256"
{ },
"name": "voter", {
"type": "address" "name": "percentOfVotesCastToWin",
} "type": "uint256"
], },
"outputs": [ {
{ "name": "countNonvotesAsBlanks",
"name": "", "type": "bool"
"type": "int256" },
} {
] "name": "maxVotesPerVoter",
}, "type": "uint256"
{ },
"name": "uncreate", {
"type": "function", "name": "maxVotesPerProposal",
"payable": false, "type": "uint256"
"constant": false, },
"stateMutability": "nonpayable", {
"inputs": [], "name": "proposalNames",
"outputs": [] "type": "bytes32[]"
}, }
{ ],
"name": "voterList", "payable": false,
"type": "function", "stateMutability": "nonpayable",
"payable": false, "type": "constructor"
"constant": true, },
"stateMutability": "view", {
"inputs": [ "constant": true,
{ "inputs": [],
"name": "", "name": "ballotChairman",
"type": "uint256" "outputs": [
} {
], "name": "",
"outputs": [ "type": "address"
{ }
"name": "voter", ],
"type": "address" "payable": false,
}, "stateMutability": "view",
{ "type": "function"
"name": "votesLeft", },
"type": "uint256" {
} "constant": true,
] "inputs": [],
}, "name": "ballotCountNonvotesAsBlanks",
{ "outputs": [
"name": "ballotCountNonvotesAsBlanks", {
"type": "function", "name": "",
"payable": false, "type": "bool"
"constant": true, }
"stateMutability": "view", ],
"inputs": [], "payable": false,
"outputs": [ "stateMutability": "view",
{ "type": "function"
"name": "", },
"type": "bool" {
} "constant": true,
] "inputs": [],
}, "name": "ballotMaxVotesPerProposal",
{ "outputs": [
"name": "ballotVoteBefore", {
"type": "function", "name": "",
"payable": false, "type": "uint256"
"constant": true, }
"stateMutability": "view", ],
"inputs": [], "payable": false,
"outputs": [ "stateMutability": "view",
{ "type": "function"
"name": "", },
"type": "uint256" {
} "constant": true,
] "inputs": [],
}, "name": "ballotMaxVotesPerVoter",
{ "outputs": [
"constant": false, {
"inputs": [ "name": "",
{ "type": "uint256"
"name": "voters", }
"type": "address[]" ],
} "payable": false,
], "stateMutability": "view",
"name": "giveRightToVote", "type": "function"
"outputs": [], },
"payable": false, {
"stateMutability": "nonpayable", "constant": true,
"type": "function" "inputs": [],
}, "name": "ballotPercentOfRegisteredVotersReqToBeValid",
{ "outputs": [
"constant": true, {
"inputs": [], "name": "",
"name": "ballotVoteStarts", "type": "uint256"
"outputs": [ }
{ ],
"name": "", "payable": false,
"type": "uint256" "stateMutability": "view",
} "type": "function"
], },
"payable": false, {
"stateMutability": "view", "constant": true,
"type": "function" "inputs": [],
}, "name": "ballotPercentOfVotesCastToWin",
{ "outputs": [
"constant": true, {
"inputs": [], "name": "",
"name": "ballotMaxVotesPerProposal", "type": "uint256"
"outputs": [ }
{ ],
"name": "", "payable": false,
"type": "uint256" "stateMutability": "view",
} "type": "function"
], },
"payable": false, {
"stateMutability": "view", "constant": true,
"type": "function" "inputs": [],
}, "name": "ballotTitle",
{ "outputs": [
"constant": true, {
"inputs": [], "name": "",
"name": "ballotMaxVotesPerVoter", "type": "string"
"outputs": [ }
{ ],
"name": "", "payable": false,
"type": "uint256" "stateMutability": "view",
} "type": "function"
], },
"payable": false, {
"stateMutability": "view", "constant": true,
"type": "function" "inputs": [],
}, "name": "ballotVoteBefore",
{ "outputs": [
"constant": true, {
"inputs": [], "name": "",
"name": "ballotTitle", "type": "uint256"
"outputs": [ }
{ ],
"name": "", "payable": false,
"type": "string" "stateMutability": "view",
} "type": "function"
], },
"payable": false, {
"stateMutability": "view", "constant": true,
"type": "function" "inputs": [],
}, "name": "ballotVoteStarts",
{ "outputs": [
"constant": true, {
"inputs": [ "name": "",
{ "type": "uint256"
"name": "", }
"type": "uint256" ],
} "payable": false,
], "stateMutability": "view",
"name": "proposalList", "type": "function"
"outputs": [ },
{ {
"name": "", "constant": true,
"type": "bytes32" "inputs": [
} {
], "name": "voter",
"payable": false, "type": "address"
"stateMutability": "view", }
"type": "function" ],
}, "name": "getVoterIdx",
{ "outputs": [
"constant": true, {
"inputs": [], "name": "",
"name": "ballotPercentOfVotesCastToWin", "type": "int256"
"outputs": [ }
{ ],
"name": "", "payable": false,
"type": "uint256" "stateMutability": "view",
} "type": "function"
], },
"payable": false, {
"stateMutability": "view", "constant": true,
"type": "function" "inputs": [
}, {
{ "name": "",
"constant": true, "type": "uint256"
"inputs": [], }
"name": "ballotChairman", ],
"outputs": [ "name": "proposalList",
{ "outputs": [
"name": "", {
"type": "address" "name": "",
} "type": "bytes32"
], }
"payable": false, ],
"stateMutability": "view", "payable": false,
"type": "function" "stateMutability": "view",
}, "type": "function"
{ },
"inputs": [ {
{ "constant": true,
"name": "title", "inputs": [],
"type": "string" "name": "proposalListLength",
}, "outputs": [
{ {
"name": "voteStarts", "name": "",
"type": "uint256" "type": "uint256"
}, }
{ ],
"name": "voteBefore", "payable": false,
"type": "uint256" "stateMutability": "view",
}, "type": "function"
{ },
"name": "percentOfRegisteredVotersReqToBeValid", {
"type": "uint256" "constant": true,
}, "inputs": [
{ {
"name": "percentOfVotesCastToWin", "name": "",
"type": "uint256" "type": "uint256"
}, }
{ ],
"name": "countNonvotesAsBlanks", "name": "voterList",
"type": "bool" "outputs": [
}, {
{ "name": "voter",
"name": "maxVotesPerVoter", "type": "address"
"type": "uint256" },
}, {
{ "name": "votesLeft",
"name": "maxVotesPerProposal", "type": "uint256"
"type": "uint256" }
}, ],
{ "payable": false,
"name": "proposalNames", "stateMutability": "view",
"type": "bytes32[]" "type": "function"
} },
], {
"payable": false, "constant": true,
"stateMutability": "nonpayable", "inputs": [
"type": "constructor" {
} "name": "",
"type": "address"
}
],
"name": "voterMap",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]; ];
// $ solc --abi src/Ballot.sol | tail -1 | jq // $ solc --abi src/Ballot.sol | tail -1 | jq
......
...@@ -6,6 +6,7 @@ var netid; ...@@ -6,6 +6,7 @@ var netid;
var netname; var netname;
var blocknumber = -2; var blocknumber = -2;
var nowblock; var nowblock;
var proposalLength = 0;
var netnames = { var netnames = {
"1": 'Ethereum mainnet', "1": 'Ethereum mainnet',
...@@ -20,9 +21,9 @@ var netnames = { ...@@ -20,9 +21,9 @@ var netnames = {
var mainaddr = { var mainaddr = {
'5445': '0xe5bf7c3e8aa529e42fbd99428137b68db75d85f9', '5445': '0xe5bf7c3e8aa529e42fbd99428137b68db75d85f9',
'47525974938': '0xe3e08934b6fa0b68972c08e0f545cee31ed039c6', '47525974938': '0xe3e08934b6fa0b68972c08e0f545cee31ed039c6',
'5777': '0x68bc96dd287Fd7AdAD480b487B16ac5AE7D59B3A' '5777': '0xeAf032eaC758646E167916028F3abAbF0f33ae5d'
}; };
var ballot_keccak3 = '0xfd956d3ac857d157367d1a1bfe0e0fddee572dd24aebe34df32c430543377bb0'; var ballot_keccak3 = '0x20ab18e35a65929a015b8faf468469a21d2268ffce74a8888a12eb6b9d10bf43';
var contract_event; var contract_event;
window.addEventListener('load', page_loaded); window.addEventListener('load', page_loaded);
...@@ -478,9 +479,10 @@ async function ver_votacion2(addr, code) { ...@@ -478,9 +479,10 @@ async function ver_votacion2(addr, code) {
// Getting the title // Getting the title
contract.ballotTitle.call({ gas: 2111000 }, getBallotTitle); contract.ballotTitle.call({ gas: 2111000 }, getBallotTitle);
// Getting the proposal list // Getting the proposal list
// @TODO: get the proposal mapping's length let proposalLength = await getProposalListLength(contract);
contract.proposalList.call(0, { gas: 2111000 }, getProposalList); for(var i=0;i<proposalLength;i++){
contract.proposalList.call(1, { gas: 2111000 }, getProposalList); contract.proposalList.call(i, { gas: 2111000 }, getProposalList);
}
// Getting the ballot dates // Getting the ballot dates
contract.ballotVoteStarts.call({ gas: 2111000 }, getBallotVoteStarts); contract.ballotVoteStarts.call({ gas: 2111000 }, getBallotVoteStarts);
contract.ballotVoteBefore.call({ gas: 2111000 }, getBallotVoteBefore); contract.ballotVoteBefore.call({ gas: 2111000 }, getBallotVoteBefore);
...@@ -497,6 +499,18 @@ async function ver_votacion2(addr, code) { ...@@ -497,6 +499,18 @@ async function ver_votacion2(addr, code) {
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// UTILS for ballot form creation // UTILS for ballot form creation
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
function getProposalListLength (contract) {
return new Promise (function (resolve, reject) {
contract.proposalListLength.call({ gas: 2111000 }, function (error, result) {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
}
async function getBallotVoteStarts(err, rcpt){ async function getBallotVoteStarts(err, rcpt){
if(err){ if(err){
alertar(err); alertar(err);
......
...@@ -326,6 +326,9 @@ ...@@ -326,6 +326,9 @@
scrollTop: 0 scrollTop: 0
}, 200); }, 200);
$('#errorForm').focus(); $('#errorForm').focus();
$("#voterow :input").attr("readonly", false);
$("#voterow :input").attr("disabled", false);
$("#voterow .btn").show();
} }
}, },
submitHandler: function (form) { submitHandler: function (form) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment