Script: some helpers for managing a local network.
This commit is contained in:
parent
09dcb59c14
commit
e665a4f7e6
102
scripts/client_lib.inc.sh
Normal file
102
scripts/client_lib.inc.sh
Normal file
@ -0,0 +1,102 @@
|
||||
#! /bin/bash
|
||||
|
||||
client=${client:=tezos-client}
|
||||
|
||||
function wait_for_the_node_to_be_ready() {
|
||||
local last_level
|
||||
local current_level
|
||||
while ! $client rpc call blocks/head/proto/context/level >/dev/null 2>&1
|
||||
do
|
||||
echo Waiting 10 seconds for the node to launch...
|
||||
sleep 10
|
||||
done
|
||||
## Wait for the level not to change for 30sec...
|
||||
last_level="$($client rpc call blocks/head/proto/context/level)"
|
||||
while [ "$last_level" != "$current_level" ]
|
||||
do
|
||||
echo Waiting 30 seconds for the node to synchronize...
|
||||
sleep 30
|
||||
last_level=$current_level
|
||||
current_level="$($client rpc call blocks/head/proto/context/level)"
|
||||
done
|
||||
}
|
||||
|
||||
function wait_for_a_new_block() {
|
||||
local last_level
|
||||
local current_level
|
||||
last_level="$($client rpc call blocks/head/proto/context/level)"
|
||||
current_level="$last_level"
|
||||
while [ "$last_level" = "$current_level" ]
|
||||
do
|
||||
echo Waiting 10 seconds for a block to be baked...
|
||||
sleep 10
|
||||
current_level="$($client rpc call blocks/head/proto/context/level)"
|
||||
done
|
||||
}
|
||||
|
||||
function create_identity() {
|
||||
if ! $client get balance my_identity 2> /dev/null 1> /dev/null
|
||||
then
|
||||
$client gen keys my_identity
|
||||
fi
|
||||
}
|
||||
|
||||
function create_account() {
|
||||
while ! $client get balance my_account 2> /dev/null 1> /dev/null
|
||||
do
|
||||
echo Emiting origination...
|
||||
$client forget contract my_account || true
|
||||
$client originate account my_account for my_identity \
|
||||
transfering 50,000.00 from bootstrap1
|
||||
wait_for_a_new_block
|
||||
done
|
||||
echo Adding some credit in the new account...
|
||||
$client transfer 50,000.00 from bootstrap2 to my_account
|
||||
$client transfer 50,000.00 from bootstrap3 to my_account
|
||||
$client transfer 50,000.00 from bootstrap4 to my_account
|
||||
echo Provisining some credit for bond deposit...
|
||||
$client transfer 50,000.00 from bootstrap5 to my_identity
|
||||
wait_for_a_new_block
|
||||
}
|
||||
|
||||
function wait_for_the_account() {
|
||||
local account
|
||||
while [ -z "$account" ]
|
||||
do
|
||||
echo Waiting 10 seconds for baker to create the account...
|
||||
sleep 10
|
||||
for contract in $($client list contracts \
|
||||
| grep -v "(default)" \
|
||||
| awk '{ print $1; }')
|
||||
do
|
||||
if $client get manager "$contract" | grep my_identity; then
|
||||
account=$($client get manager "$contract" | awk '{ print $1; }')
|
||||
echo account created
|
||||
fi
|
||||
done
|
||||
done
|
||||
$client remember contract my_account "$account"
|
||||
}
|
||||
|
||||
function start_baker() {
|
||||
declare -a identities
|
||||
if [ $# -eq 0 ]; then
|
||||
identities[0]=my_identity
|
||||
else
|
||||
identities=("$@")
|
||||
fi
|
||||
echo "Start baking for ${identities[*]}..."
|
||||
$client launch daemon -mining -max-priority 64 "${identities[@]}"
|
||||
}
|
||||
|
||||
function start_endorser() {
|
||||
declare -a identities
|
||||
if [ $# -eq 0 ]; then
|
||||
identities[0]=my_identity
|
||||
else
|
||||
identities=("$@")
|
||||
fi
|
||||
echo "Start endorsing for ${identities[*]}..."
|
||||
$client launch daemon -endorsement "${identities[@]}"
|
||||
}
|
||||
|
79
scripts/launch-client.sh
Executable file
79
scripts/launch-client.sh
Executable file
@ -0,0 +1,79 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
script_dir="$(dirname "$(readlink -f "$0")")"
|
||||
src_dir="$(dirname "$script_dir")"
|
||||
cd "$src_dir"
|
||||
|
||||
function usage() {
|
||||
echo "Small script client to a local and closed test network with a maximum of 9 nodes."
|
||||
echo
|
||||
echo "Usage: $0 <id> [ bake [id] | endorse [id] | exec ... ]"
|
||||
echo " where <id> should be an integer between 1 and 9."
|
||||
}
|
||||
|
||||
if [ $# -lt 2 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
id="$1"
|
||||
cmd="$2"
|
||||
shift 2
|
||||
|
||||
rpc=$((18730 + id))
|
||||
base_dir="/tmp/tezos-client-$rpc"
|
||||
|
||||
client="./tezos-client -base-dir $base_dir -addr 127.0.0.1 -port $rpc"
|
||||
|
||||
. "$script_dir/client_lib.inc.sh"
|
||||
|
||||
function cmd_bake() {
|
||||
wait_for_the_node_to_be_ready
|
||||
if [ $# -eq 0 ]; then
|
||||
create_identity
|
||||
create_account
|
||||
fi
|
||||
start_baker "$@"
|
||||
}
|
||||
|
||||
function cmd_endorse() {
|
||||
wait_for_the_node_to_be_ready
|
||||
if [ $# -eq 0 ]; then
|
||||
create_account
|
||||
endorsement
|
||||
fi
|
||||
start_endorser "$@"
|
||||
}
|
||||
|
||||
function cmd_exec() {
|
||||
$client "$@"
|
||||
}
|
||||
|
||||
function cmd_clear() {
|
||||
rm -fr "$base_dir"
|
||||
}
|
||||
|
||||
if [ ! -d "$base_dir" ] && [ "$cmd" != "clear" ]; then
|
||||
$client bootstrap
|
||||
fi
|
||||
|
||||
case $cmd in
|
||||
bake)
|
||||
cmd_bake "$@"
|
||||
;;
|
||||
endorse)
|
||||
cmd_endorse "$@"
|
||||
;;
|
||||
exec)
|
||||
cmd_exec "$@"
|
||||
;;
|
||||
clear)
|
||||
cmd_clear
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
41
scripts/launch-node.sh
Executable file
41
scripts/launch-node.sh
Executable file
@ -0,0 +1,41 @@
|
||||
#! /bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
script_dir="$(dirname "$(readlink -f "$0")")"
|
||||
src_dir="$(dirname "$script_dir")"
|
||||
cd "$src_dir"
|
||||
|
||||
if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
|
||||
echo "Small script to launch local and closed test network with a maximum of 9 nodes."
|
||||
echo
|
||||
echo "Usage: $0 <id>"
|
||||
echo " where <id> should be an integer between 1 and 9."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
id="$1"
|
||||
shift 1
|
||||
|
||||
port=$((19730 + id))
|
||||
rpc=$((18730 + id))
|
||||
expected_pow=10
|
||||
data_dir="$(mktemp -td tezos-node-XXXXX)"
|
||||
peers="--no-bootstrap-peers $(seq -f '--peer localhost:1973%.f' 1 9) --closed"
|
||||
node="$src_dir/tezos-node"
|
||||
|
||||
cleanup () {
|
||||
set +e
|
||||
echo Cleaning up...
|
||||
# rm -rf "$data_dir"
|
||||
}
|
||||
trap cleanup EXIT INT
|
||||
|
||||
$node config init \
|
||||
--data-dir "$data_dir" \
|
||||
--net-addr ":$port" \
|
||||
--rpc-addr "[::]:$rpc" \
|
||||
--expected-pow "$expected_pow" \
|
||||
--connections 2 $peers
|
||||
$node identity generate "$expected_pow" --data-dir "$data_dir"
|
||||
$node run --data-dir "$data_dir" "$@"
|
Loading…
Reference in New Issue
Block a user