Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Miguel Montes
nucleo
Commits
d69b6372
Commit
d69b6372
authored
6 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Problemas con extend. Hacemos nuestro propio interfaz.
parent
091b8502
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bin/libbfa.js
+50
-45
50 additions, 45 deletions
bin/libbfa.js
bin/monitor.js
+8
-23
8 additions, 23 deletions
bin/monitor.js
with
58 additions
and
68 deletions
bin/libbfa.js
+
50
−
45
View file @
d69b6372
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
bin/monitor.js
+
8
−
23
View file @
d69b6372
...
...
@@ -11,7 +11,7 @@ var lastUnlock = 0;
function
peerlist
()
{
web3
.
eth
.
bfa
A
dminpeers
(
).
then
(
web3
.
bfa
.
a
dmin
.
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
.
bfa
A
dminaddPeer
(
enode
);
web3
.
bfa
.
a
dmin
.
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
.
bfa
M
inerstart
();
web3
.
bfa
.
m
iner
.
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
.
bfa
M
inerstop
();
web3
.
bfa
.
m
iner
.
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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment