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
09adac96
Commit
09adac96
authored
6 years ago
by
Miguel Braidot
Browse files
Options
Downloads
Patches
Plain Diff
Modificación de SC para devolver address del contrato nuevo
parent
b0e0831a
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
ballot/abi.js
+58
-51
58 additions, 51 deletions
ballot/abi.js
ballot/votar1.js
+37
-10
37 additions, 10 deletions
ballot/votar1.js
solidity/Ballot.sol
+5
-4
5 additions, 4 deletions
solidity/Ballot.sol
with
100 additions
and
65 deletions
ballot/abi.js
+
58
−
51
View file @
09adac96
...
...
@@ -292,55 +292,62 @@ var abiBallot = [
// $ 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
"
}
{
"
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
"
:
[],
"
payable
"
:
false
,
"
stateMutability
"
:
"
nonpayable
"
,
"
type
"
:
"
function
"
},
{
"
anonymous
"
:
false
,
"
inputs
"
:
[
{
"
indexed
"
:
false
,
"
name
"
:
"
contrato
"
,
"
type
"
:
"
address
"
}
],
"
name
"
:
"
contratocreado
"
,
"
type
"
:
"
event
"
}
];
This diff is collapsed.
Click to expand it.
ballot/votar1.js
+
37
−
10
View file @
09adac96
...
...
@@ -2,8 +2,10 @@ var hasplugin = 0;
var
mainaddr
=
{
'
5445
'
:
'
0xe5bf7c3e8aa529e42fbd99428137b68db75d85f9
'
,
'
47525974938
'
:
'
0xe3e08934b6fa0b68972c08e0f545cee31ed039c6
'
'
47525974938
'
:
'
0xe3e08934b6fa0b68972c08e0f545cee31ed039c6
'
,
'
5777
'
:
'
0xC4d36AaA89b75357bd68f2E526f27B277Bd43c23
'
};
var
event
;
window
.
addEventListener
(
'
load
'
,
init1
);
...
...
@@ -23,6 +25,14 @@ async function init2( err, web3 )
hasplugin
=
1
;
window
.
web3
=
web3
;
console
.
log
(
'
window.web3.version.api is
'
+
window
.
web3
.
version
.
api
);
web3
.
eth
.
getAccounts
(
function
(
error
,
accounts
)
{
if
(
error
)
return
console
.
error
(
error
)
console
.
log
(
"
Accounts:
"
+
accounts
);
window
.
web3
.
eth
.
defaultAccount
=
accounts
[
0
];
});
status_start
();
show_section
(
'
startdiv
'
);
update_create_new_ballot
();
...
...
@@ -64,8 +74,12 @@ async function nueva_votacion()
// We get this from status.js
var
netid
=
netinfo
[
'
number
'
];
//
if
(
mainaddr
[
netid
]
==
undefined
)
if
(
mainaddr
[
netid
]
==
undefined
){
console
.
log
(
netinfo
);
alert
(
"
netid undefined
"
);
return
;
}
var
f
=
document
.
forms
[
'
form_create_new_ballot
'
];
var
arguments
=
[];
//
...
...
@@ -97,7 +111,7 @@ async function nueva_votacion()
var
p
;
for
(
var
i
=
1
;
p
=
f
[
'
proposal
'
+
i
];
i
++
)
if
(
p
.
value
!=
''
)
proposals
.
push
(
p
.
value
);
proposals
.
push
(
web3
.
fromAscii
(
p
.
value
)
);
popup
(
'
Trying to access your account.
'
);
setTimeout
(
nueva_votacion2
,
1000
,
netid
,
arguments
,
proposals
);
}
...
...
@@ -113,13 +127,23 @@ async function nueva_votacion2( netid, arguments, proposals )
if
(
api_version
()
==
0
)
{
console
.
log
(
contract
);
console
.
log
(
arguments
,
proposals
);
try
{
contract
.
newBallot
(
//var thatnewcontractaddress =
event
=
contract
.
contratocreado
();
event
.
watch
(
function
(
error
,
result
){
if
(
!
error
){
console
.
log
(
result
);
popup
(
result
.
args
.
contrato
);
// the contract address
}
});
contract
.
newBallot
.
sendTransaction
(
arguments
[
0
],
arguments
[
1
],
arguments
[
2
],
arguments
[
3
],
arguments
[
4
],
arguments
[
5
],
arguments
[
6
],
arguments
[
7
],
proposals
,
{
gas
:
2111000
},
contract_created
);
//console.log( thatnewcontractaddress);
}
catch
(
error
)
{
...
...
@@ -128,19 +152,19 @@ async function nueva_votacion2( netid, arguments, proposals )
}
}
}
async
function
contract_created
(
err
,
rcpt
)
{
popup
(
err
);
// the actual error, or undefined
console
.
log
(
rcpt
);
//console.log(web3.eth.getTransactionReceipt(rcpt));
web3
.
eth
.
getTransactionReceipt
(
rcpt
);
if
(
!
rcpt
)
return
;
if
(
!
rcpt
.
address
)
// The hash of the transaction, which deploys the contract
console
.
log
(
rcpt
.
transactionHash
);
console
.
log
(
"
Transaction hash:
"
,
rcpt
.
transactionHash
);
// check address on the second call (contract deployed)
else
console
.
log
(
rcpt
.
address
);
// the contract address
console
.
log
(
"
Transaction address:
"
,
rcpt
.
address
);
// the contract address
//ver_votacion( newaddr );
}
...
...
@@ -175,14 +199,17 @@ async function ver_votacion2( addr, code )
}
var
keccak3
=
window
.
web3
.
sha3
(
code
,
{
'
encoding
'
:
'
hex
'
}
);
console
.
log
(
keccak3
);
if
(
keccak3
!=
'
0xabcd
'
)
//if ( keccak3 != '0xabcd' )
if
(
keccak3
!=
'
0xca753fe72f9141d87c626c29a766381187dbf6fd350319cd6ba8c62b00040154
'
)
{
popup
(
'
There is no recognised Ballot contract at that address.
'
);
return
;
}
var
contract
=
setup_existing_contract
(
abiBallot
,
addr
);
if
(
!
contract
)
if
(
!
contract
)
{
return
;
}
//var detailpromises;
// make sure we have just a single verdiv
//var verdiv;
...
...
This diff is collapsed.
Click to expand it.
solidity/Ballot.sol
+
5
−
4
View file @
09adac96
...
...
@@ -2,7 +2,7 @@
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
pragma solidity >= 0.5.
2
;
pragma solidity >= 0.5.
1
;
/// @title A single ballot contract which allows certain
/// @title accounts to vote (one single vote).
...
...
@@ -176,6 +176,7 @@ contract Ballot
contract NewBallot
{
event contratocreado(address contrato);
function newBallot(
string memory title,
uint voteStarts,
...
...
@@ -188,11 +189,10 @@ contract NewBallot
bytes32[] memory proposalNames
)
public
returns (Ballot newaddr)
{
// Create a new ballot contract. Returns the new contract's address.
// tx.origin will be ballotChairman ("owner") of that contract.
return
new Ballot(
address ballot = address(
new Ballot(
title,
voteStarts,
voteBefore,
...
...
@@ -202,6 +202,7 @@ contract NewBallot
maxVotesPerVoter,
maxVotesPerProposal,
proposalNames
);
));
emit contratocreado(ballot);
}
}
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