Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Aug 11, 2023
1 parent 0f5cc16 commit 7afc192
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions scripts/gen_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ set -euo pipefail

OASIS_CMD=$(readlink -f ./oasis)
IN=$(readlink -f $1)
touch "$2" # XXX MacOS: readlink -f does not work if file does not exist. readlink -m is not implemented yet.
OUT=$(readlink -f $2)
EXAMPLE_NAME=$(echo $(basename $(dirname $IN)))
EXAMPLE_NAME="$(basename $(dirname $IN))"
USER_CFG_DIR="${HOME}/.config/oasis"
CUSTOM_CFG_DIR="$(dirname $IN)/config"
CFG_DIR="/tmp/cli_examples/${EXAMPLE_NAME}"
Expand All @@ -27,7 +28,7 @@ fi
# Prepare clean config file for the example or take the example-specific one, if it exists.
function init_cfg() {
# Init config in the first scenario step only.
if [ "$IN" != "$(ls $(dirname $IN)/* | head -n1)" ]; then
if [ "$IN" != "$(ls $(dirname $IN)/*.in | head -n1)" ]; then
return
fi

Expand Down Expand Up @@ -75,26 +76,12 @@ export TZ=UTC

# Execute the Oasis CLI and store the PID.
cd $(dirname ${IN})
${CMD} > ${OUT} &
${CMD} > ${OUT}

PID=$!
while ! test -f ${OUT} || ! grep -q "Sign this transaction" "${OUT}" && ps -p ${PID} > /dev/null
do
sleep 0.5
done

kill -9 ${PID} 2&>/dev/null || true

# Trim the transaction submission notice (In case you are using a hardware-based signer...).
if [ "$YES_FLAG" != "" ]
then
head -n -1 ${OUT} > ${OUT}.tmp
mv ${OUT}.tmp ${OUT}
fi

# Trim "Sign this transaction" prompt, if present.
if tail -n 1 ${OUT} | grep -q "Sign this transaction"
# Trim last two lines, if in non-interactive mode ("Sign this transaction?" and "In case you are using a hardware-based signer...").
if [ "$YES_FLAG" != "" ] && [ grep -q "Sign this transaction?" "${OUT}" ]
then
head -n -1 ${OUT} > ${OUT}.tmp
OUT_LINES=$(($(wc -l ${OUT} | cut -d ' ' -f 1)-2)) # XXX MacOS: head -n -2 is not implemented yet
head -n ${OUT_LINES} ${OUT} > ${OUT}.tmp
mv ${OUT}.tmp ${OUT}
fi

0 comments on commit 7afc192

Please sign in to comment.