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 @@
1. Install geth
- For Debian read doc/compiling-geth-on-debian.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`
4. `source ${HOME}/bfa/bin`
- You can include this line in your .bash_profile if you want.
- It is perfectly safe to source it multiple times.
5. run `start.sh`
6. create your contract (there is already one deployed, so do not confuse the two)
7. Type lines of text into `tsa-insert.sh` (end with ctrl-D)
- `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.
11. Try the basic `explorer.sh`
12. consider this crontab: @reboot bfa/network5445/start.sh
13. Try out walker.pl
5. Install this crontab: `@reboot bfa/network5445/start.sh`
- If you are running a sealer you MUST do this.
6. run `start.sh`. This will start synchronizing and probably takes at least an hour.
7. Change your node's settings with `syncmode.sh`
- 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.
8. Wait for it to finish synchronizing.
9. Run `maymine.sh` to update your configuration (detects if you are allowed to seal/mine or not).
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
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.
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
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.
Example: `create.contract src/contract.TimestampDocument.sol`
Example: `create.contract src/contract.TimestampAuthority.sol`
## insert.sh
## tsa-insert.sh
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**
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
requires: **curl**, **jq**, **tput** _(ncurses-bin)_
requires: **curl**, **jq**, **tput** _(ncurses-bin)_, _(curl)_
Simple script to look at blocks
## src/contract.TimestampDocument.sol
The initial Timestamp service.
## src/contract.TimeStampAuthority.sol
Simpler TSA.
The initial Timestamp service.
## walker.pl
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
source ${BFAHOME}/bin/libbfa.sh || exit 1
bfaconfig max
prereq tput
# rpcport is set per node, in a file. Default is port 8545.
rpcport=8545
prereq tput curl
cd "${BFANETWORKDIR}"
test -r "$BFANODEDIR/rpcport" &&
rpcport=$( cat "$BFANODEDIR/rpcport" )
test -n "$rpcport"
width=$( tput cols )
height=$( tput lines )
function showblock
{
test "$1" = "latest" &&
set $maxblock
hexblock=$( printf '%x' $1 )
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 |
jq -C . |
fold --width=$width |
head -$(( $height - 2 ))
printf '\e[m'
maxblock=$( latest )
local hexblock
if [ "$1" = "latest" ]
then
hexblock="latest"
else
hexblock=$( printf '0x%x' $(( $1 )) )
fi
local json=$( geth_rpc eth_getBlockByNumber \"${hexblock}\" true )
if [ "${_onscreen}" != "$( echo $json | jq .hash )" ]
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
{
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
local json=$( geth_rpc eth_blockNumber )
local num=$( echo "$json" | jq -r . )
# This arithmetic expansion in bash converts a hex number prefixed with 0x to a decimal number
echo $(( $num ))
}
function tm
{
if [ "$block" = "latest" ]
then
timeout="-t 1"
else
timeout=
fi
}
block=$1
maxblock=$( latest )
if [ -z "$block" ]
then
test -z "$block" &&
block=latest
fi
test -n "$block"
showblock $block
timeout=
while read -r -s -n 1 ${timeout} -p "j=up k=down q=quit "
lastblock=
tm
while :
do
case "${REPLY,,}" in
q)
echo
exit 0
;;
k)
if [ "$block" = "latest" -a $maxblock -gt 0 ]
then
block=$(( $maxblock - 1 ))
else
if [ $block -gt 0 ]
then
block=$(( $block - 1 ))
fi
fi
;;
j)
if [ "$block" != "latest" ]
read -r -s -n 1 ${timeout} || true
maxblock=$( latest )
case "${REPLY^^}" in
Q)
echo
exit 0
;;
K)
if [ "$block" = "latest" -a $maxblock -gt 0 ]
then
block=$(( $maxblock - 1 ))
else
if [ $block -gt 0 ]
then
block=$(( $block + 1 ))
block=$(( $block - 1 ))
fi
;;
*)
continue
;;
esac
showblock $block
timeout=
test "$block" = "latest" &&
timeout="-t 1"
fi
;;
J)
if [ "$block" != "latest" ]
then
block=$(( $block + 1 ))
fi
;;
L)
block="latest"
;;
# *)
# continue
# ;;
esac
lastblock=$block
showblock $block
tm
done
......@@ -44,6 +44,47 @@ function geth_exec_js
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
{
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