[#185] bin: Print human-readable errors

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-10 11:32:20 +03:00 committed by Anastasia Prasolova
parent 7448e2e777
commit b725905b39
6 changed files with 65 additions and 35 deletions

View file

@ -3,4 +3,4 @@
# Source env settings
. .env
ln -sf $(pwd)/services/storage/s04tls.crt ${CA_CERTS_TRUSTED_STORE}/s04.${LOCAL_DOMAIN}.tls.crt
ln -sf "$(pwd)/services/storage/s04tls.crt" "${CA_CERTS_TRUSTED_STORE}/s04.${LOCAL_DOMAIN}.tls.crt"

View file

@ -3,6 +3,7 @@
# Source env settings
. .env
. services/ir/.ir.env
source bin/helper.sh
# NeoGo binary path.
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
@ -12,7 +13,7 @@ WALLET="${WALLET:-services/chain/node-wallet.json}"
WALLET_IMG="${WALLET_IMG:-wallets/node-wallet.json}"
# Wallet password that would be entered automatically; '-' means no password
PASSWD="one"
NETMAP_ADDR=`bin/resolve.sh netmap.neofs`
NETMAP_ADDR=$(bin/resolve.sh netmap.neofs)
# NeoFS configuration record: variable type [string|int|etc],
# key is a string and value is a constant of given type
@ -26,21 +27,23 @@ VALUE="${3}"
# Internal variables
if [[ -z "${NEOFS_NOTARY_DISABLED}" ]]; then
ADDR=`cat ${WALLET} | jq -r .accounts[2].address`
ADDR=$(jq -r .accounts[2].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
else
ADDR=`cat ${WALLET} | jq -r .accounts[0].address`
ADDR=$(jq -r .accounts[0].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
fi
# Change config value in side chain
echo "Changing ${KEY} configration value to ${VALUE}"
# shellcheck disable=SC2086
./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \
-w ${WALLET_IMG} \
-a ${ADDR} \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
setConfig bytes:beefcafe \
string:${KEY} \
${TYPE}:${VALUE} -- ${ADDR} || exit 1
-w ${WALLET_IMG} \
-a ${ADDR} \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
setConfig bytes:beefcafe \
string:${KEY} \
${TYPE}:${VALUE} -- ${ADDR} || exit 1
# Update epoch to apply new configuration value
./bin/tick.sh

View file

@ -3,6 +3,7 @@
# Source env settings
. .env
. services/ir/.ir.env
source bin/helper.sh
# NeoGo binary path.
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
@ -14,14 +15,20 @@ PASSWD="-"
DEPOSIT="${1:-50}"
# Internal variables
ADDR=`cat ${WALLET} | jq -r .accounts[0].address`
CONTRACT_ADDR=`${NEOGO} util convert ${NEOFS_IR_CONTRACTS_NEOFS} | grep 'LE ScriptHash to Address' | awk '{print $5}' | grep -oP [A-z0-9]+`
ADDR=$(jq -r .accounts[0].address < "${WALLET}" \
|| die "Cannot get address from wallet: ${WALLET}")
CONTRACT_ADDR=$(${NEOGO} util convert "${NEOFS_IR_CONTRACTS_NEOFS}" \
| grep 'LE ScriptHash to Address' \
| awk '{print $5}' \
| grep -oP "[A-z0-9]+" \
|| die "Cannot parse contract address: ${NEOFS_IR_CONTRACTS_NEOFS}")
# Make deposit
# shellcheck disable=SC2086
./bin/passwd.exp ${PASSWD} ${NEOGO} wallet nep17 transfer \
-w ${WALLET} \
-r http://main-chain.${LOCAL_DOMAIN}:30333 \
--from ${ADDR} \
--to ${CONTRACT_ADDR} \
--token GAS \
--amount ${DEPOSIT}
-w ${WALLET} \
-r http://main-chain.${LOCAL_DOMAIN}:30333 \
--from ${ADDR} \
--to ${CONTRACT_ADDR} \
--token GAS \
--amount ${DEPOSIT}

6
bin/helper.sh Normal file
View file

@ -0,0 +1,6 @@
set -eo pipefail
die() {
echo "$(caller 0):" "$*" >&2
exit 1
}

View file

@ -2,12 +2,21 @@
# Source env settings
. .env
source bin/helper.sh
# NeoGo binary path.
NEOGO="${NEOGO:-docker exec -it morph_chain neo-go}"
# NNS contract script hash
NNS_ADDR=`curl -s --data '{ "id": 1, "jsonrpc": "2.0", "method": "getcontractstate", "params": [1] }' http://morph-chain.${LOCAL_DOMAIN}:30333/ | jq -r '.result.hash'`
output=$(curl -s --data '{ "id": 1, "jsonrpc": "2.0", "method": "getcontractstate", "params": [1] }' \
"http://morph-chain.${LOCAL_DOMAIN}:30333/") \
|| die "Cannot fetch NNS contract state"
NNS_ADDR=$(jq -r '.result.hash' <<< "$output") \
|| die "Cannot parse NNS contract hash: $NNS_ADDR"
${NEOGO} contract testinvokefunction \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
${NNS_ADDR} resolve string:${1} int:16 | jq -r '.stack[0].value | if type=="array" then .[0].value else . end' | base64 -d
-r "http://morph-chain.${LOCAL_DOMAIN}:30333" \
"${NNS_ADDR}" resolve string:"${1}" int:16 \
| jq -r '.stack[0].value | if type=="array" then .[0].value else . end' \
| base64 -d \
|| die "Cannot invoke 'NNS.resolve' $output"

View file

@ -3,6 +3,7 @@
# Source env settings
. .env
. services/ir/.ir.env
source bin/helper.sh
# NeoGo binary path.
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
@ -16,29 +17,33 @@ PASSWD="one"
# Internal variables
if [[ -z "${NEOFS_NOTARY_DISABLED}" ]]; then
ADDR=`cat ${WALLET} | jq -r .accounts[2].address`
ADDR=$(jq -r .accounts[2].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
else
ADDR=`cat ${WALLET} | jq -r .accounts[0].address`
ADDR=$(jq -r .accounts[0].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
fi
# Grep Morph block time
SIDECHAIN_PROTO="${SIDECHAIN_PROTO:-services/morph_chain/protocol.privnet.yml}"
BLOCK_DURATION=`grep SecondsPerBlock < $SIDECHAIN_PROTO | awk '{print $2}'`
NETMAP_ADDR=`bin/resolve.sh netmap.neofs`
BLOCK_DURATION=$(grep SecondsPerBlock < "$SIDECHAIN_PROTO" | awk '{print $2}') \
|| die "Cannot fetch block duration"
NETMAP_ADDR=$(bin/resolve.sh netmap.neofs) || die "Cannot resolve netmap.neofs"
# Fetch current epoch value
EPOCH=`${NEOGO} contract testinvokefunction -r \
http://morph-chain.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
epoch | grep 'value' | awk -F'"' '{ print $4 }'`
EPOCH=$(${NEOGO} contract testinvokefunction \
-r "http://morph-chain.${LOCAL_DOMAIN}:30333" "${NETMAP_ADDR}" epoch \
| grep 'value' | awk -F'"' '{ print $4 }') \
|| die "Cannot fetch epoch from netmap contract"
echo "Updating NeoFS epoch to $((EPOCH+1))"
# shellcheck disable=SC2086
./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \
-w ${WALLET_IMG} \
-a ${ADDR} \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
newEpoch int:$((EPOCH+1)) -- ${ADDR}:Global
-w ${WALLET_IMG} \
-a ${ADDR} \
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
${NETMAP_ADDR} \
newEpoch int:$((EPOCH+1)) -- ${ADDR}:Global
# Wait one Morph block to ensure the transaction broadcasted
# shellcheck disable=SC2086
sleep $BLOCK_DURATION