Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Votacion
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
Votacion
Commits
7a55c380
Commit
7a55c380
authored
5 years ago
by
Miguel Braidot
Browse files
Options
Downloads
Patches
Plain Diff
El formulario de votación se llena con las opciones del SC
parent
eb7dce85
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
web/dist/index.html
+3
-3
3 additions, 3 deletions
web/dist/index.html
web/dist/js/vendor/ballot.js
+113
-60
113 additions, 60 deletions
web/dist/js/vendor/ballot.js
web/dist/smartVotar.html
+16
-21
16 additions, 21 deletions
web/dist/smartVotar.html
with
132 additions
and
84 deletions
web/dist/index.html
+
3
−
3
View file @
7a55c380
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
<i
class=
"fas fa-plus"
aria-hidden=
"true"
></i>
<i
class=
"fas fa-plus"
aria-hidden=
"true"
></i>
</span>
</span>
</a>
</a>
<form
action=
""
>
<form
action=
"
smartVotar.html
"
>
<div
class=
"alert alert-danger"
role=
"alert"
id=
"errorForm"
>
<div
class=
"alert alert-danger"
role=
"alert"
id=
"errorForm"
>
<p>
Comprobá los siguientes errores del formulario:
</p>
<p>
Comprobá los siguientes errores del formulario:
</p>
<ul></ul>
<ul></ul>
...
@@ -111,8 +111,8 @@
...
@@ -111,8 +111,8 @@
},
},
submitHandler
:
function
(
form
)
{
submitHandler
:
function
(
form
)
{
// do other things for a valid form
// do other things for a valid form
//
form.submit();
form
.
submit
();
ver_votacion
(
''
);
//
ver_votacion('');
},
},
messages
:
{
messages
:
{
input_address
:
{
input_address
:
{
...
...
This diff is collapsed.
Click to expand it.
web/dist/js/vendor/ballot.js
+
113
−
60
View file @
7a55c380
...
@@ -219,6 +219,17 @@ function setup_existing_contract(abi, addr) {
...
@@ -219,6 +219,17 @@ function setup_existing_contract(abi, addr) {
return
;
return
;
}
}
function
setup_existing_instance
(
abi
,
addr
)
{
if
(
api_version
()
==
0
)
{
var
MyContract
=
window
.
web3
.
eth
.
contract
(
abi
);
console
.
log
(
MyContract
);
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
;
}
function
add_proposal
(
pos
)
{
function
add_proposal
(
pos
)
{
var
div
=
document
.
getElementById
(
'
newtable
'
);
var
div
=
document
.
getElementById
(
'
newtable
'
);
if
(
!
div
)
if
(
!
div
)
...
@@ -386,53 +397,18 @@ async function nueva_votacion(arguments,proposals) {
...
@@ -386,53 +397,18 @@ async function nueva_votacion(arguments,proposals) {
if
(
mainaddr
[
netid
]
==
undefined
)
if
(
mainaddr
[
netid
]
==
undefined
)
return
;
return
;
//var f = document.forms['form_create_new_ballot'];
/*var arguments = [];
arguments.push(document.getElementById('_title').value);
arguments.push(document.getElementById('start_date').value);
arguments.push(document.getElementById('voteBefore').value);
arguments.push(document.getElementById('percentOfRegisteredVotersReqToBeValid').value);
arguments.push(document.getElementById('percentOfVotesCastToWin').value);
arguments.push(document.getElementById('countNonvotesAsBlanks').value);
arguments.push(document.getElementById('maxVotesPerVoter').value);
arguments.push(document.getElementById('maxVotesPerProposal').value);
var p;
var proposals = [];
for (var i = 1; p = document.getElementById('proposal' + i); i++){
proposals.push(web3.fromAscii(p.value));
}*/
for
(
var
i
=
0
;
i
<
proposals
.
length
;
i
++
){
for
(
var
i
=
0
;
i
<
proposals
.
length
;
i
++
){
proposals
[
i
]
=
web3
.
fromAscii
(
proposals
[
i
]);
proposals
[
i
]
=
web3
.
fromAscii
(
proposals
[
i
]);
}
}
//var newdiv = document.getElementById('newcontract');
//var localstatus = addchild(newdiv, 'p', 'Trying to access your account.');
alertarLoading
(
'
Trying to access your account.
'
);
alertarLoading
(
'
Trying to access your account.
'
);
await
access_accounts
();
await
access_accounts
();
//localstatus.innerHTML = 'Creating new voting contract.';
alertarLoading
(
'
Creating new voting contract.
'
);
alertarLoading
(
'
Creating new voting contract.
'
);
var
contract
=
setup_existing_contract
(
abiNew
,
mainaddr
[
netid
]);
var
contract
=
setup_existing_contract
(
abiNew
,
mainaddr
[
netid
]);
if
(
!
contract
)
if
(
!
contract
)
return
;
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
);*/
console
.
log
(
arguments
,
proposals
);
console
.
log
(
arguments
,
proposals
);
try
try
{
{
...
@@ -459,9 +435,6 @@ async function nueva_votacion(arguments,proposals) {
...
@@ -459,9 +435,6 @@ async function nueva_votacion(arguments,proposals) {
async
function
contract_created
(
err
,
rcpt
)
{
async
function
contract_created
(
err
,
rcpt
)
{
console
.
log
(
rcpt
);
console
.
log
(
rcpt
);
/*if (!rcpt)
return;*/
//ver_votacion( newaddr );
}
}
async
function
ver_votacion
(
addr
)
{
async
function
ver_votacion
(
addr
)
{
...
@@ -481,6 +454,7 @@ async function ver_votacion(addr) {
...
@@ -481,6 +454,7 @@ async function ver_votacion(addr) {
ver_votacion2
(
addr
,
code
);
ver_votacion2
(
addr
,
code
);
});
});
}
}
async
function
ver_votacion2
(
addr
,
code
)
{
async
function
ver_votacion2
(
addr
,
code
)
{
console
.
log
(
'
Contract code
'
,
code
);
console
.
log
(
'
Contract code
'
,
code
);
if
(
code
==
'
0x
'
)
{
if
(
code
==
'
0x
'
)
{
...
@@ -491,33 +465,107 @@ async function ver_votacion2(addr, code) {
...
@@ -491,33 +465,107 @@ async function ver_votacion2(addr, code) {
'
encoding
'
:
'
hex
'
'
encoding
'
:
'
hex
'
});
});
console
.
log
(
'
keccak3:
'
,
keccak3
);
console
.
log
(
'
keccak3:
'
,
keccak3
);
if
(
keccak3
!=
ballot_keccak3
)
{
/*
if (keccak3 != ballot_keccak3) {
alertar('No hay una votación en esa dirección.');
alertar('No hay una votación en esa dirección.');
return;
return;
}
}
*/
var
contract
=
setup_existing_
contract
(
abiBallot
,
addr
);
var
contract
=
setup_existing_
instance
(
abiBallot
,
addr
);
if
(
!
contract
)
if
(
!
contract
)
return
;
return
;
var
detailpromises
;
// make sure we have just a single verdiv
try
var
verdiv
;
{
while
(
verdiv
=
document
.
getElementById
(
'
verdiv
'
))
// Getting the title
verdiv
.
parent
.
removeChild
(
verdiv
);
contract
.
ballotTitle
.
call
({
gas
:
2111000
},
getBallotTitle
);
verdiv
=
addchild
(
rootdiv
,
'
div
'
,
undefined
,
{
// Getting the proposal list
'
id
'
:
'
verdiv
'
// @TODO: get the proposal mapping's length
});
contract
.
proposalList
.
call
(
0
,
{
gas
:
2111000
},
getProposalList
);
// Get headline
contract
.
proposalList
.
call
(
1
,
{
gas
:
2111000
},
getProposalList
);
var
proposaldiv
=
addchild
(
verdiv
,
'
p
'
,
'
Proposal:
'
)
// Getting the ballot dates
contract
.
methods
.
proposal
().
call
({})
contract
.
ballotVoteStarts
.
call
({
gas
:
2111000
},
getBallotVoteStarts
);
.
then
(
contract
.
ballotVoteBefore
.
call
({
gas
:
2111000
},
getBallotVoteBefore
);
function
showproposal
(
result
)
{
proposaldiv
.
innerHTML
=
'
Proposal:
'
+
result
;
close_alertar
();
},
function
failproposal
(
err
)
{
}
proposaldiv
.
innerHTML
=
'
Failed to get proposal:
'
+
err
catch
(
error
)
}
{
);
alertar
(
error
);
}
}
///////////////////////////////////////////////////////////
// UTILS for ballot form creation
///////////////////////////////////////////////////////////
async
function
getBallotVoteStarts
(
err
,
rcpt
){
if
(
err
){
alertar
(
err
);
}
else
{
$
(
'
#comienza_votacion
'
).
text
(
getDateFromTimestamp
(
rcpt
));
var
today
=
new
Date
();
if
(
rcpt
>
today
.
getTime
()){
$
(
"
#form_votacion :input
"
).
prop
(
"
disabled
"
,
true
);
alertar
(
"
La votación no ha comenzado aún.
"
);
}
}
}
async
function
getBallotVoteBefore
(
err
,
rcpt
){
if
(
err
){
alertar
(
err
);
}
else
{
$
(
'
#termina_votacion
'
).
text
(
getDateFromTimestamp
(
rcpt
));
var
today
=
new
Date
();
if
(
rcpt
<
today
.
getTime
()){
$
(
"
#form_votacion :input
"
).
prop
(
"
disabled
"
,
true
);
alertar
(
"
La votación ha finalizado.
"
);
}
}
}
async
function
getBallotTitle
(
err
,
rcpt
){
if
(
err
){
alertar
(
err
);
}
else
{
$
(
'
#titulo_votacion
'
).
text
(
rcpt
);
}
}
async
function
getProposalList
(
err
,
rcpt
){
if
(
err
){
alertar
(
err
);
}
else
{
var
num
=
$
(
'
#proposals div
'
).
length
;
var
element
=
'
<div class="radio">
\
<input type="radio" name="votacion" id="vote_
'
+
num
+
'
" required="required" aria-required="true">
\
<label for="vote_
'
+
num
+
'
">
'
+
hex2ascii
(
rcpt
)
+
'
</label>
\
</div>
'
;
$
(
'
#proposals
'
).
append
(
element
);
}
}
function
hex2ascii
(
hexx
)
{
var
hex
=
hexx
.
toString
();
var
str
=
''
;
for
(
var
i
=
0
;
(
i
<
hex
.
length
&&
hex
.
substr
(
i
,
2
)
!==
'
00
'
);
i
+=
2
)
str
+=
String
.
fromCharCode
(
parseInt
(
hex
.
substr
(
i
,
2
),
16
));
return
str
;
}
}
function
pad
(
str
,
max
)
{
str
=
str
.
toString
();
return
str
.
length
<
max
?
pad
(
"
0
"
+
str
,
max
)
:
str
;
}
function
getDateFromTimestamp
(
timestamp
){
var
date_timestamp
=
new
Date
(
parseInt
(
timestamp
));
var
date
=
pad
(
date_timestamp
.
getDate
(),
2
)
+
'
-
'
+
pad
(
date_timestamp
.
getMonth
()
+
1
,
2
)
+
'
-
'
+
date_timestamp
.
getFullYear
()
+
'
'
;
date
+=
pad
(
date_timestamp
.
getHours
(),
2
)
+
'
:
'
+
pad
(
date_timestamp
.
getMinutes
(),
2
)
+
'
:
'
+
pad
(
date_timestamp
.
getSeconds
(),
2
)
+
'
Hs.
'
;
return
date
;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
function
access_accounts
()
{
function
access_accounts
()
{
if
(
gotEth
)
{
if
(
gotEth
)
{
...
@@ -565,4 +613,9 @@ function alertarSuccess(err){
...
@@ -565,4 +613,9 @@ function alertarSuccess(err){
document
.
getElementById
(
'
alert-wrapper
'
).
innerHTML
=
'
<div class="alert alert-success" role="alert" id="alert"><i class="fas fa-check" aria-hidden="true"></i> <span id="alert-content"></span></div>
'
;
document
.
getElementById
(
'
alert-wrapper
'
).
innerHTML
=
'
<div class="alert alert-success" role="alert" id="alert"><i class="fas fa-check" aria-hidden="true"></i> <span id="alert-content"></span></div>
'
;
document
.
getElementById
(
'
alert-content
'
).
innerHTML
=
err
;
document
.
getElementById
(
'
alert-content
'
).
innerHTML
=
err
;
document
.
getElementById
(
'
alert
'
).
style
.
display
=
"
block
"
;
document
.
getElementById
(
'
alert
'
).
style
.
display
=
"
block
"
;
}
function
close_alertar
(){
document
.
getElementById
(
'
alert-content
'
).
innerHTML
=
''
;
document
.
getElementById
(
'
alert
'
).
style
.
display
=
"
none
"
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
web/dist/smartVotar.html
+
16
−
21
View file @
7a55c380
...
@@ -32,12 +32,16 @@
...
@@ -32,12 +32,16 @@
<div
id=
"alert-wrapper"
></div>
<div
id=
"alert-wrapper"
></div>
<div
id=
"voterow"
class=
"row hide"
>
<div
id=
"voterow"
class=
"row hide"
>
<section>
<section>
<h1
class=
"page-header"
>
Título de la votación
</h1>
<h1
class=
"page-header"
id=
"titulo_votacion"
>
Título de la votación
</h1>
<p
class=
"max-container"
><b>
Dirección:
</b>
0xe3e08934b6fa0b68972c08e0f545cee31ed039
<p
class=
"max-container"
><b>
Dirección:
</b>
<span
id=
"contract_address"
>
0xe3e08934b6fa0b68972c08e0f545cee31ed039
</span>
<a
class=
"btn-default btn btn-lg btn-address"
aria-label=
"Cambiar dirección"
href=
"
smartVote
.html"
>
<a
class=
"btn-default btn btn-lg btn-address"
aria-label=
"Cambiar dirección"
href=
"
index
.html"
>
Cambiar
Cambiar
</a>
</a>
</p>
</p>
<p
class=
"max-container"
>
<b>
Comienza:
</b>
<span
id=
"comienza_votacion"
></span><br
/>
<b>
Termina:
</b>
<span
id=
"termina_votacion"
></span>
</p>
<div
class=
"resultados"
style=
"display: none;"
>
<div
class=
"resultados"
style=
"display: none;"
>
<h2>
Resultados
</h2>
<h2>
Resultados
</h2>
<div
class=
"res_op"
>
<div
class=
"res_op"
>
...
@@ -110,29 +114,13 @@
...
@@ -110,29 +114,13 @@
</table>
</table>
</div>
</div>
<form
action=
""
>
<form
action=
""
id=
"form_votacion"
>
<div
class=
"alert alert-danger"
role=
"alert"
id=
"errorForm"
>
<div
class=
"alert alert-danger"
role=
"alert"
id=
"errorForm"
>
<p>
Comprobá los siguientes errores del formulario:
</p>
<p>
Comprobá los siguientes errores del formulario:
</p>
<ul></ul>
<ul></ul>
</div>
</div>
<fieldset
class=
"form-group votar"
>
<fieldset
class=
"form-group votar"
id=
"proposals"
>
<legend>
Opciones para votar
</legend>
<legend>
Opciones para votar
</legend>
<div
class=
"radio"
>
<input
type=
"radio"
name=
"votacion"
id=
"vote_0"
required=
"required"
aria-required=
"true"
>
<label
for=
"vote_0"
>
Opción 1
</label>
</div>
<div
class=
"radio"
>
<input
type=
"radio"
name=
"votacion"
id=
"vote_1"
>
<label
for=
"vote_1"
>
Opción 2
</label>
</div>
<div
class=
"radio"
>
<input
type=
"radio"
name=
"votacion"
id=
"vote_3"
>
<label
for=
"vote_3"
>
Opción 3
</label>
</div>
<div
class=
"radio"
>
<input
type=
"radio"
name=
"votacion"
id=
"vote_4"
>
<label
for=
"vote_4"
>
Opción 4
</label>
</div>
</fieldset>
</fieldset>
<div
class=
"form-group col-sm-6 col-sm-push-6"
>
<div
class=
"form-group col-sm-6 col-sm-push-6"
>
<button
class=
"btn-primary btn btn-block"
type=
"submit"
id=
"submit"
>
Votar
</button>
<button
class=
"btn-primary btn btn-block"
type=
"submit"
id=
"submit"
>
Votar
</button>
...
@@ -185,6 +173,13 @@
...
@@ -185,6 +173,13 @@
var
container
=
$
(
'
#errorForm
'
);
var
container
=
$
(
'
#errorForm
'
);
var
url
=
new
URL
(
window
.
location
.
href
);
var
input_address
=
url
.
searchParams
.
get
(
"
input_address
"
);
if
(
typeof
input_address
!=
"
undefined
"
&&
input_address
!=
""
){
$
(
"
#contract_address
"
).
text
(
input_address
);
ver_votacion
(
input_address
);
}
$
(
"
form
"
).
validate
({
$
(
"
form
"
).
validate
({
focusInvalid
:
false
,
focusInvalid
:
false
,
errorContainer
:
container
,
errorContainer
:
container
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment