2017-08-28 20:34:36 +04:00
|
|
|
#! /usr/bin/env bash
|
2017-02-24 20:11:51 +04:00
|
|
|
|
2017-03-09 17:43:59 +04:00
|
|
|
client_dir="${client_dir:=$HOME/.tezos-client}"
|
|
|
|
client="${client:=tezos-client -base-dir $client_dir}"
|
2017-02-24 20:11:51 +04:00
|
|
|
|
2017-08-28 20:34:36 +04:00
|
|
|
client_dirs=()
|
|
|
|
|
|
|
|
init_sandboxed_client() {
|
|
|
|
|
|
|
|
id="$1"
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
rpc=$((18730 + id))
|
|
|
|
client_dir="$(mktemp -d -t tezos-client.XXXXXXXX)"
|
|
|
|
client_dirs+=("$client_dir")
|
2017-10-27 22:45:31 +04:00
|
|
|
local_client=${local_client:-$src_dir/_build/default/src/client_main.exe}
|
|
|
|
client="$local_client -base-dir $client_dir -addr 127.0.0.1 -port $rpc"
|
2017-08-28 20:34:36 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup_clients() {
|
|
|
|
rm -rf "${client_dirs[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-09 17:43:59 +04:00
|
|
|
## Waiter ##################################################################
|
|
|
|
|
|
|
|
wait_for_the_node_to_be_ready() {
|
2017-08-28 11:56:57 +04:00
|
|
|
local count=0
|
2017-03-09 17:43:59 +04:00
|
|
|
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
|
2017-02-24 20:11:51 +04:00
|
|
|
do
|
2017-08-28 11:56:57 +04:00
|
|
|
count=$((count+1))
|
|
|
|
if [ "$count" -ge 30 ]; then
|
|
|
|
echo " timeout."
|
|
|
|
exit 2
|
|
|
|
fi
|
2017-03-09 17:43:59 +04:00
|
|
|
printf "."
|
|
|
|
sleep 1
|
2017-02-24 20:11:51 +04:00
|
|
|
done
|
2017-03-09 17:43:59 +04:00
|
|
|
echo " done."
|
2017-02-24 20:11:51 +04:00
|
|
|
}
|
|
|
|
|
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-02-24 20:11:51 +04:00
|
|
|
}
|
|
|
|
|
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')..."
|
2017-04-17 04:25:20 +04:00
|
|
|
$client gen keys "my_identity"
|
2017-02-24 20:11:51 +04:00
|
|
|
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')..."
|
2017-04-17 04:25:20 +04:00
|
|
|
$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-02-24 20:11:51 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 17:43:59 +04:00
|
|
|
## Baker ###################################################################
|
|
|
|
|
|
|
|
check_baker() {
|
|
|
|
pids=$(pgrep -x tezos-client 2>/dev/null)
|
|
|
|
for pid in $pids; do
|
2017-11-01 15:13:23 +04:00
|
|
|
if grep -- "-baking" "/proc/$pid/cmdline" >/dev/null 2>&1 ; then
|
2017-03-09 17:43:59 +04:00
|
|
|
return 0
|
|
|
|
fi
|
2017-02-24 20:11:51 +04:00
|
|
|
done
|
2017-03-09 17:43:59 +04:00
|
|
|
return 1
|
2017-02-24 20:11:51 +04:00
|
|
|
}
|
|
|
|
|
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..."
|
2017-11-01 15:13:23 +04:00
|
|
|
exec $client launch daemon -baking -max-priority 64 "$@" > "$client_dir/baker.log"
|
2017-03-09 17:43:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
stop_baker() {
|
|
|
|
pids=$(pgrep -x tezos-client 2>/dev/null)
|
|
|
|
for pid in $pids; do
|
2017-11-01 15:13:23 +04:00
|
|
|
if grep -- "-baking" "/proc/$pid/cmdline" >/dev/null 2>&1 ; then
|
2017-03-09 17:43:59 +04:00
|
|
|
echo "Killing the baker..."
|
|
|
|
kill "$pid"
|
|
|
|
fi
|
2017-02-24 20:11:51 +04:00
|
|
|
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"
|
2017-02-24 20:11:51 +04:00
|
|
|
else
|
2017-03-09 17:43:59 +04:00
|
|
|
tail -f "$client_dir/baker.log"
|
2017-02-24 20:11:51 +04:00
|
|
|
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"
|
2017-02-24 20:11:51 +04:00
|
|
|
else
|
2017-03-09 17:43:59 +04:00
|
|
|
tail -f "$client_dir/endorser.log"
|
2017-02-24 20:11:51 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-08-28 11:56:57 +04:00
|
|
|
## Sandboxed client ########################################################
|
|
|
|
|
|
|
|
# key pairs from $src_dir/test/sandbox.json
|
|
|
|
|
2017-08-28 20:34:36 +04:00
|
|
|
BOOTSTRAP1_IDENTITY="tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"
|
2017-08-28 11:56:57 +04:00
|
|
|
BOOTSTRAP1_PUBLIC="edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"
|
|
|
|
BOOTSTRAP1_SECRET="edskRuR1azSfboG86YPTyxrQgosh5zChf5bVDmptqLTb5EuXAm9rsnDYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi"
|
|
|
|
|
2017-08-28 20:34:36 +04:00
|
|
|
BOOTSTRAP2_IDENTITY="tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN"
|
2017-08-28 11:56:57 +04:00
|
|
|
BOOTSTRAP2_PUBLIC="edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9"
|
|
|
|
BOOTSTRAP2_SECRET="edskRkJz4Rw2rM5NtabEWMbbg2bF4b1nfFajaqEuEk4SgU7eeDbym9gVQtBTbYo32WUg2zb5sNBkD1whRN7zX43V9bftBbtaKc"
|
|
|
|
|
2017-08-28 20:34:36 +04:00
|
|
|
BOOTSTRAP3_IDENTITY="tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU"
|
2017-08-28 11:56:57 +04:00
|
|
|
BOOTSTRAP3_PUBLIC="edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV"
|
|
|
|
BOOTSTRAP3_SECRET="edskS3qsqsNgdjUqeMsVcEwBn8dkZ5iDRz6aF21KhcCtRiAkWBypUSbicccR4Vgqm9UdW2Vabuos6seezqgbXTrmcbLUG4rdAC"
|
|
|
|
|
2017-08-28 20:34:36 +04:00
|
|
|
BOOTSTRAP4_IDENTITY="tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv"
|
2017-08-28 11:56:57 +04:00
|
|
|
BOOTSTRAP4_PUBLIC="edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU"
|
|
|
|
BOOTSTRAP4_SECRET="edskRg9qcPqaVQa6jXWNMU5p71tseSuR7NzozgqZ9URsVDi81wTyPJdFSBdeakobyHUi4Xgu61jgKRQvkhXrPmEdEUfiqfiJFL"
|
|
|
|
|
2017-08-28 20:34:36 +04:00
|
|
|
BOOTSTRAP5_IDENTITY="tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv"
|
2017-08-28 11:56:57 +04:00
|
|
|
BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
|
|
|
|
BOOTSTRAP5_SECRET="edskS7rLN2Df3nbS1EYvwJbWo4umD7yPM1SUeX7gp1WhCVpMFXjcCyM58xs6xsnTsVqHQmJQ2RxoAjJGedWfvFmjQy6etA3dgZ"
|
|
|
|
|
|
|
|
DICTATOR_SECRET="edskRhxswacLW6jF6ULavDdzwqnKJVS4UcDTNiCyiH6H8ZNnn2pmNviL7pRNz9kRxxaWQFzEQEcZExGHKbwmuaAcoMegj5T99z"
|
|
|
|
|
|
|
|
add_sandboxed_bootstrap_identities() {
|
|
|
|
|
|
|
|
${client} add public key bootstrap1 ${BOOTSTRAP1_PUBLIC}
|
|
|
|
${client} add secret key bootstrap1 ${BOOTSTRAP1_SECRET}
|
|
|
|
|
|
|
|
${client} add public key bootstrap2 ${BOOTSTRAP2_PUBLIC}
|
|
|
|
${client} add secret key bootstrap2 ${BOOTSTRAP2_SECRET}
|
|
|
|
|
|
|
|
${client} add public key bootstrap3 ${BOOTSTRAP3_PUBLIC}
|
|
|
|
${client} add secret key bootstrap3 ${BOOTSTRAP3_SECRET}
|
|
|
|
|
|
|
|
${client} add public key bootstrap4 ${BOOTSTRAP4_PUBLIC}
|
|
|
|
${client} add secret key bootstrap4 ${BOOTSTRAP4_SECRET}
|
|
|
|
|
|
|
|
${client} add public key bootstrap5 ${BOOTSTRAP5_PUBLIC}
|
|
|
|
${client} add secret key bootstrap5 ${BOOTSTRAP5_SECRET}
|
|
|
|
|
|
|
|
${client} add secret key dictator ${DICTATOR_SECRET}
|
|
|
|
|
|
|
|
}
|
2017-08-28 20:34:36 +04:00
|
|
|
|
|
|
|
activate_alpha() {
|
|
|
|
|
|
|
|
${client} \
|
|
|
|
-block genesis \
|
|
|
|
activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK \
|
|
|
|
with fitness 1 \
|
|
|
|
and key dictator
|
|
|
|
|
|
|
|
}
|