ligo/scripts/client_lib.inc.sh

131 lines
3.7 KiB
Bash
Raw Normal View History

2017-03-09 17:43:59 +04:00
#! /bin/sh
2017-03-09 17:43:59 +04:00
client_dir="${client_dir:=$HOME/.tezos-client}"
client="${client:=tezos-client -base-dir $client_dir}"
2017-03-09 17:43:59 +04:00
## Waiter ##################################################################
wait_for_the_node_to_be_ready() {
if $client rpc call blocks/head/hash >/dev/null 2>&1; then return; fi
printf "Waiting for the node to initialize..."
sleep 1
while ! $client rpc call blocks/head/hash >/dev/null 2>&1
do
2017-03-09 17:43:59 +04:00
printf "."
sleep 1
done
2017-03-09 17:43:59 +04:00
echo " done."
}
2017-03-09 17:43:59 +04:00
wait_for_the_node_to_be_bootstraped() {
wait_for_the_node_to_be_ready
echo "Waiting for the node to synchronize with the network..."
$client bootstrapped
}
2017-03-09 17:43:59 +04:00
## Account #################################################################
may_create_identity() {
2017-05-19 07:14:14 +04:00
if ! $client get balance for "my_identity" >/dev/null 2>&1 ; then
2017-03-09 17:43:59 +04:00
echo "Generating new manager key (known as 'my_identity')..."
$client gen keys "my_identity"
fi
2017-05-19 07:14:14 +04:00
if ! $client get balance for "my_account" >/dev/null 2>&1 ; then
2017-03-09 17:43:59 +04:00
echo "Creating new account for 'my_identity' (known as 'my_account')..."
$client forget contract "my_account" >/dev/null 2>&1 || true
$client originate free account "my_account" for "my_identity"
2017-03-09 17:43:59 +04:00
fi
}
2017-03-09 17:43:59 +04:00
## Baker ###################################################################
check_baker() {
pids=$(pgrep -x tezos-client 2>/dev/null)
for pid in $pids; do
if grep -- "-mining" "/proc/$pid/cmdline" >/dev/null 2>&1 ; then
return 0
fi
done
2017-03-09 17:43:59 +04:00
return 1
}
2017-03-09 17:43:59 +04:00
run_baker() {
if check_baker; then
echo "Cannot run two bakers in the same container."
exit 1
fi
echo "Start baker..."
exec $client launch daemon -mining -max-priority 64 "$@" > "$client_dir/baker.log"
}
stop_baker() {
pids=$(pgrep -x tezos-client 2>/dev/null)
for pid in $pids; do
if grep -- "-mining" "/proc/$pid/cmdline" >/dev/null 2>&1 ; then
echo "Killing the baker..."
kill "$pid"
fi
done
}
2017-03-09 17:43:59 +04:00
log_baker() {
if ! check_baker ; then
echo
echo "##############################################"
echo "## ##"
echo "## Warning: The tezos baker is not running! ##"
echo "## ##"
echo "##############################################"
echo
tail "$client_dir/baker.log"
else
2017-03-09 17:43:59 +04:00
tail -f "$client_dir/baker.log"
fi
}
2017-03-09 17:43:59 +04:00
## Endorser ################################################################
check_endorser() {
pids=$(pgrep -x tezos-client 2>/dev/null)
for pid in $pids; do
if grep -- "-endorsement" "/proc/$pid/cmdline" > /dev/null 2>&1 ; then
return 0
fi
done
return 1
}
run_endorser() {
if check_endorser; then
echo "Cannot run two endorsers in the same container."
exit 1
fi
echo "Start endorser..."
exec $client launch daemon -endorsement "$@" > "$client_dir/endorser.log"
}
stop_endorser() {
pids=$(pgrep -x tezos-client 2>/dev/null)
for pid in $pids; do
if grep -- "-endorsement" "/proc/$pid/cmdline" > /dev/null 2>&1 ; then
kill "$pid"
fi
done
}
log_endorser() {
if ! check_endorser ; then
echo
echo "#################################################"
echo "## ##"
echo "## Warning: The tezos endorser is not running! ##"
echo "## ##"
echo "#################################################"
echo
tail "$client_dir/endorser.log"
else
2017-03-09 17:43:59 +04:00
tail -f "$client_dir/endorser.log"
fi
}