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

maymine.sh ahora es mayseal.js

parent a881b85e
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,20 @@ module.exports = class Libbfa
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'minerstart',
call: 'miner_start',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'minerstop',
call: 'miner_stop',
params: 0
}]
});
if ( undefined != process.env.BFAACCOUNT ) {
w3.eth.defaultAccount = this.account;
}
......
#!/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
res=$( geth_exec_file "${BFAHOME}/src/maymine.js" )
if [ "$res" = "true" ]
then
touch ${BFANODEDIR}/miner
else
rm -f ${BFANODEDIR}/miner
fi
#!/usr/bin/node
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
"use strict"
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
function mayseal()
{
var bfa = new Libbfa();
var web3 = bfa.newweb3();
var me = web3.eth.defaultAccount.toLowerCase();
web3.eth.isMining().then( function(isMining){
web3.eth.getSigners().then( function(x){
var lcsealers = x.map( name => name.toLowerCase() );
// console.log( "Miners are:\n\t" + lcsealers.join("\n\t") );
var isSigner = (lcsealers.indexOf(me) > -1);
var sealerfile = bfa.nodedir + '/miner';
var not = "not ";
if ( isSigner )
not = "";
console.log( "Account " + me + " is " + not + "allowed to seal." );
if ( isSigner )
{
if ( ! bfa.fs.existsSync( sealerfile ) )
{
var fd = bfa.fs.openSync( sealerfile, 'a' );
bfa.fs.close( fd );
console.log( "Created 'sealer' file " + sealerfile );
}
if ( ! isMining )
{
web3.eth.minerstart();
console.log( 'Started to seal.' );
}
else
{
console.log( "You are already sealing. All is well." );
}
}
else
{
if ( bfa.fs.existsSync( sealerfile ) )
{
bfa.fs.unlinkSync( sealerfile );
console.log( "Deleted 'sealer' file " + sealerfile );
}
if ( isMining )
{
web3.eth.minerstop();
console.log( 'I was trying to seal, but am not authorized. Stopped trying.' );
}
else
{
console.log( "I wasn't trying to seal anyway. All is well." );
}
}
});
},function(x){
console.log(x);
process.exit(1);
})
}
mayseal();
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
var signer
signer = (clique.getSigners().indexOf(eth.accounts[0]) > -1)
if (signer)
miner.start()
else
miner.stop()
signer
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