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
Santiago
nucleo
Commits
a0aaf8e0
Commit
a0aaf8e0
authored
5 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Mejorando ipc
parent
89cc3810
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/libbfa.js
+69
-15
69 additions, 15 deletions
bin/libbfa.js
with
69 additions
and
15 deletions
bin/libbfa.js
+
69
−
15
View file @
a0aaf8e0
...
...
@@ -3,13 +3,13 @@
"
use strict
"
var
request
=
require
(
'
request
'
);
var
net
=
require
(
'
net
'
);
module
.
exports
=
class
Libbfa
{
constructor
()
{
this
.
fs
=
require
(
'
fs
'
);
this
.
Web3
=
require
(
'
web3
'
);
var
net
=
require
(
'
net
'
);
//
// BFAHOME
if
(
undefined
==
process
.
env
.
BFAHOME
)
...
...
@@ -38,7 +38,7 @@ module.exports = class Libbfa
files
.
push
(
filename
);
});
}
// found
none
?
// found
any
?
if
(
files
.
length
>
0
)
{
files
.
sort
();
...
...
@@ -54,10 +54,13 @@ module.exports = class Libbfa
this
.
socketurl
=
this
.
nodedir
+
'
/geth.ipc
'
;
// overwrite with newer ipc method
if
(
this
.
sockettype
==
'
ipc
'
)
{
this
.
provider
=
new
this
.
Web3
.
providers
.
IpcProvider
(
this
.
nodedir
+
'
/geth.ipc
'
,
net
);
this
.
req_url
=
'
http://unix:
'
+
this
.
nodedir
+
'
/geth.ipc:/
'
;
}
else
if
(
this
.
sockettype
==
'
ws
'
)
{
this
.
provider
=
new
this
.
Web3
.
providers
.
WebsocketProvider
(
this
.
socketurl
);
this
.
req_url
=
this
.
socketurl
;
}
else
if
(
this
.
sockettype
==
'
http
'
)
{
this
.
provider
=
new
this
.
Web3
.
providers
.
HttpProvider
(
this
.
socketurl
);
this
.
req_url
=
this
.
socketurl
;
}
else
{
fatal
(
"
Unknown sockettype.
"
);
}
...
...
@@ -92,18 +95,25 @@ module.exports = class Libbfa
newweb3
()
{
var
w3
=
new
this
.
Web3
(
this
.
provider
);
w3
.
rpcreq
=
function
(
opname
,
params
,
callback
)
var
req_url
=
this
.
req_url
;
var
_bfa
=
this
;
w3
.
jsonify
=
function
(
opname
,
params
)
{
var
extra
=
params
.
join
(
'
,
'
);
var
body
=
JSON
.
parse
(
"
{
"
+
'
"jsonrpc":"2.0",
'
+
'
"id":1,
'
+
return
JSON
.
parse
(
'
{
'
+
'
"jsonrpc":"2.0",
'
+
'
"id":1,
'
+
'
"method":"
'
+
opname
+
'
",
'
+
'
"params":[
'
+
extra
+
'
]
'
+
"
}
"
'
"params":[
'
+
extra
+
'
]
'
+
'
}
'
);
};
w3
.
rpcreq
=
function
(
opname
,
params
,
callback
)
{
var
body
=
w3
.
jsonify
(
opname
,
params
);
request
.
post
({
uri
:
'
http://localhost:8545
'
,
uri
:
req_url
,
json
:
true
,
body
:
body
,
callback
:
function
RPCresponse
(
err
,
obj
)
...
...
@@ -121,26 +131,70 @@ module.exports = class Libbfa
}
});
};
w3
.
req
=
function
(
opname
,
params
,
callback
)
{
if
(
_bfa
.
sockettype
==
'
ipc
'
)
{
w3
.
ipcreq
(
opname
,
params
,
callback
);
}
else
{
w3
.
rpcreq
(
opname
,
params
,
callback
);
}
}
w3
.
ipcreq
=
function
(
opname
,
params
,
callback
)
{
var
socket
=
net
.
connect
(
_bfa
.
socketurl
);
var
result
;
var
err
;
socket
.
on
(
"
ready
"
,
()
=>
{
// When the socket has been established.
// We create a new connection per request, because it
// is easier than reliably handling JSON object boundaries
// in a TCP stream .
// Writes out data and closes our end of the connection.
// Geth will reply and then close it's end.
s
.
end
(
w3
.
jsonify
(
opname
,
params
)
);
});
socket
.
on
(
"
data
"
,
(
d
)
=>
{
try
{
result
=
JSON
.
parse
(
d
.
toString
()
);
}
catch
{
err
=
d
.
toString
();
}
});
socket
.
on
(
"
timeout
"
,
()
=>
{
socket
.
close
();
});
socket
.
on
(
"
error
"
,
(
e
)
=>
{
console
.
error
(
e
);
err
=
e
;
});
socket
.
on
(
"
close
"
,
()
=>
{
callback
(
err
,
result
);
});
}
w3
.
bfa
=
{
clique
:
{
getSigners
:
function
clique_getSigners
(
cb
)
{
w3
.
rpc
req
(
'
clique_getSigners
'
,
[],
cb
)
},
{
w3
.
req
(
'
clique_getSigners
'
,
[],
cb
)
},
},
miner
:
{
start
:
function
miner_start
()
{
w3
.
rpc
req
(
'
miner_start
'
,
[],
function
(){}
)
},
{
w3
.
req
(
'
miner_start
'
,
[],
function
(){}
)
},
stop
:
function
miner_stop
()
{
w3
.
rpc
req
(
'
miner_stop
'
,
[],
function
(){}
)
}
{
w3
.
req
(
'
miner_stop
'
,
[],
function
(){}
)
}
},
admin
:
{
peers
:
function
admin_peers
(
cb
)
{
w3
.
rpc
req
(
'
admin_peers
'
,
[],
cb
)
},
{
w3
.
req
(
'
admin_peers
'
,
[],
cb
)
},
addPeer
:
function
admin_addPeer
(
peer
)
{
w3
.
rpc
req
(
'
admin_addPeer
'
,
[
"
\"
"
+
peer
+
"
\"
"
],
function
(){}
)
}
{
w3
.
req
(
'
admin_addPeer
'
,
[
"
\"
"
+
peer
+
"
\"
"
],
function
(){}
)
}
},
personal
:
{
listWallets
:
function
personal_listWallets
(
cb
)
{
w3
.
rpc
req
(
'
personal_listWallets
'
,
[],
cb
)
}
{
w3
.
req
(
'
personal_listWallets
'
,
[],
cb
)
}
}
};
if
(
undefined
!=
process
.
env
.
BFAACCOUNT
)
{
...
...
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