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

Soporte en libbfa para SOCKETTYPE/SOCKETURL

parent e1f393a9
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
if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ]
then
echo "Node is not initialised. Initialising with genesis."
geth --cache 0 --datadir "${BFANODEDIR}" --networkid ${BFANETWORKID} init "${BFANETWORKDIR}/genesis.json"
fi
...@@ -46,11 +46,21 @@ module.exports = class Libbfa ...@@ -46,11 +46,21 @@ module.exports = class Libbfa
} }
} }
// //
this.netport = Number.parseInt( this.setfromfile( this.nodedir+'/netport', 30303 ));
this.rpcport = Number.parseInt( this.setfromfile( this.nodedir+'/rpcport', 8545 ));
//this.provider = 'http://127.0.0.1:' + this.rpcport; // old
this.provider = new this.Web3.providers.IpcProvider(this.nodedir+'/geth.ipc', net)
this.account = process.env.BFAACCOUNT; this.account = process.env.BFAACCOUNT;
this.netport = 30303;
this.rpcport = 8545;
this.sockettype = 'ipc';
this.socketurl = 'http://127.0.0.1:' + this.rpcport; // old
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 );
} else if ( this.sockettype == 'ws' ) {
this.provider = new this.Web3.providers.WebsocketProvider( this.socketurl );
} else if ( this.sockettype == 'http') {
this.provider = new this.Web3.providers.HttpProvider( this.socketurl );
} else {
fatal("Unknown sockettype.");
}
} }
contract(w3, name) contract(w3, name)
...@@ -75,7 +85,7 @@ module.exports = class Libbfa ...@@ -75,7 +85,7 @@ module.exports = class Libbfa
fatal( txt ) fatal( txt )
{ {
console.log( txt ); console.error( txt );
process.exit( 1 ); process.exit( 1 );
} }
......
...@@ -65,12 +65,13 @@ function geth_exec ...@@ -65,12 +65,13 @@ function geth_exec
geth_attach --exec "$1" </dev/null geth_attach --exec "$1" </dev/null
} }
rpc_counter=0
function geth_rpc function geth_rpc
{ {
local cmd=$1 local params= connectstring= cmd=$1
test -n "$cmd"
local params=
shift shift
test -n "$cmd"
rpc_counter=$(( $rpc_counter + 1 ))
if [ $# -gt 0 ] if [ $# -gt 0 ]
then then
params=',"params":[' params=',"params":['
...@@ -82,12 +83,18 @@ function geth_rpc ...@@ -82,12 +83,18 @@ function geth_rpc
# Eat the last comma and add a ] # Eat the last comma and add a ]
params=${params/%,/]} params=${params/%,/]}
fi fi
if [ "$BFASOCKETTYPE" = "ipc" ]
then
connectstring="--unix-socket ${BFASOCKETURL}"
else
connectstring="${BFASOCKETURL}"
fi
local json=$( local json=$(
curl \ curl \
-H 'Content-type: application/json' \ -H 'Content-type: application/json' \
-X POST \ -X POST \
--data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" \ --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":${rpc_counter}}" \
http://127.0.0.1:$rpcport \ ${connectstring} \
2>/dev/null 2>/dev/null
) )
test -n "$json" test -n "$json"
...@@ -104,34 +111,9 @@ function create_account ...@@ -104,34 +111,9 @@ function create_account
geth --cache 0 --datadir ${BFANODEDIR} --password /dev/null account new geth --cache 0 --datadir ${BFANODEDIR} --password /dev/null account new
} }
function extradata
{
local acct=$(
ls -1d "${BFANODEDIR}"/keystore/*--* 2>/dev/null |
head -1 |
sed 's/.*--//'
)
if [ -n "$acct" ]
then
# something uniqueish
## find default interface
local def_if=$(
( ip -4 route show ; ip -6 route show ) |
expand |
sed -ne '/^default /{s/ */ /g;s/^.* dev //;s/ .*//;p;q}'
)
local mymac=$(
ip link show ${def_if} |
sed -ne '/link\|ether/{s/^.*link.ether //;s/ .*//;s/://g;p;q}'
)
#
echo -n "${acct:0:19}.${mymac:0:12}"
fi
}
function prereq function prereq
{ {
err=0 local err=0
while [ -n "$1" ] while [ -n "$1" ]
do do
if ! which $1 > /dev/null if ! which $1 > /dev/null
...@@ -193,30 +175,22 @@ test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\" ...@@ -193,30 +175,22 @@ test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\"
test -n "$BFANODEDIR" || BFANODEDIR="${BFANETWORKDIR}/node" test -n "$BFANODEDIR" || BFANODEDIR="${BFANETWORKDIR}/node"
if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ] if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ]
then then
echo "Node is not initialised. Initialising with genesis." generate-genesis-block.sh
geth --cache 0 --datadir "${BFANODEDIR}" --networkid ${BFANETWORKID} init "${BFANETWORKDIR}/genesis.json"
fi
#
# netport
netport=30303
if [ -r "${BFANODEDIR}/netport" ]
then
netport=$( cat ${BFANODEDIR}/netport )
test $? = 0
fi
if [ "$netport" != "30303" ]
then
netportarg="--port ${netport}"
fi
#
# rpcport
rpcport=8545
if [ -r "${BFANODEDIR}/rpcport" ]
then
rpcport=$( cat ${BFANODEDIR}/rpcport )
test $? = 0
fi
if [ "$rpcport" != "8545" ]
then
rpcportarg="--rpcport ${rpcport}"
fi fi
true ${BFASOCKETTYPE:=ipc}
case "${BFASOCKETTYPE}" in
ipc)
test ${BFASOCKETURL:="ipc:${BFANODEDIR}/geth.ipc"}
;;
http)
test ${BFASOCKETURL:="http://127.0.0.1:8545"}
;;
ws)
test ${BFASOCKETURL:="ws://127.0.0.1:8546"}
;;
*)
echo "Unknown socket type. Supported types are http, ws, ipc" >&2
exit 1
esac
BFASOCKET
...@@ -264,7 +264,7 @@ if ( $result ) ...@@ -264,7 +264,7 @@ if ( $result )
my $i = 0; my $i = 0;
if ( scalar @$result ) if ( scalar @$result )
{ {
foreach my $account ( sort @$result ) foreach my $account ( @$result )
{ {
my $maymine = ''; my $maymine = '';
$maymine = 'sealer' $maymine = 'sealer'
......
...@@ -88,7 +88,7 @@ PIDIDX[$!]="log.sh" ...@@ -88,7 +88,7 @@ PIDIDX[$!]="log.sh"
exec > ${LOGPIPE} 2>&1 exec > ${LOGPIPE} 2>&1
echo "*** Starting geth." echo "*** Starting geth."
geth --config ${BFATOML} --gcmode archive --verbosity ${BFAVERBOSITY:-3} --allow-insecure-unlock & geth --config ${BFATOML} --gcmode archive --allow-insecure-unlock &
PIDIDX[$!]="geth" PIDIDX[$!]="geth"
# bootnode # bootnode
......
...@@ -126,29 +126,12 @@ function geth_args ...@@ -126,29 +126,12 @@ function geth_args
# (re)configure parameters (you never know if they changed) # (re)configure parameters (you never know if they changed)
flexargs="$( getsyncmode )" flexargs="$( getsyncmode )"
geth_capab geth_capab
xtra=$( extradata )
if [ -n "$xtra" ]
then
flexargs="${flexargs} --extradata $( extradata )"
fi
unset xtra
# #
if [ "$netport" != 30303 ]
then
flexargs="${flexargs} --port $netport"
fi
if [ "$rpcport" != 30303 ]
then
flexargs="${flexargs} --rpcport $rpcport"
fi
if [ -n "$BFAVERBOSITY" -a "$BFAVERBOSITY" != 3 ]
then
flexargs="${flexargs} --verbosity ${BFAVERBOSITY:-3}"
fi
# the basic modules # the basic modules
rpcapis="eth,net,web3,clique" local rpcapis="eth,net,web3,clique"
if [ -e "${BFANODEDIR}/opentx" ] if [ -e "${BFANODEDIR}/opentx" ]
then then
local txhostnames dummy
# If you want other hostnames, put them in this file (comma separated) # If you want other hostnames, put them in this file (comma separated)
read txhostnames dummy < ${BFANODEDIR}/opentx read txhostnames dummy < ${BFANODEDIR}/opentx
if [ "${txhostnames}" = "" ] if [ "${txhostnames}" = "" ]
......
...@@ -74,7 +74,7 @@ sub hex2string($) ...@@ -74,7 +74,7 @@ sub hex2string($)
sub rpcreq sub rpcreq
{ {
my ( $opname, @params ) = @_; my ( $opname, @params ) = @_;
my $req = HTTP::Request->new( POST => 'http://127.0.0.1:' . $libbfa->{'rpcport'} ); my $req = HTTP::Request->new( POST => 'http://127.0.0.1:8545' );
$req->content_type('application/json'); $req->content_type('application/json');
my $extra = scalar @params my $extra = scalar @params
? sprintf(qq(,\"params\":[%s]), join(',', @params)) ? sprintf(qq(,\"params\":[%s]), join(',', @params))
......
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