From 7f4b9e20a4bdfe129abb0cea798ba4dcc96bcd97 Mon Sep 17 00:00:00 2001 From: mbraidot <mbraidot@buenosaires.gob.ar> Date: Thu, 25 Apr 2019 16:50:54 -0300 Subject: [PATCH] =?UTF-8?q?Haciendo=20din=C3=A1mica=20la=20lectura=20de=20?= =?UTF-8?q?proposals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solidity/Ballot.sol | 6 +- web/dist/js/vendor/abi.js | 586 ++++++++++++++++++----------------- web/dist/js/vendor/ballot.js | 24 +- web/dist/smartNewvote.html | 3 + 4 files changed, 325 insertions(+), 294 deletions(-) diff --git a/solidity/Ballot.sol b/solidity/Ballot.sol index 5ab270a..1998d57 100644 --- a/solidity/Ballot.sol +++ b/solidity/Ballot.sol @@ -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 ); diff --git a/web/dist/js/vendor/abi.js b/web/dist/js/vendor/abi.js index 913f54e..7a99718 100644 --- a/web/dist/js/vendor/abi.js +++ b/web/dist/js/vendor/abi.js @@ -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 diff --git a/web/dist/js/vendor/ballot.js b/web/dist/js/vendor/ballot.js index 66a6951..72489c0 100644 --- a/web/dist/js/vendor/ballot.js +++ b/web/dist/js/vendor/ballot.js @@ -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); diff --git a/web/dist/smartNewvote.html b/web/dist/smartNewvote.html index 1dba573..642d1d0 100644 --- a/web/dist/smartNewvote.html +++ b/web/dist/smartNewvote.html @@ -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) { -- GitLab