Commit cd8958d2 authored by Robert Martin-Legene's avatar Robert Martin-Legene

Import from Robert

parent 769802c8
// $ 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>
This diff is collapsed.
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