diff --git a/.gitignore b/.gitignore index ee0322267ff5269444f8832f046b992c23da9732..d94a031649a960be7963f2ea78a5f2842aa45053 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ */status cache */cache -network/node -network/bootnode +network*/node +network*/bootnode +network*/contracts/* diff --git a/bin/MasterDistiller.js b/bin/MasterDistiller.js index 1fcabecc2becf1f6e8215fe7f3ee419f9b29e263..c7deec68f64b8d9ce450fe7e760356a978c66845 100755 --- a/bin/MasterDistiller.js +++ b/bin/MasterDistiller.js @@ -1,5 +1,7 @@ #!/usr/bin/node +"use strict" + const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js'); const rl = require('readline').createInterface( { input: process.stdin, output: process.stdout } @@ -11,7 +13,7 @@ var notation = [ 6 ]; function init() { - notation.push( 10**notation[0] ); + notation.push( Math.pow(10, notation[0]) ); switch ( notation[0] ) { case 6: notation.push( "Mwei" ); @@ -20,11 +22,13 @@ function init() notation.push( "Gwei" ); break; default: - notation = [ 6, 10**6, "Mwei" ]; + notation = [ 6, Math.pow(10, 6), "Mwei" ]; } bfa = new Libbfa(); web3 = bfa.newweb3(); Distillery = bfa.contract( web3, 'Distillery' ); + if ( undefined == Distillery ) + fatal('Can not initialise Distillery contact.'); web3.eth.getBalance( Distillery.contractaddress ).then( function receivedOwnBalance(val) { Distillery.contractbalance = val; @@ -128,7 +132,7 @@ function editAccount( entry, pallet ) if ( entry == "x" ) { // trigger distribution - Distillery.methods.distribute().send( {"from": bfa.account, "gas": 1000000 } ) + Distillery.methods.distribute().send( {"from": bfa.account, "gas": 4000000 } ) .then( function distOK(x) { console.log( @@ -155,7 +159,15 @@ function editAccount( entry, pallet ) return; } else + if ( entry == "" ) + { + // Do nothing, basically just update the display + return; + } + else + { bfa.fatal("I don't know what to do with \""+entry+"\"." ); + } rl.question( "Adjust the " + notation[2] diff --git a/bin/libbfa.js b/bin/libbfa.js index 1308def06894ad6f04c96628db3cd60be8b9ee96..6bab557a5bc15c557432463acb5c0dc1468c3726 100644 --- a/bin/libbfa.js +++ b/bin/libbfa.js @@ -1,62 +1,70 @@ // 20180724 Robert Martin-Legene <robert@nic.ar> +"use strict" + module.exports = class Libbfa { constructor() { - this.fs = require('fs'); - this.Web3 = require('web3'); + this.fs = require('fs'); + this.Web3 = require('web3'); // // BFAHOME if ( undefined == process.env.BFAHOME ) fatal( "$BFAHOME not set. Did you source bfa/bin/env ?" ); // BFANETWORKID + this.home = process.env.BFAHOME; if ( undefined == process.env.BFANETWORKID ) - process.env.BFANETWORKID= 47525974938; + process.env.BFANETWORKID = 47525974938; + this.networkid = process.env.BFANETWORKID; // BFANETWORKDIR if ( undefined == process.env.BFANETWORKDIR ) - process.env.BFANETWORKDIR = process.env.BFAHOME + '/network'; + process.env.BFANETWORKDIR = process.env.BFAHOME + '/network'; + this.networkdir = process.env.BFANETWORKDIR; // BFANODEDIR if ( undefined == process.env.BFANODEDIR ) - process.env.BFANODEDIR = this.networkdir + "/node"; + process.env.BFANODEDIR = this.networkdir + "/node"; + this.nodedir = process.env.BFANODEDIR; // ACCOUNT if ( undefined == process.env.BFAACCOUNT ) { var files = new Array(); - this.fs.readdirSync( process.env.BFANODEDIR + '/keystore' ).forEach( function(filename) { - if ( filename.includes('--') ) - files.push( filename ); - }); + if ( this.fs.existsSync( process.env.BFANODEDIR + '/keystore' ) ) + { + this.fs.readdirSync( process.env.BFANODEDIR + '/keystore' ).forEach( function(filename) { + if ( filename.includes('--') ) + files.push( filename ); + }); + } // found none? - if ( files.length == 0 ) - fatal( "Found no accounts in your keystore." ); - files.sort(); - process.env.BFAACCOUNT = '0x' + files[0].replace( /^.*--/, '' ); + if ( files.length > 0 ) + { + files.sort(); + process.env.BFAACCOUNT = '0x' + files[0].replace( /^.*--/, '' ); + } } // - this.home = process.env.BFAHOME; - this.networkid = process.env.BFANETWORKID; - this.networkdir = process.env.BFANETWORKDIR; - this.nodedir = process.env.BFANODEDIR; - this.netport = Number.parseInt( this.setfromfile( this.nodedir+'/netport', 30303 ); - this.rpcport = Number.parseInt( this.setfromfile( this.nodedir+'/rpcport', 8545 ); - this.account = process.env.BFAACCOUNT; + this.netport = Number.parseInt( this.setfromfile( this.nodedir+'/netport', 30303 )); + this.rpcport = Number.parseInt( this.setfromfile( this.nodedir+'/rpcport', 8545 )); + this.account = process.env.BFAACCOUNT; } contract(w3, name) { - this._networkdir(); - var contractdir = [ this.networkdir, 'contracts', name ].join('/'); - var contractaddress = this.fs.realpathSync( contractdir ).replace(/^.*\//, ''); + var contractdir = [ this.networkdir, 'contracts', name ].join('/'); + if ( ! this.fs.existsSync( contractdir ) ) + return; + var contractaddress = this.fs.realpathSync( contractdir ).replace(/^.*\//, ''); if ( undefined == contractaddress ) return; - var abi = JSON.parse( - this.fs.readFileSync( contractdir + '/abi' ).toString() - ); + var abistr = this.fs.readFileSync( contractdir + '/abi' ).toString(); + if ( undefined == abistr ) + return; + var abi = JSON.parse( abistr ); if ( undefined == abi ) return; - var c = new w3.eth.Contract( abi, contractaddress ); - c.abi = abi; - c.contractaddress = contractaddress; + var c = new w3.eth.Contract( abi, contractaddress ); + c.abi = abi; + c.contractaddress = contractaddress; return c; } @@ -68,9 +76,8 @@ module.exports = class Libbfa newweb3() { - this._nodedir(); - var provider = 'http://127.0.0.1:' + this.rpcport; - var w3 = new this.Web3( provider ); + var provider = 'http://127.0.0.1:' + this.rpcport; + var w3 = new this.Web3( provider ); w3.eth.extend({ //property: 'bfaclique', methods: [{ @@ -79,6 +86,9 @@ module.exports = class Libbfa params: 0 }] }); + if ( undefined != process.env.BFAACCOUNT ) { + w3.eth.defaultAccount = this.account; + } return w3; } isNumeric(n) { @@ -91,7 +101,7 @@ module.exports = class Libbfa setfromfile( filename, defval ) { - if ( this.fs.statSync( filename ).isFile() ) + if ( this.fs.existsSync( filename ) ) return this.fs.readFileSync( filename ); return defval; } diff --git a/src/Sealers.sol b/src/Sealers.sol index 0d5391880c70287c2a6e8447c4413c79e1afbc72..bfdecdd62114bce247d237d357baeaceb9db7f3f 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