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

Fixed some errors in explorer.sh and enhanced it a little bit.

parent a5ef0220
No related branches found
No related tags found
No related merge requests found
...@@ -4,19 +4,28 @@ ...@@ -4,19 +4,28 @@
1. Install geth 1. Install geth
- For Debian read doc/compiling-geth-on-debian.txt - For Debian read doc/compiling-geth-on-debian.txt
- For Ubuntu read doc/installing-geth-on-ubuntu.txt - For Ubuntu read doc/installing-geth-on-ubuntu.txt
2. `sudo apt install jq ncurses-bin` 2. `sudo apt install jq ncurses-bin curl`
3. `git clone https://github.com/rlegene/bfa.git` 3. `git clone https://github.com/rlegene/bfa.git`
4. `source ${HOME}/bfa/bin` 4. `source ${HOME}/bfa/bin`
- You can include this line in your .bash_profile if you want. - You can include this line in your .bash_profile if you want.
- It is perfectly safe to source it multiple times. - It is perfectly safe to source it multiple times.
5. run `start.sh` 5. Install this crontab: `@reboot bfa/network5445/start.sh`
6. create your contract (there is already one deployed, so do not confuse the two) - If you are running a sealer you MUST do this.
7. Type lines of text into `tsa-insert.sh` (end with ctrl-D) 6. run `start.sh`. This will start synchronizing and probably takes at least an hour.
- `tsa-verify.sh "<yourtexthere>"` 7. Change your node's settings with `syncmode.sh`
- If the text can not be found, it is because your insert transaction still isn't in the blockchain. Wait a bit and try again. - Do this before you have synced too much in the step before, as it might remove all your downloaded chain data and restart synchronizing the chain.
11. Try the basic `explorer.sh` 8. Wait for it to finish synchronizing.
12. consider this crontab: @reboot bfa/network5445/start.sh 9. Run `maymine.sh` to update your configuration (detects if you are allowed to seal/mine or not).
13. Try out walker.pl 10. Get some Ether from someone. Once you have some, you can try:
- Create your contract (there is already one deployed, but you can "overwrite" it with your own)
- Type lines of text into `tsa-insert.sh` (end with ctrl-D)
11. Free things to do with the BFA:
- Verify that the checksum has been seen with `tsa-verify.sh "<yourtexthere>"`
- If the text can not be found, it is because your insert transaction still isn't in the blockchain. Wait a bit and try again.
- Try the basic `explorer.sh`. It follows "latest" by default, but you can specify a block number as argument, e.g. `explorer.sh 0` to see genesis (block 0).
- Try out `walker.pl`
There are other "interesting" programs in the bin/ and src/ directories.
## start.sh ## start.sh
requires: **geth** requires: **geth**
...@@ -24,37 +33,55 @@ requires: **geth** ...@@ -24,37 +33,55 @@ requires: **geth**
Starts a node on the 5445 BFA test net. Creates a genesis.json if you don't have one already. Starts a node on the 5445 BFA test net. Creates a genesis.json if you don't have one already.
One is already included in this package, which will allow you to connect to the existing BFA testnet. One is already included in this package, which will allow you to connect to the existing BFA testnet.
## attach.sh
request: **geth**
Connects you to your running local geth.
## create.contract ## create.contract
requires: **geth**, **solc**, **jq** requires: **geth**, **solc**, **jq**
Compiles and deploys a contract to the blockchain. A local "node1" must already be running. Compiles and deploys a contract to the blockchain. A local "node1" must already be running and synchronized.
Argument 1 is the contract to compile. Argument 1 is the contract to compile.
Example: `create.contract src/contract.TimestampDocument.sol` Example: `create.contract src/contract.TimestampAuthority.sol`
## insert.sh ## tsa-insert.sh
requires: **geth** requires: **geth**
Inserts the checksum of a text into the compiled contract. Inserts the checksum of a text into the TSA.
## verify.sh ## tsa-verify.sh
requires: **geth** requires: **geth**
Returns the first blocknumber where the SHA256 checksum of a document was seen (0 for no match). Returns the first blocknumber where the SHA256 checksum of a text was seen. The timestamp can then be found in the block (with `explorer.sh` for instance).
## explorer.sh ## explorer.sh
requires: **curl**, **jq**, **tput** _(ncurses-bin)_ requires: **curl**, **jq**, **tput** _(ncurses-bin)_, _(curl)_
Simple script to look at blocks Simple script to look at blocks
## src/contract.TimestampDocument.sol
The initial Timestamp service.
## src/contract.TimeStampAuthority.sol ## src/contract.TimeStampAuthority.sol
Simpler TSA. The initial Timestamp service.
## walker.pl ## walker.pl
requires: **geth**, **perl**, __(libjson-perl)__ requires: **geth**, **perl**, __(libjson-perl)__
## rewind.sh
If your local node seems stuck and still connected, then you can try
this tool, and it'll back up a few blocks on the chain and try to catch
up from there. It really shouldn't happen, but it was seen a few times
when there were few sealers, that some nodes could get stuck on a side
fork.
## log.sh
Takes stdin and rotates it over a limited number of log files. We pipe
the output from `geth` into `log.sh`, so we still can read the log.
## sendether.sh
If you wish to give someone Ether, this script might be useful.
...@@ -5,82 +5,94 @@ if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ...@@ -5,82 +5,94 @@ if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env
source ${BFAHOME}/bin/libbfa.sh || exit 1 source ${BFAHOME}/bin/libbfa.sh || exit 1
bfaconfig max bfaconfig max
prereq tput prereq tput curl
# rpcport is set per node, in a file. Default is port 8545.
rpcport=8545
cd "${BFANETWORKDIR}" cd "${BFANETWORKDIR}"
test -r "$BFANODEDIR/rpcport" &&
rpcport=$( cat "$BFANODEDIR/rpcport" )
test -n "$rpcport"
width=$( tput cols ) width=$( tput cols )
height=$( tput lines ) height=$( tput lines )
function showblock function showblock
{ {
test "$1" = "latest" && local hexblock
set $maxblock if [ "$1" = "latest" ]
hexblock=$( printf '%x' $1 ) then
printf '\e[H\e[JBlock %d (0x%x)\n' $block $block hexblock="latest"
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 | else
jq -C . | hexblock=$( printf '0x%x' $(( $1 )) )
fold --width=$width | fi
head -$(( $height - 2 )) local json=$( geth_rpc eth_getBlockByNumber \"${hexblock}\" true )
printf '\e[m' if [ "${_onscreen}" != "$( echo $json | jq .hash )" ]
maxblock=$( latest ) then
hexblock=$( echo $json | jq -r .number )
printf '\e[H\e[JBlock %d (0x%x)\n' $(( $hexblock )) $(( $hexblock ))
echo $json |
jq -C . |
fold --width=$width |
head -$(( $height - 2 ))
_onscreen=$( echo $json | jq .hash )
printf '\e[mj=up k=down l=latest q=quit '
fi
} }
function latest function latest
{ {
curl \ local json=$( geth_rpc eth_blockNumber )
-H 'Content-type: application/json' \ local num=$( echo "$json" | jq -r . )
-X POST \ # This arithmetic expansion in bash converts a hex number prefixed with 0x to a decimal number
--data '{"jsonrpc":"2.0","method":"eth_getNumber","id":1}' \ echo $(( $num ))
http://127.0.0.1:$rpcport \ }
2>/dev/null |
jq -rM .result function tm
{
if [ "$block" = "latest" ]
then
timeout="-t 1"
else
timeout=
fi
} }
block=$1 block=$1
maxblock=$( latest ) maxblock=$( latest )
if [ -z "$block" ] test -z "$block" &&
then
block=latest block=latest
fi
test -n "$block"
showblock $block showblock $block
timeout= lastblock=
while read -r -s -n 1 ${timeout} -p "j=up k=down q=quit " tm
while :
do do
case "${REPLY,,}" in read -r -s -n 1 ${timeout} || true
q) maxblock=$( latest )
echo case "${REPLY^^}" in
exit 0 Q)
;; echo
k) exit 0
if [ "$block" = "latest" -a $maxblock -gt 0 ] ;;
then K)
block=$(( $maxblock - 1 )) if [ "$block" = "latest" -a $maxblock -gt 0 ]
else then
if [ $block -gt 0 ] block=$(( $maxblock - 1 ))
then else
block=$(( $block - 1 )) if [ $block -gt 0 ]
fi
fi
;;
j)
if [ "$block" != "latest" ]
then then
block=$(( $block + 1 )) block=$(( $block - 1 ))
fi fi
;; fi
*) ;;
continue J)
;; if [ "$block" != "latest" ]
esac then
showblock $block block=$(( $block + 1 ))
timeout= fi
test "$block" = "latest" && ;;
timeout="-t 1" L)
block="latest"
;;
# *)
# continue
# ;;
esac
lastblock=$block
showblock $block
tm
done done
...@@ -44,6 +44,47 @@ function geth_exec_js ...@@ -44,6 +44,47 @@ function geth_exec_js
geth_attach --exec "loadScript(\"$1\")" geth_attach --exec "loadScript(\"$1\")"
} }
function geth_exec
{
test -n "$1"
geth_attach --exec "$1"
}
function geth_rpc
{
bfaconfig nodedir
local cmd=$1
test -n "$cmd"
local params=
shift
if [ $# -gt 0 ]
then
params=',"params":['
while [ $# -gt 0 ]
do
params="${params}${1},"
shift
done
# Eat the last command and add a ]
params=${params/%,/]}
fi
local json=$(
curl \
-H 'Content-type: application/json' \
-X POST \
--data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" \
http://127.0.0.1:$rpcport \
2>/dev/null
)
test -n "$json"
if [ "$( echo "$json" | jq .error )" != "null" ]
then
echo "$json" | jq -r .error.message >&2
false
fi
echo "$json" | jq .result
}
function getnetworkid function getnetworkid
{ {
test -n "${BFANETWORKID}" && test -n "${BFANETWORKID}" &&
......
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