diff --git a/bin/attach.sh b/bin/attach.sh index 5f42960057fe59d3f664c72c2e7bb6b8520171fc..c9da22f8ba826a58768dea21848204203c6f84f5 100755 --- a/bin/attach.sh +++ b/bin/attach.sh @@ -1,8 +1,8 @@ #!/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 +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 -config node +bfaconfig node geth attach ipc:${BFANODEDIR}/geth.ipc diff --git a/bin/create.contract b/bin/create.contract index 16d0ebb8a95f4a7d554e9a8f993ba7674af64b09..cc4ebb9ccceeb1709d4da4073e5f83b7355d25d2 100755 --- a/bin/create.contract +++ b/bin/create.contract @@ -1,7 +1,7 @@ #!/bin/bash # 20180618 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 +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 function create @@ -29,7 +29,7 @@ var address = rcpt.contractAddress; var pubcontract = mycontract.at(address); console.log( pubcontract.address ); EOT - echo '*** Creating contract. Will take 16-30 seconds' + echo '*** Creating contract. This will take at least 16 seconds.' outfile=$( geth_exec_js $js ) if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ] then @@ -60,6 +60,6 @@ contractname=${filename%%.sol} contractname=${contractname##*/} contractname=${contractname##contract.} contractname=${contractname%.*} -config max +bfaconfig max prereq jq solc geth create diff --git a/bin/explorer.sh b/bin/explorer.sh index 39cc6476aa9fa246e9770f11ed71ebe8d1f76a3e..46927209b1d74163ce6aecd66a599666ca42bb89 100755 --- a/bin/explorer.sh +++ b/bin/explorer.sh @@ -1,10 +1,10 @@ #!/bin/bash # 20180619 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 +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 -config max +bfaconfig max prereq tput # rpcport is set per node, in a file. Default is port 8545. rpcport=8545 diff --git a/bin/insert.sh b/bin/insert.sh index 8aa2f3ba5e5e4a9b7403c77c42a343173d2f2744..859eb3dba366d28b561c299d58ef951490265fb8 100755 --- a/bin/insert.sh +++ b/bin/insert.sh @@ -1,32 +1,43 @@ #!/bin/bash -# $BFAHOME must point to a directory. Did you source $BFAHOME/bin/env ? +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 -trap "echo Argh;exit 1" ERR -cd $( dirname $0 ) -in=$1 -test -n "$in" || in="Hello World!" -account=` ls -1dl node1/keystore/* | head -1 | sed 's/.*--//' ` -test -n "$account" -contract=$( readlink contracts/TimestampDocument ) -abi=$( cat contracts/${contract}/abi ) -cleanup g1.js -cat > g1.js <<EOT -var mycontract = eth.contract(JSON.parse($abi)) -var thecontract = mycontract.at("$contract"); -console.log ( thecontract.storeDocument.sendTransaction( "${in}", {from: eth.accounts[0], gas: 1000000} ) ) +contract=$1 +text=$2 +test -n "${contract}" || + contract="TimestampDocument" +if [ ! -e "${contract}" -a -r "${BFANETWORKDIR}/contracts/${contract}" ] +then + contract=${BFANETWORKDIR}/contracts/${contract} +fi +test -L "${contract}" && + contract=$( readlink "${contract}" ) +test -n "${contract}" +basecontract=$( basename "${contract}" ) +test -n "${basecontract}" +abi=$( cat ${contract}/abi ) +test -n "${abi}" +test -n "$text" || text="Hello World!" +js=$( bfamktemp ) +cat > $js <<EOT +var mycontract = eth.contract(JSON.parse(${abi})) +var thecontract = mycontract.at("${basecontract}"); +console.log ( thecontract.storeDocument.sendTransaction( "${text}", {from: eth.accounts[0], gas: 1000000} ) ) EOT -cleanup out1 -geth --datadir node1 --exec 'loadScript("g1.js")' attach ipc:node1/geth.ipc > out1 -if [ ` wc -l < out1 ` = 2 -a `tail -1 < out1` = "true" ] +out=$( bfamktemp ) +geth --datadir node1 --exec "loadScript(\"${js}\")" attach ipc:node1/geth.ipc > ${out} +if [ ` wc -l < ${out} ` = 2 -a ` tail -1 < ${out} ` = "true" ] then - conf=` head -1 < out1 ` - echo "Sent document in transaction ${conf}." + trans=` head -1 < ${out} ` + echo "Sent document in transaction ${trans}." else - cat g1.js - echo - echo ' ***' - echo - cat out1 + ( + cat ${js} + echo + echo ' ***' + echo + cat ${out} + ) >&2 + exit 1 fi diff --git a/bin/libbfa.sh b/bin/libbfa.sh index a4ab1d60593555abaa14a8dd91fabcf648ab0dc4..fc799b8904efe81bd84cc348d436425f143d2181 100644 --- a/bin/libbfa.sh +++ b/bin/libbfa.sh @@ -1,13 +1,15 @@ # This should only be sourced, not executed directly. # 20180626 Robert Martin-Legene <robert@nic.ar> -fatal() +trap "echo Argh! ; exit 1" ERR + +function fatal() { echo "$@" >&2 exit 1 } -trap "echo Argh! ; exit 1" ERR +trap "fatal Argh!" ERR test "$( basename $SHELL 2>/dev/null )" = "bash" || fatal "This file must be source(d) from bash." test "$( caller 2>/dev/null | awk '{print $1}' )" != "0" || @@ -100,7 +102,7 @@ function account test -n "$account" } -function config +function bfaconfig { case "$1" in network) diff --git a/bin/sendether.sh b/bin/sendether.sh index c51eb8de1ea6690934729325d28f5f7d7a97fefa..24a912b84715d1bb500ffe14f5a5e63356684c4d 100644 --- a/bin/sendether.sh +++ b/bin/sendether.sh @@ -1,6 +1,6 @@ -#!/bin/sh +#!/bin/bash -# $BFAHOME must point to a directory. Did you source $BFAHOME/bin/env ? +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 test -n "$1" || diff --git a/bin/verify.sh b/bin/verify.sh index 850690ac8706c838d815e47f4046138e8cb3a5e4..4f40e846e3791a1f6487545fd1d92084a15fec73 100755 --- a/bin/verify.sh +++ b/bin/verify.sh @@ -1,37 +1,49 @@ #!/bin/bash # 20180619 Robert Martin-Legene <robert@nic.ar> -# $BFAHOME must point to a directory. Did you source $BFAHOME/bin/env ? +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 -in=$1 -test -n "$in" || in="Hello World!" -cd $( dirname $0 ) -account=` ls -1dl node1/keystore/* | head -1 | sed 's/.*--//' ` -test -n "$account" -contract=$( readlink contracts/TimestampDocument ) -abi=$( cat contracts/${contract}/abi ) -cleanup g1.js -cat > g1.js <<EOT -var mycontract = eth.contract(JSON.parse($abi)) -var thecontract = mycontract.at("$contract"); -console.log ( thecontract.checkDocument.call( "${in}" ) ) +contract=$1 +text=$2 +test -n "${contract}" || + contract="TimestampDocument" +if [ ! -e "${contract}" -a -r "${BFANETWORKDIR}/contracts/${contract}" ] +then + contract=${BFANETWORKDIR}/contracts/${contract} +fi +test -L "${contract}" && + contract=$( readlink "${contract}" ) +test -n "${contract}" +basecontract=$( basename "${contract}" ) +test -n "${basecontract}" +abi=$( cat ${contract}/abi ) +test -n "${abi}" +test -n "$text" || text="Hello World!" +js=$( bfamktemp ) +cat > ${js} <<EOT +var mycontract = eth.contract(JSON.parse(${abi})) +var thecontract = mycontract.at("${basecontract}"); +console.log ( thecontract.checkDocument.call( "${text}" ) ) EOT -cleanup out1 -geth --datadir node1 --exec 'loadScript("g1.js")' attach ipc:node1/geth.ipc > out1 -if [ ` wc -l < out1 ` = 2 -a `tail -1 < out1` = "true" ] +out=$( bfamktemp ) +geth --datadir node1 --exec "loadScript(\"${js}\")" attach ipc:node1/geth.ipc > ${out} +if [ ` wc -l < ${out} ` = 2 -a ` tail -1 < ${out} ` = "true" ] then - block=` head -1 < out1 ` - if [ "$block" = "0" ] + block=` head -1 < $out ` + if [ "${block}" -gt "0" ] then - echo "The checksum of this document has not been stored in the smart contract (yet?)." - else echo "Document first seen in block ${block}" + else + echo "The checksum of this document has not been stored in the smart contract (yet?)." + exit 1 fi else - cat g1.js - echo - echo ' ***' - echo - cat out1 + ( + cat ${js} + echo + echo ' ***' + echo + cat ${out} + ) >&2 fi