Skip to content
Snippets Groups Projects
Commit cd8958d2 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Import from Robert

parent 769802c8
No related branches found
No related tags found
No related merge requests found
// $ solc --abi src/Ballot.sol | head -4 | tail -1 | jq
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"
}
];
// $ solc --abi src/Ballot.sol | tail -1 | jq
var abiNew = [
{
"constant": false,
"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[]"
}
],
"name": "newBallot",
"outputs": [
{
"name": "newaddr",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
];
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 139.31 100"><defs><style>.c{fill:#5c5c60}</style><radialGradient id="a" cx="69.48" cy="64.25" r="48.74" gradientTransform="matrix(1.39 0 0 1.39 -27.38 -19.65)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#84d0d0"/><stop offset="1" stop-color="#6a9ad1"/></radialGradient></defs><title>Blockchain Federal Argentina</title><path fill="#e5b449" d="M69.65 53.63a14.47 14.47 0 0 0-14.47 14.48h28.95a14.48 14.48 0 0 0-14.48-14.48z"/><path fill="url(#a)" d="M1.61 68.11V55.32l22.14 12.79L45.9 55.32v12.79h1.61V54.39l22.14-12.78L91.8 54.39v13.72h1.61V54.39L104.48 48l10.27-5.93v26h1.61v-26l21.34 12.32v13.72h1.61V53.47l-23-13.25v-26.5L92.6 0 69.65 13.25 46.7 0 23 13.72v26.5L0 53.47v14.64zm91.8-65.79l21.34 12.32v24.65L93.41 27zm20.53 38.36l-10.26 5.93L92.6 53 71.26 40.68 92.6 28.36zm-43.48-26L91.8 2.32V27L70.46 39.29zm-1.61 25.54L47.51 52.54V27.89l21.34-12.32zM46.7 1.86L68 14.18 46.7 26.5 25.36 14.18zM24.56 15.57L45.9 27.89v24.65l-10.27-5.93-11.07-6.39zm-.81 26L34.83 48l10.27 5.93-21.35 12.32L2.41 53.93z"/><path d="M.09 73.53H5.6c2.66 0 4.58 1.47 4.58 4a3.68 3.68 0 0 1-2 3.39 3.79 3.79 0 0 1 2.59 3.81c0 3-2.3 4.48-5.06 4.48H.09zm5.51 6.62a2.23 2.23 0 0 0 2.32-2.39 2.16 2.16 0 0 0-2.36-2.32H2.3v4.71zm.25 7.21a2.5 2.5 0 0 0 2.7-2.68A2.56 2.56 0 0 0 5.83 82H2.3v5.38zM14.43 73.53h2.21v13.83h7.05v1.91h-9.26zM33.25 73.26a7.93 7.93 0 0 1 8.07 8 8.09 8.09 0 1 1-16.17 0 8 8 0 0 1 8.1-8zm0 14.25a6 6 0 0 0 5.8-6.22 5.82 5.82 0 1 0-11.63 0 6 6 0 0 0 5.83 6.22zM51.47 73.26a8.11 8.11 0 0 1 5.73 2.07L56.11 77a7.2 7.2 0 0 0-4.55-1.71 5.71 5.71 0 0 0-5.82 6 5.91 5.91 0 0 0 5.84 6.22 7.11 7.11 0 0 0 4.86-2.05L57.63 87a8.47 8.47 0 0 1-6.12 2.5 8.14 8.14 0 0 1 0-16.28zM61 73.53h2.21v6.62l6.32-6.62H72L65.06 81l7.21 8.23h-2.5l-6.54-7.22v7.22H61zM80.9 73.33a8 8 0 0 1 5.65 2l-.83 1.13A7.37 7.37 0 0 0 81 74.75a6.27 6.27 0 0 0-6.31 6.56c0 3.75 2.63 6.8 6.35 6.8A7.35 7.35 0 0 0 86.08 86l.92 1.11a8.36 8.36 0 0 1-6 2.43 7.89 7.89 0 0 1-8-8.21 7.77 7.77 0 0 1 7.9-8zM90.32 73.59h1.54v7.14H101v-7.14h1.54v15.68H101v-7.16h-9.1v7.16h-1.58zM114.79 84.28h-6.32l-1.78 5h-1.63l5.75-15.68h1.66l5.75 15.68h-1.63zm-3.17-9.06s-.34 1.3-.6 2l-2.1 5.69h5.4l-2.06-5.69c-.26-.73-.6-2-.6-2zM120.78 73.59h1.54v15.68h-1.54zM126.87 73.59h1.5l8 11.29c.53.78 1.29 2.12 1.29 2.12s-.13-1.29-.13-2.12V73.59h1.54v15.68h-1.49l-8-11.28c-.54-.78-1.3-2.12-1.3-2.12s.13 1.29.13 2.12v11.28h-1.54zM0 94.19h3v.5H.58v2.15h2.1v.5H.58v2.56H0zM7.88 94.19h3.22v.5H8.44v2.08h2.17v.51H8.44v2.12h2.81v.5H7.88zM16.21 94.19h1.84a2.86 2.86 0 1 1 0 5.71h-1.84zM18 99.4a2.36 2.36 0 0 0 0-4.71h-1.23v4.71zM25.91 94.19h3.22v.5h-2.66v2.08h2.17v.51h-2.17v2.12h2.8v.5h-3.36zM34.23 94.19h1.69a2.73 2.73 0 0 1 1.08.15 1.67 1.67 0 0 1-.22 3l.14.23 1.25 2.3h-.65l-1.29-2.4h-1.44v2.4h-.56zM36.15 97a1.18 1.18 0 0 0 .61-2.16 1.61 1.61 0 0 0-.81-.14h-1.16V97zM45.84 98.08h-2.3l-.65 1.82h-.59l2.09-5.71H45l2.09 5.71h-.59zm-1.15-3.3l-.22.74-.77 2.07h2l-.75-2.07a9.7 9.7 0 0 1-.22-.74zM51.71 94.19h.56v5.21h2.65v.5h-3.21zM68.29 98.08H66l-.66 1.82h-.59l2.1-5.71h.6l2.1 5.71H69zm-1.15-3.3s-.12.47-.22.74l-.76 2.07h2l-.74-2.07a9.7 9.7 0 0 1-.22-.74zM74.17 94.19h1.69a2.7 2.7 0 0 1 1.07.15 1.67 1.67 0 0 1-.22 3l.15.23 1.24 2.3h-.64l-1.29-2.4h-1.44v2.4h-.56zM76.08 97a1.06 1.06 0 0 0 1.13-1.16 1.05 1.05 0 0 0-.52-1 1.61 1.61 0 0 0-.81-.14h-1.15V97zM85.45 94.09a3.08 3.08 0 0 1 2 .67l-.3.42a2.82 2.82 0 0 0-1.71-.57 2.44 2.44 0 0 0 0 4.87 2.49 2.49 0 0 0 1.8-.84v-1h-1v-.51h1.51v2.77h-.52v-.43-.24a2.56 2.56 0 0 1-1.86.77 2.83 2.83 0 0 1-2.8-3 2.87 2.87 0 0 1 2.88-2.91zM92.8 94.19H96v.5h-2.64v2.08h2.17v.51h-2.17v2.12h2.8v.5H92.8zM101.12 94.19h.55l2.92 4.11c.19.29.47.77.47.77V94.19h.56v5.71H105l-2.92-4.11c-.19-.28-.47-.77-.47-.77V99.9h-.57zM112.21 94.69h-2v-.5h4.66v.5h-2v5.21h-.56zM119.39 94.19h.61v5.71h-.56zM125.29 94.19h.55l2.92 4.11c.19.29.47.77.47.77s-.05-.47-.05-.77v-4.11h.57v5.71h-.55l-2.92-4.11c-.19-.28-.47-.77-.47-.77V99.9h-.56zM137.92 98.08h-2.3L135 99.9h-.59l2.09-5.71h.6l2.1 5.71h-.59zm-1.16-3.3s-.12.47-.21.74l-.77 2.07h2l-.78-2.07a9.7 9.7 0 0 1-.22-.74z" class="c"/></svg>
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 139.31 100">
<defs>
<style>.c{fill:#5c5c60}</style>
</defs>
<title>Blockchain Federal Argentina</title>
<!-- sun -->
<path fill="#e5b449" d="M69.65 53.63a14.47 14.47 0 0 0-14.47 14.48h28.95a14.48 14.48 0 0 0-14.48-14.48z"/>
<!-- cubes -->
<path fill="#ffffff" d="M1.61 68.11V55.32l22.14 12.79L45.9 55.32v12.79h1.61V54.39l22.14-12.78L91.8 54.39v13.72h1.61V54.39L104.48 48l10.27-5.93v26h1.61v-26l21.34 12.32v13.72h1.61V53.47l-23-13.25v-26.5L92.6 0 69.65 13.25 46.7 0 23 13.72v26.5L0 53.47v14.64zm91.8-65.79l21.34 12.32v24.65L93.41 27zm20.53 38.36l-10.26 5.93L92.6 53 71.26 40.68 92.6 28.36zm-43.48-26L91.8 2.32V27L70.46 39.29zm-1.61 25.54L47.51 52.54V27.89l21.34-12.32zM46.7 1.86L68 14.18 46.7 26.5 25.36 14.18zM24.56 15.57L45.9 27.89v24.65l-10.27-5.93-11.07-6.39zm-.81 26L34.83 48l10.27 5.93-21.35 12.32L2.41 53.93z"/>
<!-- text block -->
<path fill="#ffffff" d="M.09 73.53H5.6c2.66 0 4.58 1.47 4.58 4a3.68 3.68 0 0 1-2 3.39 3.79 3.79 0 0 1 2.59 3.81c0 3-2.3 4.48-5.06 4.48H.09zm5.51 6.62a2.23 2.23 0 0 0 2.32-2.39 2.16 2.16 0 0 0-2.36-2.32H2.3v4.71zm.25 7.21a2.5 2.5 0 0 0 2.7-2.68A2.56 2.56 0 0 0 5.83 82H2.3v5.38zM14.43 73.53h2.21v13.83h7.05v1.91h-9.26zM33.25 73.26a7.93 7.93 0 0 1 8.07 8 8.09 8.09 0 1 1-16.17 0 8 8 0 0 1 8.1-8zm0 14.25a6 6 0 0 0 5.8-6.22 5.82 5.82 0 1 0-11.63 0 6 6 0 0 0 5.83 6.22zM51.47 73.26a8.11 8.11 0 0 1 5.73 2.07L56.11 77a7.2 7.2 0 0 0-4.55-1.71 5.71 5.71 0 0 0-5.82 6 5.91 5.91 0 0 0 5.84 6.22 7.11 7.11 0 0 0 4.86-2.05L57.63 87a8.47 8.47 0 0 1-6.12 2.5 8.14 8.14 0 0 1 0-16.28zM61 73.53h2.21v6.62l6.32-6.62H72L65.06 81l7.21 8.23h-2.5l-6.54-7.22v7.22H61zM80.9 73.33a8 8 0 0 1 5.65 2l-.83 1.13A7.37 7.37 0 0 0 81 74.75a6.27 6.27 0 0 0-6.31 6.56c0 3.75 2.63 6.8 6.35 6.8A7.35 7.35 0 0 0 86.08 86l.92 1.11a8.36 8.36 0 0 1-6 2.43 7.89 7.89 0 0 1-8-8.21 7.77 7.77 0 0 1 7.9-8zM90.32 73.59h1.54v7.14H101v-7.14h1.54v15.68H101v-7.16h-9.1v7.16h-1.58zM114.79 84.28h-6.32l-1.78 5h-1.63l5.75-15.68h1.66l5.75 15.68h-1.63zm-3.17-9.06s-.34 1.3-.6 2l-2.1 5.69h5.4l-2.06-5.69c-.26-.73-.6-2-.6-2zM120.78 73.59h1.54v15.68h-1.54zM126.87 73.59h1.5l8 11.29c.53.78 1.29 2.12 1.29 2.12s-.13-1.29-.13-2.12V73.59h1.54v15.68h-1.49l-8-11.28c-.54-.78-1.3-2.12-1.3-2.12s.13 1.29.13 2.12v11.28h-1.54zM0 94.19h3v.5H.58v2.15h2.1v.5H.58v2.56H0zM7.88 94.19h3.22v.5H8.44v2.08h2.17v.51H8.44v2.12h2.81v.5H7.88zM16.21 94.19h1.84a2.86 2.86 0 1 1 0 5.71h-1.84zM18 99.4a2.36 2.36 0 0 0 0-4.71h-1.23v4.71zM25.91 94.19h3.22v.5h-2.66v2.08h2.17v.51h-2.17v2.12h2.8v.5h-3.36zM34.23 94.19h1.69a2.73 2.73 0 0 1 1.08.15 1.67 1.67 0 0 1-.22 3l.14.23 1.25 2.3h-.65l-1.29-2.4h-1.44v2.4h-.56zM36.15 97a1.18 1.18 0 0 0 .61-2.16 1.61 1.61 0 0 0-.81-.14h-1.16V97zM45.84 98.08h-2.3l-.65 1.82h-.59l2.09-5.71H45l2.09 5.71h-.59zm-1.15-3.3l-.22.74-.77 2.07h2l-.75-2.07a9.7 9.7 0 0 1-.22-.74zM51.71 94.19h.56v5.21h2.65v.5h-3.21zM68.29 98.08H66l-.66 1.82h-.59l2.1-5.71h.6l2.1 5.71H69zm-1.15-3.3s-.12.47-.22.74l-.76 2.07h2l-.74-2.07a9.7 9.7 0 0 1-.22-.74zM74.17 94.19h1.69a2.7 2.7 0 0 1 1.07.15 1.67 1.67 0 0 1-.22 3l.15.23 1.24 2.3h-.64l-1.29-2.4h-1.44v2.4h-.56zM76.08 97a1.06 1.06 0 0 0 1.13-1.16 1.05 1.05 0 0 0-.52-1 1.61 1.61 0 0 0-.81-.14h-1.15V97zM85.45 94.09a3.08 3.08 0 0 1 2 .67l-.3.42a2.82 2.82 0 0 0-1.71-.57 2.44 2.44 0 0 0 0 4.87 2.49 2.49 0 0 0 1.8-.84v-1h-1v-.51h1.51v2.77h-.52v-.43-.24a2.56 2.56 0 0 1-1.86.77 2.83 2.83 0 0 1-2.8-3 2.87 2.87 0 0 1 2.88-2.91zM92.8 94.19H96v.5h-2.64v2.08h2.17v.51h-2.17v2.12h2.8v.5H92.8zM101.12 94.19h.55l2.92 4.11c.19.29.47.77.47.77V94.19h.56v5.71H105l-2.92-4.11c-.19-.28-.47-.77-.47-.77V99.9h-.57zM112.21 94.69h-2v-.5h4.66v.5h-2v5.21h-.56zM119.39 94.19h.61v5.71h-.56zM125.29 94.19h.55l2.92 4.11c.19.29.47.77.47.77s-.05-.47-.05-.77v-4.11h.57v5.71h-.55l-2.92-4.11c-.19-.28-.47-.77-.47-.77V99.9h-.56zM137.92 98.08h-2.3L135 99.9h-.59l2.09-5.71h.6l2.1 5.71h-.59zm-1.16-3.3s-.12.47-.21.74l-.77 2.07h2l-.78-2.07a9.7 9.7 0 0 1-.22-.74z"/>
</svg>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Firmar contrato en BFA</title>
<link rel="stylesheet" href="votar1.css">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
</head>
<body>
<noscript>You need to enable JavaScript to use this page.</noscript>
<div id="background"></div>
<div id="root">
<div id="status" class="hidden status" ></div>
<img id="bfalogo" src="bfalogobw.svg" />
<div id="popup" class="hidden warning"> Y U P </div>
<div id="startdiv">
<h1>Ver o votar usando un contrato en BFA.</h1>
<p>Ya tenés la dirección de una votación?</p>
<p>
<form action="javascript:ver_votacion('')">
<p>Dirección de la votación:
<input id="input_address" name="addr" size="42" maxlength="42"
autofocus required title="40 caracteres hex (puede empezar con 0x)" />
<input type="submit" value="Ver votación" />
</p>
</form>
</p>
<div id="div_create_ballot" class="hidden">
<span>o tal vez querés</span>
<a href="javascript:ask_for_ballot_details()" id="nueva_link">crear una votación nueva</a>
<span>?</span>
</div>
</div>
<div id="newcontract" class="hidden">
<form id="form_create_new_ballot" action="javascript:nueva_votacion()">
<table id="newtable">
<tr>
<td>Title
<td><input name="title" />
<tr>
<td>Vote starts
<td><input name="voteStarts" />
<tr>
<td>Vote before
<td><input name="voteBefore" />
<tr>
<td>Percent of registered voters must vote for the result to be valid
<td><input name="percentOfRegisteredVotersReqToBeValid" value="0.000001" />
<tr>
<td>Percent of votes cast is required to win
<td><input name="percentOfVotesCastToWin" value="50.000001" />
<tr>
<td>Count non-votes as blanks
<td>
<select name="countNonvotesAsBlanks">
<option value="No" selected>No </option>
<option value="Yes" >Si / Yes</option>
</select>
<tr>
<td>Maximum number of votes per voter
<td><input name="maxVotesPerVoter" value="1" />
<tr>
<td>How many votes each voter may use for the same proposal
<td><input name="maxVotesPerProposal" value="1" />
<tr class="proposal">
<td>Proposal 1 description
<td><input name="proposal1" />
<tr class="proposal">
<td>Proposal 2 description
<td><input name="proposal2" />
<tr class="proposal">
<td>Proposal 3 description
<td><input name="proposal3" />
<tr class="proposal">
<td>Proposal 4 description
<td><input name="proposal4" />
<tr class="proposal">
<td>Proposal 5 description
<td><input name="proposal5" />
<tr class="proposal">
<td>Proposal 6 description
<td><input name="proposal6" />
<tr class="proposal">
<td>Proposal 7 description
<td><input name="proposal7" />
<tr class="proposal">
<td>Proposal 8 description
<td><input name="proposal8" />
<tr class="proposal">
<td>Proposal 9 description
<td><input name="proposal9" />
<tr class="proposal">
<td>Proposal 10 description
<td><input name="proposal11" />
<tr class="proposal">
<td>Proposal 11 description
<td><input name="proposal12" />
<tr class="proposal">
<td>Proposal 12 description
<td><input name="proposal10" />
</table>
<input type="submit" value="Crear nueva" />
</form>
</div>
</div>
<script type="text/javascript" src="web3.js" ></script>
<script type="text/javascript" src="abi.js" ></script>
<script type="text/javascript" src="utils.js" ></script>
<script type="text/javascript" src="status.js"></script>
<script type="text/javascript" src="votar1.js"></script>
</body>
</html>
ballot/pattern.png

624 B

var gotEth = 0;
var accExposed = 0;
var rootdiv;
var error;
var netid;
var netname;
var blocknumber = -2;
var nowblock;
var netnames = {
"1": 'Ethereum mainnet',
"2": 'Morden test',
"3": 'ropsten test',
"4": 'Rinkeby test',
'42': 'Kovan test',
'5445': 'BFA test',
'47525974938': 'Blockchain Federal Argentina'
};
var mainaddr = {
'5445': '0xe5bf7c3e8aa529e42fbd99428137b68db75d85f9',
'47525974938': '0xe3e08934b6fa0b68972c08e0f545cee31ed039c6'
};
window.addEventListener('load', page_loaded );
function addchild(parent, childtype, childText, attributes) {
var childNode = document.createElement(childtype);
if (typeof childText == 'string') {
var childTextNode = document.createTextNode( childText );
childNode.appendChild( childTextNode );
}
if (attributes) {
for ( var att in attributes )
childNode.setAttribute( att, attributes[att] );
}
parent.appendChild( childNode );
return childNode;
}
function ask_about_contract_address()
{
addchild( rootdiv, 'img', undefined, {
'id': 'bfalogo',
'src': 'bfalogobw.svg',
});
var d = addchild( rootdiv, 'div');
addchild( d, 'h1', 'Ver o votar usando un contrato en BFA.');
addchild( d, 'p', 'Ya tenés la dirección de una votación?');
var p = addchild( d, 'p');
// form initialisation
var f = addchild( p, 'form', undefined, {
'action': 'javascript:ver_votacion("")'
});
// describing the form to the user
var fp = addchild( f, 'p', 'Dirección de la votación: ' );
// text input element
addchild( fp, 'input', undefined, {
'id': 'input_address',
'type': 'text',
'name': 'addr',
'size': '42',
'maxlength': '42',
'autofocus': 'true',
'required': 'true',
'title': '40 caracteres hex (puede empezar con 0x)'
});
// submit button
addchild( fp, 'input', undefined, {
'type': 'submit',
'value': 'Ver votación'
});
}
function update_create_new_ballot()
{
// Find our div (if it exists).
var div = document.getElementById('div_create_ballot');
if ( ! div )
return;
// Don't change anything, if we are in the middle of creating a new contract.
if ( document.getElementById('newcontract') )
return;
// See if we already have the form inside the div
if ( ! document.getElementById('nueva_link') )
{
addchild( div, 'span', 'o tal vez querés ' );
addchild( div, 'a', 'crear una votación nueva',
{
'href':'javascript:ask_for_ballot_details()',
'id':'nueva_link'
}
);
addchild( div, 'span', '?' );
}
if ( mainaddr[netid] == undefined )
{
// if we do not have the address of the mother contract, we will
// not present the user with a choice to create a new form.
div.setAttribute( 'class', 'hidden' );
return;
}
div.removeAttribute( 'class' );
}
async function page_loaded()
{
var body = document.getElementsByTagName("body")[0];
addchild( body, 'div', undefined, {
'id': 'background'
});
rootdiv = addchild( body, 'div', undefined, {'id':'root'} );
const Web3 = require('web3');
// post Nov 2018 this works
if (window.ethereum)
{
window.web3 = new Web3(ethereum);
gotEth = 1;
}
else
// pre Nov 2018, we look here
if (window.web3)
{
window.web3 = new Web3(web3.currentProvider);
gotEth = 1;
// in pre 2019 dapp browsers acccounts are always exposed
accExposed = 1;
}
else
if ( document.URL.search( /file:/ ) == 0 )
error = "Plugins can not be properly detected " +
"when running directly from a file. The document needs to be " +
"served from a web server.";
else
{
// Non-dapp browsers...
window.alert("Non-Ethereum browser detected. Consider using MetaMask.");
error = "I can't figure out how to ask your " +
"browser or plugins how to interact with the blockchain.";
}
if ( error )
{
addchild( rootdiv, 'div', error, {'class':'warning'});
return;
}
// wow, all okay
// add more UI elements
console.log( 'window.web3.version.api is ' + window.web3.version.api );
ask_about_contract_address();
//addchild( rootdiv, 'hr', undefined, {'width':'20%'} );
addchild( rootdiv, 'div', undefined, {'id':'div_create_ballot','class':'hidden'} );
update_create_new_ballot();
get_status();
timer = setInterval( get_status, 1000 );
}
function deleteAllChildren( node )
{
node.children.forEach(
function(item,idx)
{
node.removeChild( item );
}
);
}
async function get_netid()
{
window.web3.version.getNetwork(
(err, netId) =>
{
netid = undefined;
netname = undefined;
if ( netId != undefined )
{
netid = netId;
netname = netnames[netid];
if ( netname == undefined )
netname = netid;
else
netname = netid + " ("+netname+")";
}
update_status_display();
}
)
}
async function got_block_details( err, block )
{
if (err)
return;
nowblock = block;
update_status_display();
}
async function get_status()
{
window.web3.eth.getBlockNumber(
(err,blocknum) =>
{
// If the increase is bigger than one,
// or negative, get the netid.
var diff = blocknum - blocknumber;
if ( diff < 0 || diff > 1 )
get_netid();
if ( blocknum != blocknumber )
{
blocknumber = blocknum;
update_status_display();
nowblock = undefined;
window.web3.eth.getBlock( blocknumber, false, got_block_details );
}
}
)
}
function update_status_display()
{
var div = document.getElementById('status') ||
addchild( rootdiv, 'div', undefined, {"class":"status","id":"status"} );
var info = [];
if ( netname )
info.push( 'Network ' + netname );
var thattimething;
if ( blocknumber )
{
var thistxt = "Current block: #" + blocknumber;
if ( nowblock )
thistxt += ' @ ' + new Date( nowblock.timestamp * 1000 ).toISOString();
info.push( thistxt );
}
if ( info.length == 0 )
{
if ( div && div.parent )
div.parent.removeChild( div );
}
else
div.innerHTML = info.join('<br/>');
update_create_new_ballot()
}
function api_version()
{
if ( window.web3.version.api.substring(0,2) == '0.' )
return 0;
if ( window.web3.version.api.substring(0,2) == '1.' )
return 1;
return -1;
}
function setup_existing_contract( abi, addr)
{
if ( api_version() == 0 )
{
var MyContract = window.web3.eth.contract( abiNew );
console.log( MyContract );
contract = MyContract.at( mainaddr[netid] );
return contract;
}
window.alert( 'Do not know how to deal with contracts at this API version (' +window.web3.version.api+ ').' );
return;
}
function add_proposal( pos )
{
var div = document.getElementById( 'newtable' );
if ( ! div )
return;
var len = div.children.length;
//
var newnode = document.createElement('tr');
newnode.setAttribute( 'class', 'proposal' );
// We add/adjust text and attribs afterwards
var td1 = addchild( newnode, 'td' );
var td2 = addchild( newnode, 'td' );
addchild( td2, 'input' );
var idx = 0;
for ( var i = 0; i < div.children.length; i++ )
{
if ( div.children[i].getAttribute('class') == 'proposal' )
{
idx++;
if ( newnode )
{
if ( pos == idx )
{
div.insertBefore( newnode, div.children[i-1] );
newnode = undefined;
}
}
}
}
if ( newnode && idx < 10 )
div.insertBefore( newnode, div.lastChild );
// Fix numbering
idx = 0;
for ( var i = 0; i < div.children.length; i++ )
{
if ( div.children[i].getAttribute('class') == 'proposal' )
{
idx++;
div.children[i].children[0].innerHTML = 'Proposal '+idx;
div.children[i].children[1].children[0].setAttribute( 'name', 'proposal'+idx );
}
}
}
async function ask_for_ballot_details()
{
if ( mainaddr[netid] == undefined )
return;
if ( abiNew == undefined )
return
if ( abiNew == '' )
return;
//
var otherdiv;
if ( otherdiv = document.getElementById('div_create_ballot') )
otherdiv.setAttribute( 'class', 'hidden' );
//
// Our territory starts here
//
var newdiv = addchild( rootdiv, 'div', undefined, {'id':'newcontract'} );
// Create form.
var form = addchild( newdiv, 'form', undefined, {
'id': 'form_create_new_ballot',
'action': 'javascript:nueva_votacion()'
});
var table = addchild( form, 'table', undefined, {'id':'newtable' } );
// Title
var tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Title' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {'name':'title'}
);
// Vote Starts
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Vote starts' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {'name':'voteStarts'}
);
// Vote Before
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Vote before' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {'name':'voteBefore'}
);
// % of registered voters req to be valid
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Percent of registered voters must vote for the result to be valid' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {
'name': 'percentOfRegisteredVotersReqToBeValid',
'value': '0.000001'
}
);
// % of votes cast to win
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Percent of votes cast to win' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {'name':'percentOfVotesCastToWin','value':'50.000001'}
);
// Count non-votes as blanks
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Count non-votes as blanks');
var select = addchild(
addchild( tr, 'td' ),
'select', undefined, { 'name':'countNonvotesAsBlanks' }
);
addchild( select, 'option', undefined, {'value':'Yes'} ).innerHTML = 'Si / Yes';
addchild( select, 'option', undefined, {'value':'No'} ).innerHTML = 'No';
// Max votes per voter
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Maximum number of votes per voter' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {'name':'maxVotesPerVoter','value':'1'}
);
// Max votes per proposal
tr = addchild( table, 'tr' );
addchild( tr, 'td', 'Maximum number of votes per proposal' );
addchild(
addchild( tr, 'td' ),
'input', undefined, {'name':'maxVotesPerProposal','value':'1'}
);
// more mas extra
tr = addchild( table, 'tr' );
addchild(
addchild( tr, 'td', undefined, {'colspan':'2'} ),
'a', '[ + extra proposal ]', {'href':'javascript:add_proposal(999)'} );
// Proposals
add_proposal( 1 );
//
// submit button to create a new ballot
addchild( form, 'input', undefined, {
'type': 'submit',
'value': 'Crear nueva'
});
}
async function nueva_votacion()
{
if ( mainaddr[netid] == undefined )
return;
var f = document.forms['form_create_new_ballot'];
var arguments = [];
arguments.push( f['title'] .value );
arguments.push( f['voteStarts'] .value );
arguments.push( f['voteBefore'] .value );
arguments.push( f['percentOfRegisteredVotersReqToBeValid'] .value );
arguments.push( f['percentOfVotesCastToWin'] .value );
arguments.push( f['countNonvotesAsBlanks'] .value );
arguments.push( f['maxVotesPerVoter'] .value );
arguments.push( f['maxVotesPerProposal'] .value );
var p;
var proposals = [];
for ( var i = 1; p = f['proposal'+i]; i++ )
proposals.push( p.value );
var newdiv = document.getElementById('newcontract');
var localstatus = addchild( newdiv, 'p', 'Trying to access your account.' );
access_accounts();
localstatus.innerHTML = 'Creating new voting contract.';
var contract = setup_existing_contract( abiNew, mainaddr[netid] );
if ( ! contract )
return;
var rcpt;
if ( api_version() == 0 )
contract.newBallot.call(
arguments[0],
arguments[1],
arguments[2],
arguments[3],
arguments[4],
arguments[5],
arguments[6],
arguments[7],
proposals,
{ gas: 2111000 },
contract_created
);
}
async function contract_created(err,rcpt)
{
console.log( rcpt );
if ( !rcpt )
return;
//ver_votacion( newaddr );
}
async function ver_votacion( addr )
{
if ( addr == "" )
addr =
document
.getElementById('input_address')
.value;
rootdiv.innerHTML = '<p>Loading contract details, if possible.</p>';
if ( addr && addr.length == 40 )
addr = '0x' + addr;
window.web3.eth.getCode( addr, function(err,code) {
if ( err )
{
rootdiv.innerHTML = '<p>Unable to get bytecode of contract: ' + err + '</p>';
return;
}
ver_votacion2( addr, code );
});
}
async function ver_votacion2( addr, code )
{
console.log( code );
if ( code == '0x' )
{
rootdiv.innerHTML = '<p>There is no contract at that address</p>';
return;
}
var keccak3 = window.web3.sha3( code, {'encoding':'hex'} );
console.log( keccak3 );
if ( keccak3 != '0xabcd' )
{
rootdiv.innerHTML = '<p>There is no recognised Ballot contract at that address.</p>';
return;
}
var contract = setup_existing_contract( abiBallot, addr );
if ( !contract )
return;
var detailpromises;
// make sure we have just a single verdiv
var verdiv;
while ( verdiv = document.getElementById('verdiv'))
verdiv.parent.removeChild( verdiv );
verdiv = addchild( rootdiv, 'div', undefined, { 'id': 'verdiv' });
// Get headline
var proposaldiv = addchild( verdiv, 'p', 'Proposal:')
contract.methods.proposal().call( {} )
.then(
function showproposal(result)
{
proposaldiv.innerHTML = 'Proposal: ' + result;
},
function failproposal(err)
{
proposaldiv.innerHTML = 'Failed to get proposal: ' + err
}
);
}
function access_accounts()
{
if ( gotEth )
{
if ( ! accExposed )
{
try
{
// dapp browsers from after Nov 2018, requires us to ask
// permission to use the account.
ethereum.enable();
// Acccounts now exposed, or the error gets caught
accExposed = 1;
}
catch ( error )
{
window.alert(
"Access to your ethereum account was denied. The reason " +
"given with was \"" +
error +
"\"."
);
}
}
// web3.eth.sendTransaction({/* ... */});
}
}
async function de_acuerdo_y_firmar()
{
access_accounts();
if ( ! accExposed )
return;
// web3.eth.sendTransaction({/* ... */});
}
var provider = 'https://opentx.bfa.ar:8546';
var netnames = {
"1": 'Ethereum mainnet',
"2": 'Morden test',
"3": 'ropsten test',
"4": 'Rinkeby test',
'42': 'Kovan test',
'5445': 'BFA test',
'47525974938': 'Blockchain Federal Argentina'
};
var netinfo;
var nowblock;
var web3;
var timer;
function status_reset()
{
netinfo = {
'blocknumber': -2
};
}
async function visibilitychange()
{
if ( timer != undefined && document.visibilityState == 'hidden' )
{
clearInterval( timer );
status_reset();
update_status_display();
timer = undefined;
return;
}
if ( timer == undefined && document.visibilityState == 'visible' )
{
get_status();
timer = setInterval( get_status, 2500 );
return;
}
}
async function status_start()
{
document.addEventListener( "visibilitychange", visibilitychange );
status_reset();
const Web3 = require('web3');
// post Nov 2018 this works
if (window.ethereum)
{
web3 = new Web3(ethereum);
gotEth = 1;
}
else
// pre Nov 2018, we look here
if (window.web3)
{
web3 = new Web3( window.web3.currentProvider );
gotEth = 1;
// in pre 2019 dapp browsers acccounts are always exposed
accExposed = 1;
}
else
return;
web3.setProvider( new web3.providers.HttpProvider(provider) );
//console.log( web3.currentProvider );
visibilitychange();
}
function gotNetwork( err, networknumber )
{
if ( networknumber != undefined )
{
netinfo['number'] = networknumber;
var name = netnames[networknumber];
if ( name == undefined )
netinfo['name'] = networknumber;
else
netinfo['name'] = networknumber + " (" + name + ")";
}
update_status_display();
update_create_new_ballot(); // ugly to do from here
}
async function get_netid()
{
web3.version.getNetwork( gotNetwork );
}
function update_status_display()
{
var div = document.getElementById('status');
var info = [];
if ( netinfo['name'] )
info.push( 'Network ' + netinfo['name'] );
if ( netinfo['blocknumber'] != undefined )
{
var thistxt = "Current block: #" + netinfo['blocknumber'];
if ( nowblock )
thistxt += ' @ ' + new Date( nowblock.timestamp * 1000 ).toISOString();
info.push( thistxt );
}
var newhtml = info.join('<br/>');
if ( div.innerHTML != newhtml )
div.innerHTML = newhtml;
if ( info == [] )
setAttribWord( document.getElementById('status'), 'class', 'hidden' );
else
removeAttribWord( document.getElementById('status'), 'class', 'hidden' );
}
async function gotBlockDetails( err, blockdetails )
{
if (err)
status_reset();
else
nowblock = blockdetails;
update_status_display();
}
async function gotBlockNumber( err, newblocknum )
{
if (err)
{
console.log( err );
clearInterval( timer );
timer = undefined;
status_reset();
update_status_display();
return;
}
var diff = newblocknum - netinfo['blocknumber'];
// console.log( "diff = "+diff + " newblocknum = "+newblocknum + " stored = "+netinfo['blocknumber']);
if ( diff < 0 || diff > 4 )
{
// If the increase is bigger than one,
// or negative, then we probably changed
// network. So get the netid.
netinfo['number'] = undefined;
netinfo['name'] = undefined;
get_netid();
}
if ( diff )
{
netinfo['blocknumber'] = newblocknum;
nowblock = undefined;
web3.eth.getBlock( newblocknum, false, gotBlockDetails );
}
}
async function get_status()
{
web3.eth.getBlockNumber( gotBlockNumber );
}
var accExposed = 0;
function api_version()
{
if ( window.web3.version.api.substring(0,2) == '0.' )
return 0;
if ( window.web3.version.api.substring(0,2) == '1.' )
return 1;
return -1;
}
function removeAttribWord( node, attrib, word )
{
if ( !node )
return;
var a = node.getAttribute( attrib );
if ( !a )
return;
var list = a.split(' ');
var idx_word = list.indexOf( word );
// Return if it's class does not have the hidden keyword.
if ( idx_word == -1 )
return;
list.splice( idx_word, idx_word+1 );
node.setAttribute( attrib, list );
}
function setAttribWord( node, attrib, word )
{
if ( !node )
return;
var a = node.getAttribute( attrib );
var list = [];
if ( a )
{
list = a.split(' ');
var idx_word = list.indexOf( word );
// Return if it's class has the hidden keyword already.
if ( idx_word > -1 )
return;
}
// If not there yet, add it.
list.push( word );
node.setAttribute( attrib, list.join(' ') );
}
function isSetAttribWord( node, attrib, word )
{
if ( !node )
return false;
var a = node.getAttribute( attrib );
if ( !a )
return false;
var list = a.split(' ');
if ( ! a )
return false;
var idx_word = list.indexOf( word );
if ( idx_word > -1 )
return true;
return false
}
// The named section will be shows. The others will be hidden.
function show_section( name )
{
var sections = [ 'startdiv', 'newcontract' ];
for ( var i=0 ; i < sections.length ; i++ )
{
var thisname = sections[i];
var node = document.getElementById( thisname );
var func = setAttribWord;
if ( thisname == name )
func = removeAttribWord;
func( node, 'class', 'hidden' );
}
}
function access_accounts()
{
if ( ! accExposed )
{
try
{
// dapp browsers from after Nov 2018, requires us to ask
// permission to use the account.
ethereum.enable();
// Acccounts now exposed, or the error gets caught
// accExposed = 1;
}
catch ( error )
{
window.alert(
"Access to your ethereum account was denied. The reason " +
"given with was \"" +
error +
"\"."
);
}
}
// web3.eth.sendTransaction({/* ... */});
}
function bfa_setup( callback )
{
var w3prov = 'https://opentx.bfa.ar:8546';
var err;
const Web3 = require('web3');
// post Nov 2018 this works
if ( window.ethereum )
{
w3prov = window.ethereum;
gotEth = 1;
}
else
// pre Nov 2018, we look here
if ( window.web3 )
{
w3prov = window.web3.currentProvider;
gotEth = 1;
// in pre 2019 dapp browsers acccounts are always exposed
accExposed = 1;
}
else
if ( document.URL.search(/file:/) == 0 )
{
err = new RangeError(
"Plugins can not be properly detected when running directly "
+ "from a local file. "
+ "The document needs to be served from a web server."
);
callback( err, undefined );
return;
}
else
{
// Non-dapp browsers...
// "Non-Ethereum browser detected. Consider using MetaMask."
err = new ReferenceError(
"I can't figure out how to ask your " +
"browser or plugins how to interact with the blockchain."
);
// soft fail.. we do return an error plus a web3 object for
// interacting with an opentx server.
}
callback( err, new Web3(w3prov) );
}
function popup( text )
{
var div = document.getElementById('popup');
var func = removeAttribWord;
if ( text == undefined || text == '' )
{
text = '';
func = setAttribWord;
}
func( div, 'class', 'hidden' );
div.innerHTML = text;
}
html
{
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
background:
url(pattern.png),
#3b76ba;
background:
url(pattern.png),
-webkit-gradient(
linear,
left top,
right top,
from(#3b76ba),
to(#7dd2d9)
);
background:
url(pattern.png),
-webkit-linear-gradient(
left,
#3b76ba 0,
#7dd2d9 100%
);
background:
url(pattern.png),
linear-gradient(
to right,
#3b76ba 0,
#7dd2d9 100%
);
}
#root
{
margin: 5%;
}
#bfalogo
{
width: 140px;
height: 100px;
display: block;
margin-left: auto;
margin-right: auto;
}
div.warning
{
border: 1px solid yellow;
background: gray;
padding: 10px;
display: inline-grid;
position: fixed;
top: 30%;
left: 30%;
}
div.status
{
border: 1px dotted grey;
position: fixed;
top: 8px;
right: 8px;
padding: 4px;
text-align: right;
}
.hidden
{
display: none;
visibility: hidden;
}
var hasplugin = 0;
var mainaddr = {
'5445': '0xe5bf7c3e8aa529e42fbd99428137b68db75d85f9',
'47525974938': '0xe3e08934b6fa0b68972c08e0f545cee31ed039c6'
};
window.addEventListener('load', init1 );
async function init1()
{
bfa_setup( init2 );
}
async function init2( err, web3 )
{
if ( web3 == undefined )
{
window.alert( err );
return;
}
if ( err == undefined )
hasplugin = 1;
window.web3 = web3;
console.log( 'window.web3.version.api is ' + window.web3.version.api );
status_start();
show_section('startdiv');
update_create_new_ballot();
}
function update_create_new_ballot()
{
// Find our div
var div = document.getElementById('div_create_ballot');
// We get this from status.js
var netid = netinfo['number'];
// if we do not have the address of the mother contract, we will
// not present the user with a choice to create a new form.
if ( mainaddr[netid] == undefined )
div.setAttribute( 'class', 'hidden' );
else
div.removeAttribute( 'class', 'hidden' );
}
function setup_existing_contract( abi, addr)
{
if ( api_version() == 0 )
{
var MyContract = window.web3.eth.contract( abiNew );
contract = MyContract.at( addr );
return contract;
}
window.alert( 'Do not know how to deal with contracts at this API version (' +window.web3.version.api+ ').' );
return;
}
async function ask_for_ballot_details()
{
show_section('newcontract');
}
async function nueva_votacion()
{
// We get this from status.js
var netid = netinfo['number'];
//
if ( mainaddr[netid] == undefined )
return;
var f = document.forms['form_create_new_ballot'];
var arguments = [];
//
var title = f['title'].value;
if ( !title || title == '' )
throw new Error("No title is set");
arguments.push( f['title'] .value );
//
var voteStarts = new Date( f['voteStarts'].value );
voteStarts = new Date( Date.now() + 300000 );
if ( voteStarts == 'Invalid Date' )
throw new Error( voteStarts );
arguments.push( Math.floor(voteStarts.valueOf() / 1000) );
//
var voteBefore = new Date( f['voteBefore'].value );
voteBefore = new Date( Date.now() + 86700000 );
if ( voteBefore == 'Invalid Date' )
throw new Error( voteBefore );
arguments.push( Math.floor(voteBefore.valueOf() / 1000) );
//
arguments.push( f['percentOfRegisteredVotersReqToBeValid'] .value );
arguments.push( f['percentOfVotesCastToWin'] .value );
//
arguments.push( f['countNonvotesAsBlanks'].value == 'Yes' );
//
arguments.push( f['maxVotesPerVoter'] .value );
arguments.push( f['maxVotesPerProposal'] .value );
var proposals = [];
var p;
for ( var i = 1; p = f['proposal'+i]; i++ )
if ( p.value != '' )
proposals.push( p.value );
popup( 'Trying to access your account.' );
setTimeout( nueva_votacion2, 1000, netid, arguments, proposals );
}
async function nueva_votacion2( netid, arguments, proposals )
{
await access_accounts();
popup( 'Creating new voting contract.' );
var contract = setup_existing_contract( abiNew, mainaddr[netid] );
if ( ! contract )
return;
var rcpt;
if ( api_version() == 0 )
{
console.log( contract );
try
{
contract.newBallot(
arguments[0], arguments[1], arguments[2], arguments[3],
arguments[4], arguments[5], arguments[6], arguments[7],
proposals, { gas: 2111000 }, contract_created
);
}
catch (error)
{
popup(error);
setTimeout( popup, 5000, '' );
}
}
}
async function contract_created(err,rcpt)
{
popup( err ); // the actual error, or undefined
console.log( rcpt );
if ( !rcpt )
return;
if( !rcpt.address )
// The hash of the transaction, which deploys the contract
console.log( rcpt.transactionHash );
// check address on the second call (contract deployed)
else
console.log( rcpt.address ); // the contract address
//ver_votacion( newaddr );
}
async function ver_votacion( addr )
{
if ( addr == "" )
addr =
document
.getElementById('input_address')
.value;
popup( 'Loading contract details, if possible.' );
if ( addr && addr.length == 40 )
addr = '0x' + addr;
window.web3.eth.getCode( addr, function(err,code) {
if ( err )
{
popup( 'Unable to get bytecode of contract: ' + err );
return;
}
ver_votacion2( addr, code );
});
}
async function ver_votacion2( addr, code )
{
popup( undefined );
console.log( code );
if ( code == '0x' )
{
popup( 'There is no contract at that address' );
return;
}
var keccak3 = window.web3.sha3( code, {'encoding':'hex'} );
console.log( keccak3 );
if ( keccak3 != '0xabcd' )
{
popup( 'There is no recognised Ballot contract at that address.' );
return;
}
var contract = setup_existing_contract( abiBallot, addr );
if ( !contract )
return;
//var detailpromises;
// make sure we have just a single verdiv
//var verdiv;
//while ( verdiv = document.getElementById('verdiv'))
// verdiv.parent.removeChild( verdiv );
//verdiv = addchild( rootdiv, 'div', undefined, { 'id': 'verdiv' });
// Get headline
//var proposaldiv = addchild( verdiv, 'p', 'Proposal:')
//contract.methods.proposal().call( {} )
//.then(
// function showproposal(result)
// {
// proposaldiv.innerHTML = 'Proposal: ' + result;
// },
// function failproposal(err)
// {
// proposaldiv.innerHTML = 'Failed to get proposal: ' + err
// }
//);
}
async function de_acuerdo_y_firmar()
{
access_accounts();
if ( ! accExposed )
return;
// web3.eth.sendTransaction({/* ... */});
}
source diff could not be displayed: it is too large. Options to address this: view the blob.
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