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
{
// May only be called by chairman.
require( msg.sender == ballotChairman );
require( ballotVoteBefore < now );
require( ballotVoteBefore > now );
uint len = voters.length;
uint i = 0;
while ( i < len )
......@@ -147,8 +147,8 @@ contract Ballot
public
{
require( proposal < proposalList.length );
require( ballotVoteStarts >= now );
require( ballotVoteBefore < now );
require( ballotVoteStarts <= now );
require( ballotVoteBefore > now );
int idx = getVoterIdx( msg.sender );
require( idx > -1 );
uint uidx = uint( idx );
......
......@@ -2,292 +2,306 @@
var abiBallot = [
{
"name": "vote",
"type": "function",
"payable": false,
"constant": false,
"stateMutability": "nonpayable",
"inputs": [
{
"name": "proposal",
"type": "uint256"
}
],
"outputs": []
},
{
"name": "ballotPercentOfRegisteredVotersReqToBeValid",
"type": "function",
"payable": false,
"constant": true,
"inputs": [],
"stateMutability": "view",
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"name": "voterMap",
"type": "function",
"payable": false,
"constant": true,
"stateMutability": "view",
"inputs": [
{
"name": "",
"type": "address"
}
],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"name": "getVoterIdx",
"type": "function",
"payable": false,
"constant": true,
"stateMutability": "view",
"inputs": [
{
"name": "voter",
"type": "address"
}
],
"outputs": [
{
"name": "",
"type": "int256"
}
]
},
{
"name": "uncreate",
"type": "function",
"payable": false,
"constant": false,
"stateMutability": "nonpayable",
"inputs": [],
"outputs": []
},
{
"name": "voterList",
"type": "function",
"payable": false,
"constant": true,
"stateMutability": "view",
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"outputs": [
{
"name": "voter",
"type": "address"
},
{
"name": "votesLeft",
"type": "uint256"
}
]
},
{
"name": "ballotCountNonvotesAsBlanks",
"type": "function",
"payable": false,
"constant": true,
"stateMutability": "view",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bool"
}
]
},
{
"name": "ballotVoteBefore",
"type": "function",
"payable": false,
"constant": true,
"stateMutability": "view",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"constant": false,
"inputs": [
{
"name": "voters",
"type": "address[]"
}
],
"name": "giveRightToVote",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotVoteStarts",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotMaxVotesPerProposal",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotMaxVotesPerVoter",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotTitle",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "proposalList",
"outputs": [
{
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotPercentOfVotesCastToWin",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotChairman",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "title",
"type": "string"
},
{
"name": "voteStarts",
"type": "uint256"
},
{
"name": "voteBefore",
"type": "uint256"
},
{
"name": "percentOfRegisteredVotersReqToBeValid",
"type": "uint256"
},
{
"name": "percentOfVotesCastToWin",
"type": "uint256"
},
{
"name": "countNonvotesAsBlanks",
"type": "bool"
},
{
"name": "maxVotesPerVoter",
"type": "uint256"
},
{
"name": "maxVotesPerProposal",
"type": "uint256"
},
{
"name": "proposalNames",
"type": "bytes32[]"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
{
"constant": false,
"inputs": [
{
"name": "voters",
"type": "address[]"
}
],
"name": "giveRightToVote",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "uncreate",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "proposal",
"type": "uint256"
}
],
"name": "vote",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "title",
"type": "string"
},
{
"name": "voteStarts",
"type": "uint256"
},
{
"name": "voteBefore",
"type": "uint256"
},
{
"name": "percentOfRegisteredVotersReqToBeValid",
"type": "uint256"
},
{
"name": "percentOfVotesCastToWin",
"type": "uint256"
},
{
"name": "countNonvotesAsBlanks",
"type": "bool"
},
{
"name": "maxVotesPerVoter",
"type": "uint256"
},
{
"name": "maxVotesPerProposal",
"type": "uint256"
},
{
"name": "proposalNames",
"type": "bytes32[]"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": true,
"inputs": [],
"name": "ballotChairman",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotCountNonvotesAsBlanks",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotMaxVotesPerProposal",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotMaxVotesPerVoter",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotPercentOfRegisteredVotersReqToBeValid",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotPercentOfVotesCastToWin",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotTitle",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotVoteBefore",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ballotVoteStarts",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "voter",
"type": "address"
}
],
"name": "getVoterIdx",
"outputs": [
{
"name": "",
"type": "int256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "proposalList",
"outputs": [
{
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "proposalListLength",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "voterList",
"outputs": [
{
"name": "voter",
"type": "address"
},
{
"name": "votesLeft",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "voterMap",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
];
// $ solc --abi src/Ballot.sol | tail -1 | jq
......
......@@ -6,6 +6,7 @@ var netid;
var netname;
var blocknumber = -2;
var nowblock;
var proposalLength = 0;
var netnames = {
"1": 'Ethereum mainnet',
......@@ -20,9 +21,9 @@ var netnames = {
var mainaddr = {
'5445': '0xe5bf7c3e8aa529e42fbd99428137b68db75d85f9',
'47525974938': '0xe3e08934b6fa0b68972c08e0f545cee31ed039c6',
'5777': '0x68bc96dd287Fd7AdAD480b487B16ac5AE7D59B3A'
'5777': '0xeAf032eaC758646E167916028F3abAbF0f33ae5d'
};
var ballot_keccak3 = '0xfd956d3ac857d157367d1a1bfe0e0fddee572dd24aebe34df32c430543377bb0';
var ballot_keccak3 = '0x20ab18e35a65929a015b8faf468469a21d2268ffce74a8888a12eb6b9d10bf43';
var contract_event;
window.addEventListener('load', page_loaded);
......@@ -478,9 +479,10 @@ async function ver_votacion2(addr, code) {
// Getting the title
contract.ballotTitle.call({ gas: 2111000 }, getBallotTitle);
// Getting the proposal list
// @TODO: get the proposal mapping's length
contract.proposalList.call(0, { gas: 2111000 }, getProposalList);
contract.proposalList.call(1, { gas: 2111000 }, getProposalList);
let proposalLength = await getProposalListLength(contract);
for(var i=0;i<proposalLength;i++){
contract.proposalList.call(i, { gas: 2111000 }, getProposalList);
}
// Getting the ballot dates
contract.ballotVoteStarts.call({ gas: 2111000 }, getBallotVoteStarts);
contract.ballotVoteBefore.call({ gas: 2111000 }, getBallotVoteBefore);
......@@ -497,6 +499,18 @@ async function ver_votacion2(addr, code) {
///////////////////////////////////////////////////////////
// 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){
if(err){
alertar(err);
......
......@@ -326,6 +326,9 @@
scrollTop: 0
}, 200);
$('#errorForm').focus();
$("#voterow :input").attr("readonly", false);
$("#voterow :input").attr("disabled", false);
$("#voterow .btn").show();
}
},
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