From 2253f6de633c3e8b4fb6df4ee05b11d9aeac8452 Mon Sep 17 00:00:00 2001 From: Robert Martin-Legene <robert@nic.ar> Date: Tue, 25 Sep 2018 17:25:47 -0300 Subject: [PATCH] Minor optimizations --- .gitignore | 1 + bin/compile.and.deploy.contract | 2 +- bin/libbfa.js | 7 ++++--- src/Sealers.sol | 20 ++++++++------------ 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 8ab0fc9..373f742 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ */status cache */cache +network5445/contracts/* diff --git a/bin/compile.and.deploy.contract b/bin/compile.and.deploy.contract index f7a36c0..9b5c967 100755 --- a/bin/compile.and.deploy.contract +++ b/bin/compile.and.deploy.contract @@ -32,7 +32,7 @@ var address = rcpt.contractAddress var pubcontract = mycontract.at(address) console.log( pubcontract.address ) EOT - echo '*** Creating contract. This will take at least 16 seconds.' + echo '*** Creating contract. Please stand by.' outfile=$( mktemp ) cleanup "$outfile" geth_exec_file $js > $outfile diff --git a/bin/libbfa.js b/bin/libbfa.js index 4af1f41..c542be6 100644 --- a/bin/libbfa.js +++ b/bin/libbfa.js @@ -125,9 +125,10 @@ module.exports = class Libbfa var contractaddress = this.fs.realpathSync( contractdir ).replace(/^.*\//, ''); if ( contractaddress == undefined ) return; - var abi = JSON.parse( - this.fs.readFileSync( contractdir + '/abi' ).toString() - ); + var abistr = this.fs.readFileSync( contractdir + '/abi' ).toString(); + if ( abistr == undefined ) + return; + var abi = JSON.parse( abistr ); if ( abi == undefined ) return; var c = new w3.eth.Contract( abi, contractaddress ); diff --git a/src/Sealers.sol b/src/Sealers.sol index 0d53918..bfdecdd 100644 --- a/src/Sealers.sol +++ b/src/Sealers.sol @@ -13,16 +13,16 @@ contract Sealers { struct Proposal { address victim; // Whom are we voting about. uint votestart; // In which block did this vote begin? - bool promotion; // true=promotion, false=demotion - address[] voters; // List of voters. + bool promotion; // true=promotion, false=demotion + address[] voters; // List of voters. } - address[] public sealers; - Proposal[] public sealerproposals; + address[] private sealers; + Proposal[] private sealerproposals; event voteCast( address voter, address victim, bool promotionOrDemotion ); event adminChange( address admin, bool promotionOrDemotion ); - constructor() public + constructor() public { sealers.push( msg.sender ); } @@ -47,11 +47,6 @@ contract Sealers { return ( _findAddressInList( sealers, subject ) > 0 ); } - function requireSealer( address subject ) public view - { - require( isSealer(subject), "Not sealer" ); - } - // Returns an index to the position of the needle inside haystack. // Beware that: // 0 = not found. @@ -197,12 +192,13 @@ contract Sealers { // Is already Sealer and want to promote him? // Can't promote someone who is already a sealer. - if ( isSealer(victim) && promotion ) + bool victimSealer = isSealer( victim ); + if ( victimSealer && promotion ) return false; // Is not Sealer and want to demote him? // Can't demote someone who is not a sealer. - if ( !isSealer(victim) && !promotion ) + if ( !victimSealer && !promotion ) return false; // See if the voter is already in the list of voters for this [victim,promotion] tuple -- GitLab