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

Moving to use the new libbfa

parent 6c22e58d
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# 20180626 Robert Martin-Legene <robert@nic.ar>
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/libbfa.sh ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
config node
geth attach ipc:${BFANODEDIR}/geth.ipc
#!/bin/bash #!/bin/bash
# 20180618 Robert Martin-Legene <robert@nic.ar>
cd $( dirname $0 ) if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/libbfa.sh ?" >&2; exit 1; fi
. ./libbfa.sh source ${BFAHOME}/bin/libbfa.sh || exit 1
function prereq
{
err=0
while [ -n "$1" ]
do
if ! which $1 > /dev/null
then
echo "Need $1"
err=1
fi
shift
done
test $err -eq 0 || exit 1
}
function create function create
{ {
workdir=$( bfamktemp -p . -d ) workdir=$( bfamktemp -p . -d )
json=$( solc --optimize --combined-json abi,bin $filename ) json=$( solc --optimize --combined-json abi,bin $filename ); test $? eq 0
test $? eq 0 abi=$( echo "$json" | jq -rM ".contracts.${prefix}.abi" ); test $? eq 0
prefix=$( echo "$json" | jq '.contracts|keys[0]' ) bin=$( echo "$json" | jq -rM ".contracts.${prefix}.bin" ); test $? eq 0
test $? eq 0
abi=$( echo "$json" | jq ".contracts.${prefix}.abi" )
test $? eq 0
bin=$( echo "$json" | jq ".contracts.${prefix}.bin" )
test $? eq 0
# Remove all quote marks "
bin="${bin//\"}"
# Save abi for future use # Save abi for future use
echo $abi > ${workdir}/abi echo $abi > ${workdir}/abi
# We could save the bin, but we don't actually use it later, plus # We could save the bin, but we don't actually use it later, plus
...@@ -55,28 +34,32 @@ EOT ...@@ -55,28 +34,32 @@ EOT
if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ] if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ]
then then
addr=` head -1 < $outfile ` addr=` head -1 < $outfile `
mkdir ${network}/contracts mkdir -p ${BFANETWORKDIR}/contracts
mv ${workdir} ${network}/contracts/${addr} mv ${workdir} ${BFANETWORKDIR}/contracts/${addr}
echo Your new contract can be found in ${network}/contracts/${addr} echo Your new contract can be found in ${BFANETWORKDIR}/contracts/${addr}
ln -sf ${addr} ${network}/contracts/${contractname} ln -snf ${addr} ${BFANETWORKDIR}/contracts/${contractname}
else else
echo
echo ' *** INPUT ***'
echo
cat $js cat $js
echo echo
echo ' ***' echo ' *** OUTPUT ***'
echo echo
cat $outfile cat $outfile
fi fi
} }
trap "echo Argh;exit 1" ERR
test -n "$1" || ( echo "Specify a filename of a contract you wish to compile."; false )
filename="$1" filename="$1"
test -r "$filename" if [ -z "$filename" -o ! -r "$filename" ]
then
echo "Specify a filename of a contract you wish to compile."
false
fi
contractname=${filename%%.sol} contractname=${filename%%.sol}
contractname=${contractname##*/} contractname=${contractname##*/}
contractname=${contractname##contract.} contractname=${contractname##contract.}
contractname=${contractname%.*} contractname=${contractname%.*}
account=` ls -1dl network5445/node1/keystore/* | head -1 | sed 's/.*--//' ` config max
test -n "$account"
prereq jq solc geth prereq jq solc geth
create create
#!/bin/bash #!/bin/bash
# 20180619 Robert Martin-Legene <robert@nic.ar> # 20180619 Robert Martin-Legene <robert@nic.ar>
if [ ! -d "${BFAHOME}" ] if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/libbfa.sh ?" >&2; exit 1; fi
then source ${BFAHOME}/bin/libbfa.sh || exit 1
echo "\$BFAHOME does not point to a directory. Did you source \$BFAHOME/bin/env ?" >&2
exit 1
fi
trap "echo Argh;exit 1" ERR config max
prereq tput
# rpcport is set per node, in a file. Default is port 8545.
rpcport=8545 rpcport=8545
cd "${BFANETWORKDIR}"
cd $( dirname $0 ) test -r "$BFANODEDIR/rpcport" &&
test -r "node1/rpcport" && rpcport=$( cat "$BFANODEDIR/rpcport" )
rpcport=$( cat node1/rpcport )
test -n "$rpcport" test -n "$rpcport"
width=$( tput cols ) width=$( tput cols )
height=$( tput lines ) height=$( tput lines )
block=${1:-0}
function showblock function showblock
{ {
test "$1" = "latest" &&
set $maxblock
hexblock=$( printf '%x' $1 ) hexblock=$( printf '%x' $1 )
printf '\e[H\e[JBlock %d (0x%x)\n' $block $block printf '\e[H\e[JBlock %d (0x%x)\n' $block $block
curl -H 'Content-type: application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x'${hexblock}'", true],"id":1}' http://127.0.0.1:$rpcport 2>/dev/null | curl -H 'Content-type: application/json' -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x'${hexblock}'", true],"id":1}' http://127.0.0.1:$rpcport 2>/dev/null |
...@@ -27,21 +26,61 @@ function showblock ...@@ -27,21 +26,61 @@ function showblock
fold --width=$width | fold --width=$width |
head -$(( $height - 2 )) head -$(( $height - 2 ))
printf '\e[m' printf '\e[m'
maxblock=$( latest )
}
function latest
{
curl \
-H 'Content-type: application/json' \
-X POST \
--data '{"jsonrpc":"2.0","method":"eth_getNumber","id":1}' \
http://127.0.0.1:$rpcport \
2>/dev/null |
jq -rM .result
} }
block=$1
maxblock=$( latest )
if [ -z "$block" ]
then
block=latest
fi
test -n "$block"
showblock $block showblock $block
while read -r -s -n 1 -p "j=up k=down q=quit " timeout=
while read -r -s -n 1 ${timeout} -p "j=up k=down q=quit "
do do
if [ "${REPLY,,}" = "q" ] case "${REPLY,,}" in
then q)
echo echo
exit 0 exit 0
elif [ "${REPLY,,}" = "k" -a $block -gt 0 ] ;;
then k)
let block-- if [ "$block" = "latest" -a $maxblock -gt 0 ]
elif [ "${REPLY,,}" = "j" ] then
then block=$(( $maxblock - 1 ))
let block++ || true else
fi if [ $block -gt 0 ]
then
block=$(( $block - 1 ))
fi
fi
;;
j)
if [ "$block" != "latest" ]
then
block=$(( $block + 1 ))
fi
;;
*)
continue
;;
esac
showblock $block showblock $block
timeout=
test "$block" = "latest" &&
timeout="-t 1"
done done
#!/bin/bash #!/bin/bash
function cleanup # $BFAHOME must point to a directory. Did you source $BFAHOME/bin/env ?
{ source ${BFAHOME}/bin/libbfa.sh || exit 1
rmfiles="$rmfiles $@"
trap "rm -rf ${rmfiles}" EXIT
}
trap "echo Argh;exit 1" ERR trap "echo Argh;exit 1" ERR
cd $( dirname $0 ) cd $( dirname $0 )
......
# Probably, this should only be sourced, not executed directly. # This should only be sourced, not executed directly.
# 20180626 Robert Martin-Legene <robert@nic.ar> # 20180626 Robert Martin-Legene <robert@nic.ar>
fatal() fatal()
...@@ -13,6 +13,11 @@ test "$( basename $SHELL 2>/dev/null )" = "bash" || ...@@ -13,6 +13,11 @@ test "$( basename $SHELL 2>/dev/null )" = "bash" ||
test "$( caller 2>/dev/null | awk '{print $1}' )" != "0" || test "$( caller 2>/dev/null | awk '{print $1}' )" != "0" ||
fatal "This file must be source(d), not executed." fatal "This file must be source(d), not executed."
function stderr
{
echo "$@" >&2
}
function cleanup function cleanup
{ {
if [ $# -gt 0 ] if [ $# -gt 0 ]
...@@ -45,82 +50,82 @@ function geth_exec_js ...@@ -45,82 +50,82 @@ function geth_exec_js
echo $out echo $out
} }
function config_environment function networkdir
{ {
creating=0 test -z "${BFAHOME}" -o ! -d "${BFAHOME}" ||
if [ -z "${networkdir}" ] fatal "\$BFAHOME in your environment must point to a directory."
local creating=0
# If no BFANETWORKDIR variable has been set, we will try to guess
# the network directory based on the directory we are in.
if [ -n "${BFANETWORKDIR}" ]
then then
test -d "${BFANETWORKDIR}" ||
fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found."
else
local basedir=$( basename $PWD ) local basedir=$( basename $PWD )
if [ -n "${networkdir}" -a ! -d "${networkdir}" ] if $( echo "${basedir}" | grep -qE '^network[0-9]+$' )
then then
# Networkdir is set and we can't find it. Let's see if BFANETWORKDIR="$basedir"
# we happen to already be in that directory.
if [ "${basedir}" -ne "${networkdir}" ]
then
fatal "Your \$networkdir environment variable conflicts with" \
"the name of the directory you are currently in, and I can" \
"not find the networkdir you specified (if any)."
fi
elif $( echo "${basedir}" | grep -qE '^network[0-9]+$' )
then
networkdir="$basedir"
fi fi
local n if [ -z "${BFANETWORKDIR}" ]
for n in $( ls -ld network* 2>/dev/null | grep -qE '^network[0-9]+$' )
do
if [ -n "${networkdir}" ]
then
fatal "If you have more than one work listed in your" \
"current directory, you must specify which one to" \
"use, using the \"networkdir\" environment variable."
fi
networkdir=${n}
done
if [ -z "${networkdir}" ]
then then
echo "I can't find your networkdir." local num=0
REPLY= while [ $num -lt 9876 ]
while [ "$REPLY" != "y" -a "$REPLY" != "n" ]
do do
read -n 1 -p "Would you like me to create a random one for you? [yN]: " num=$(( $RANDOM * $RANDOM ))
if [ -z "$REPLY" ]
then
REPLY=n
else
if [ "${REPLY,,}" = "y" ]
then
creating=1
fi
fi
done done
if [ $creating = 1 ] stderr "I can't find your BFANETWORKDIR."
then fatal "Consider running: mkdir ${BFAHOME}/network${num}"
local num=0
while [ $num -lt 123456 ]
do
num=$(( $RANDOM * $RANDOM ))
done
networkdir="network${num}"
echo "You had no network defined, so I am creating network ${network} for you in ${networkdir}/ ."
mkdir "${networkdir}"
fi
fi fi
fi fi
}
function nodedir
{
networkdir
# set defaults # set defaults
true ${nodedir:=node1} true ${BFANODEDIR:=${BFAHOME}/node1}
test -n "${nodedir}" test -n "${BFANODEDIR}"
if [ ! -d "${nodedir}" -a $creating = 1 ] test -d "${BFANODEDIR}"
then }
mkdir ${networkdir}/${nodedir}
else function account
test -d "${nodedir}" {
fi nodedir
if [ -z "$account" ] if [ -z "$account" ]
then then
test -d "${nodedir}/keystore" test -d "${BFANODEDIR}/keystore"
account=$( ls -1dl "${nodedir}"/keystore/* | head -1 | sed 's/.*--//' ) account=$( ls -1dl "${BFANODEDIR}"/keystore/*--* | head -1 | sed 's/.*--//' )
fi fi
test -n "$account" test -n "$account"
} }
config_environment function config
{
case "$1" in
network)
networkdir
;;
node)
nodedir
;;
account|max)
account
;;
esac
}
function prereq
{
err=0
while [ -n "$1" ]
do
if ! which $1 > /dev/null
then
echo "Need $1"
err=1
fi
shift
done
test $err -eq 0
}
#!/bin/sh #!/bin/sh
funtion fatal # $BFAHOME must point to a directory. Did you source $BFAHOME/bin/env ?
{ source ${BFAHOME}/bin/libbfa.sh || exit 1
echo "$@" >&2
exit 1
}
test -n "$1" || test -n "$1" ||
fatal "Send to whom?" fatal "Send to whom?"
......
#!/bin/bash #!/bin/bash
# 20180619 Robert Martin-Legene <robert@nic.ar>
function cleanup # $BFAHOME must point to a directory. Did you source $BFAHOME/bin/env ?
{ source ${BFAHOME}/bin/libbfa.sh || exit 1
rmfiles="$rmfiles $@"
trap "rm -rf ${rmfiles}" EXIT
}
trap "echo Argh;exit 1" ERR
in=$1 in=$1
test -n "$in" || in="Hello World!" test -n "$in" || in="Hello World!"
cd $( dirname $0 ) cd $( dirname $0 )
......
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