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

Problemas con extend. Hacemos nuestro propio interfaz.

parent 091b8502
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@
"use strict"
var request = require('request');
module.exports = class Libbfa
{
constructor() {
......@@ -76,51 +78,54 @@ module.exports = class Libbfa
newweb3()
{
var provider = 'http://127.0.0.1:' + this.rpcport;
var w3 = new this.Web3( provider );
w3.eth.extend({
//property: 'bfaclique',
methods: [{
name: 'bfaGetSigners',
call: 'clique_getSigners',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'bfaMinerstart',
call: 'miner_start',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'bfaMinerstop',
call: 'miner_stop',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'bfaAdminpeers',
call: 'admin_peers',
params: 0
}]
});
w3.eth.extend({
methods: [{
name: 'bfaAdminaddPeer',
call: 'admin_addPeer',
params: 1
}]
});
w3.eth.personal.extend({
methods: [{
name: 'bfalistWallets',
call: 'personal_listWallets',
params: 0
}]
});
var provider = 'http://127.0.0.1:' + this.rpcport;
var w3 = new this.Web3( provider );
w3.rpcreq = function( opname, params, callback )
{
var extra = params.join(',');
var body = JSON.parse("{"+
'"jsonrpc":"2.0",' +
'"id":1,' +
'"method":"' + opname + '",' +
'"params":[' + extra + ']'
+"}"
);
request.post({
uri: 'http://localhost:8545',
json: true,
body: body,
callback: function RPCresponse( err, obj )
{
if ( err )
throw new Error( err );
if ( obj.body.error && obj.body.error.code && obj.body.error.message )
throw new Error( 'Error ' + obj.body.error.code + ": "+ obj.body.error.message );
callback(obj.body.result);
}
});
};
w3.bfa = {
clique: {
getSigners: function clique_getSigners( cb )
{ w3.rpcreq( 'clique_getSigners', [], cb ) },
},
miner: {
start: function miner_start()
{ w3.rpcreq( 'miner_start', [], function(){} ) },
stop: function miner_stop()
{ w3.rpcreq( 'miner_stop', [], function(){} ) }
},
admin: {
peers: function admin_peers( cb )
{ w3.rpcreq( 'admin_peers', [], cb ) },
addPeer: function admin_addPeer( peer )
{ w3.rpcreq( 'admin_addPeer', [ "\""+peer+"\"" ], function(){} ) }
},
personal: {
listWallets: function personal_listWallets( cb )
{ w3.rpcreq( 'personal_listWallets', [], cb ) }
}
};
if ( undefined != process.env.BFAACCOUNT ) {
w3.eth.defaultAccount = this.account;
}
......
......@@ -11,7 +11,7 @@ var lastUnlock = 0;
function peerlist()
{
web3.eth.bfaAdminpeers().then(
web3.bfa.admin.peers(
function gotAdminPeers( nodelist ) {
var now = new Date();
var nowpeers = [];
......@@ -86,7 +86,7 @@ function peerlist()
+ " peer" + ( nowpeers.length==1 ? '' : 's' ) + ", so will try to connect to "
+ enode
);
web3.eth.bfaAdminaddPeer( enode );
web3.bfa.admin.addPeer( enode );
}
// write network/peers.cache
// peers.cache is a list of peers we have connected out to in the past.
......@@ -98,10 +98,6 @@ function peerlist()
peers.join("\n") + "\n",
{ mode: 0o644 }
);
},
function failedToGetAdminPeers(x)
{
// ignore connection problems?
}
);
}
......@@ -124,8 +120,7 @@ function mayseal()
{
// Get a list of clique.getSigners, so we can see if we are
// in the list of authorized sealers.
web3.eth.bfaGetSigners()
.then(
web3.bfa.clique.getSigners(
function gotListOfSealers(x)
{
var lcsealers = x.map( name => name.toLowerCase() );
......@@ -135,7 +130,7 @@ function mayseal()
if ( ! isMining )
{
console.log( 'Started to seal.' );
web3.eth.bfaMinerstart();
web3.bfa.miner.start();
}
}
else
......@@ -143,20 +138,16 @@ function mayseal()
if ( isMining )
{
console.log( 'I was trying to seal, but am not authorized. Stopped trying.' );
web3.eth.bfaMinerstop();
web3.bfa.miner.stop();
}
}
},
function failedToGetListOfSealers(x)
{
console.log(x);
}
);
},
function failedToGetIsMiningBool(x)
{
// Probably geth is not running.
//console.log(x);
throw new Error(x);
}
);
}
......@@ -165,8 +156,7 @@ function unlock()
{
if ( lastUnlock + 600 > Date.now() / 1000 )
return;
web3.eth.personal.bfalistWallets()
.then(
web3.bfa.personal.listWallets(
function pushone(x)
{
var i = x.length;
......@@ -192,12 +182,7 @@ function unlock()
}
lastUnlock = Date.now() / 1000;
}
,
function err(x)
{
// we don't care?
}
)
);
}
function timer()
......
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