Skip to content
Snippets Groups Projects
Commit 38eefbfd authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Unlocking feature now works. Also snuck in a few new features.

parent 0c21660d
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
set -x
cd ${BFAHOME}
git pull
npm rebuild
......@@ -81,32 +81,39 @@ module.exports = class Libbfa
w3.eth.extend({
//property: 'bfaclique',
methods: [{
name: 'getSigners',
name: 'bfaGetSigners',
call: 'clique_getSigners',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'minerstart',
name: 'bfaMinerstart',
call: 'miner_start',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'minerstop',
name: 'bfaMinerstop',
call: 'miner_stop',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'adminpeers',
name: 'bfaAdminpeers',
call: 'admin_peers',
params: 0
}]
});
w3.eth.personal.extend({
methods: [{
name: 'bfalistWallets',
call: 'personal_listWallets',
params: 0
}]
});
if ( undefined != process.env.BFAACCOUNT ) {
w3.eth.defaultAccount = this.account;
}
......
......@@ -5,16 +5,15 @@
"use strict"
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
var bfa = new Libbfa();
var web3 = bfa.newweb3();
var now;
function monitor()
{
var bfa = new Libbfa();
var web3 = bfa.newweb3();
var now = new Date();
//console.log(web3.eth);
web3.eth.adminpeers().then(
function(nodelist) {
var peers = [];
web3.eth.bfaAdminpeers().then(
function gotAdminPeers( nodelist ) {
var peers = [];
nodelist.forEach(
function(node) {
if ( typeof(node.protocols.eth) == 'object' )
......@@ -34,12 +33,73 @@ function monitor()
{ mode: 0o644 }
);
},
function(x)
function failedToGetAdminPeers(x)
{
console.log( x );
process.exit(1)
}
);
}
monitor();
// Function to determine if our defaultAccount is allowed to seal/mine.
// It will adjust the behaviour accordingly, i.e. stop or start mining.
function mayseal()
{
var me = web3.eth.defaultAccount;
if ( undefined == me )
{
console.log( "Failed to get default account information." );
return;
}
me = me.toLowerCase();
web3.eth.isMining().
then(
// returns a boolean whether or not we are currently mining/sealing.
function( isMining )
{
// Get a list of clique.getSigners, so we can see if we are
// in the list of authorized sealers.
web3.eth.bfaGetSigners()
.then(
function gotListOfSealers(x)
{
var lcsealers = x.map( name => name.toLowerCase() );
var isSigner = (lcsealers.indexOf(me) > -1);
if ( isSigner )
{
if ( ! isMining )
{
console.log( 'Started to seal.' );
web3.eth.bfaMinerstart();
}
}
else
{
if ( isMining )
{
console.log( 'I was trying to seal, but am not authorized. Stopped trying.' );
web3.eth.bfaMinerstop();
}
}
},
function failedToGetListOfSealers(x)
{
console.log(x);
}
);
},
function failedToGetIsMiningBool(x)
{
// Probably geth is not running.
console.log(x);
}
);
}
function timer()
{
now = new Date();
monitor();
mayseal();
}
setInterval( timer, 60 * 1000 );
......@@ -14,39 +14,11 @@ enodeDGSI="59ae768ecdee632e0daceccb6f71b215392eba89230d626573f2fb4e9c0786c9a6610
bootDGSIv4="enode://${enodeDGSI}@[200.108.146.100]:30301"
bootnodes="${bootARIUv6},${bootARIUv4},${bootUNCv4},${bootDGSIv4}"
function accountlist
{
local accts=
local filename
for filename in ${BFANODEDIR}/keystore/*--*
do
if [ -r "$filename" -a ${#filename} -ge 40 ]
then
acct=${filename:$(( ${#filename} - 40 ))}
accts="${accts},${acct}"
fi
done
# strip leading comma
accts=${accts#,}
if [ ${#accts} -ge 40 ]
then
echo "--password /dev/null --unlock ${accts}"
fi
}
# touch the "miner" file if you are authorized to mine
# If you don't want to restart after touching the file,
# you can use attach.sh and issue the command:
# miner.start()
function getminer
{
if [ -e "${BFANODEDIR}/miner" ]
then
echo "--mine"
fi
}
function getsyncmode
{
local syncmode=$( cat "${BFANODEDIR}/syncmode" 2>/dev/null || true )
......@@ -96,17 +68,9 @@ function startmonitor
echo "A monitor is already running."
false
) || exit
if [ -t 1 ]
then
echo Running monitor every 60 seconds.
fi
while :
do
monitor.js &
echo $! > $pidfile
wait
sleep 60
done &
monitor.js &
echo $! > $pidfile
wait
) 9>> $pidfile
}
......@@ -134,12 +98,11 @@ function startgeth
echo '***'
echo
# (re)configure parameters (you never know if they changed)
flexargs="$( accountlist) $( getminer ) $( getsyncmode ) --extradata $( extradata )"
flexargs="$( getsyncmode ) --extradata $( extradata )"
set -x
geth \
--datadir ${BFANODEDIR} \
--networkid ${BFANETWORKID} \
--bootnodes "${bootnodes}" \
--rpc \
--rpcport $rpcport \
--rpcapi "eth,net,web3,admin,clique,miner,personal" \
......@@ -148,7 +111,8 @@ function startgeth
--gcmode archive \
--cache 512 \
--verbosity ${BFAVERBOSITY:-3} \
${flexargs} &
${flexargs} \
--bootnodes "${bootnodes}" &
set +x
echo $! > ${BFANODEDIR}/geth.pid
wait
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment