[#185] bin: Print human-readable errors
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
7448e2e777
commit
b725905b39
6 changed files with 65 additions and 35 deletions
|
@ -3,4 +3,4 @@
|
||||||
# Source env settings
|
# Source env settings
|
||||||
. .env
|
. .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"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# Source env settings
|
# Source env settings
|
||||||
. .env
|
. .env
|
||||||
. services/ir/.ir.env
|
. services/ir/.ir.env
|
||||||
|
source bin/helper.sh
|
||||||
|
|
||||||
# NeoGo binary path.
|
# NeoGo binary path.
|
||||||
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
|
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_IMG="${WALLET_IMG:-wallets/node-wallet.json}"
|
||||||
# Wallet password that would be entered automatically; '-' means no password
|
# Wallet password that would be entered automatically; '-' means no password
|
||||||
PASSWD="one"
|
PASSWD="one"
|
||||||
NETMAP_ADDR=`bin/resolve.sh netmap.neofs`
|
NETMAP_ADDR=$(bin/resolve.sh netmap.neofs)
|
||||||
|
|
||||||
# NeoFS configuration record: variable type [string|int|etc],
|
# NeoFS configuration record: variable type [string|int|etc],
|
||||||
# key is a string and value is a constant of given type
|
# key is a string and value is a constant of given type
|
||||||
|
@ -26,21 +27,23 @@ VALUE="${3}"
|
||||||
|
|
||||||
# Internal variables
|
# Internal variables
|
||||||
if [[ -z "${NEOFS_NOTARY_DISABLED}" ]]; then
|
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
|
else
|
||||||
ADDR=`cat ${WALLET} | jq -r .accounts[0].address`
|
ADDR=$(jq -r .accounts[0].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Change config value in side chain
|
# Change config value in side chain
|
||||||
echo "Changing ${KEY} configration value to ${VALUE}"
|
echo "Changing ${KEY} configration value to ${VALUE}"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \
|
./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \
|
||||||
-w ${WALLET_IMG} \
|
-w ${WALLET_IMG} \
|
||||||
-a ${ADDR} \
|
-a ${ADDR} \
|
||||||
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
|
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
|
||||||
${NETMAP_ADDR} \
|
${NETMAP_ADDR} \
|
||||||
setConfig bytes:beefcafe \
|
setConfig bytes:beefcafe \
|
||||||
string:${KEY} \
|
string:${KEY} \
|
||||||
${TYPE}:${VALUE} -- ${ADDR} || exit 1
|
${TYPE}:${VALUE} -- ${ADDR} || exit 1
|
||||||
|
|
||||||
# Update epoch to apply new configuration value
|
# Update epoch to apply new configuration value
|
||||||
./bin/tick.sh
|
./bin/tick.sh
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# Source env settings
|
# Source env settings
|
||||||
. .env
|
. .env
|
||||||
. services/ir/.ir.env
|
. services/ir/.ir.env
|
||||||
|
source bin/helper.sh
|
||||||
|
|
||||||
# NeoGo binary path.
|
# NeoGo binary path.
|
||||||
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
|
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
|
||||||
|
@ -14,14 +15,20 @@ PASSWD="-"
|
||||||
DEPOSIT="${1:-50}"
|
DEPOSIT="${1:-50}"
|
||||||
|
|
||||||
# Internal variables
|
# Internal variables
|
||||||
ADDR=`cat ${WALLET} | jq -r .accounts[0].address`
|
ADDR=$(jq -r .accounts[0].address < "${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 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
|
# Make deposit
|
||||||
|
# shellcheck disable=SC2086
|
||||||
./bin/passwd.exp ${PASSWD} ${NEOGO} wallet nep17 transfer \
|
./bin/passwd.exp ${PASSWD} ${NEOGO} wallet nep17 transfer \
|
||||||
-w ${WALLET} \
|
-w ${WALLET} \
|
||||||
-r http://main-chain.${LOCAL_DOMAIN}:30333 \
|
-r http://main-chain.${LOCAL_DOMAIN}:30333 \
|
||||||
--from ${ADDR} \
|
--from ${ADDR} \
|
||||||
--to ${CONTRACT_ADDR} \
|
--to ${CONTRACT_ADDR} \
|
||||||
--token GAS \
|
--token GAS \
|
||||||
--amount ${DEPOSIT}
|
--amount ${DEPOSIT}
|
||||||
|
|
6
bin/helper.sh
Normal file
6
bin/helper.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
die() {
|
||||||
|
echo "$(caller 0):" "$*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
|
@ -2,12 +2,21 @@
|
||||||
|
|
||||||
# Source env settings
|
# Source env settings
|
||||||
. .env
|
. .env
|
||||||
|
source bin/helper.sh
|
||||||
|
|
||||||
# NeoGo binary path.
|
# NeoGo binary path.
|
||||||
NEOGO="${NEOGO:-docker exec -it morph_chain neo-go}"
|
NEOGO="${NEOGO:-docker exec -it morph_chain neo-go}"
|
||||||
# NNS contract script hash
|
# 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 \
|
${NEOGO} contract testinvokefunction \
|
||||||
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
|
-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
|
"${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"
|
||||||
|
|
31
bin/tick.sh
31
bin/tick.sh
|
@ -3,6 +3,7 @@
|
||||||
# Source env settings
|
# Source env settings
|
||||||
. .env
|
. .env
|
||||||
. services/ir/.ir.env
|
. services/ir/.ir.env
|
||||||
|
source bin/helper.sh
|
||||||
|
|
||||||
# NeoGo binary path.
|
# NeoGo binary path.
|
||||||
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
|
NEOGO="${NEOGO:-docker exec -it main_chain neo-go}"
|
||||||
|
@ -16,29 +17,33 @@ PASSWD="one"
|
||||||
|
|
||||||
# Internal variables
|
# Internal variables
|
||||||
if [[ -z "${NEOFS_NOTARY_DISABLED}" ]]; then
|
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
|
else
|
||||||
ADDR=`cat ${WALLET} | jq -r .accounts[0].address`
|
ADDR=$(jq -r .accounts[0].address < "${WALLET}" || die "Cannot get address from ${WALLET}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Grep Morph block time
|
# Grep Morph block time
|
||||||
SIDECHAIN_PROTO="${SIDECHAIN_PROTO:-services/morph_chain/protocol.privnet.yml}"
|
SIDECHAIN_PROTO="${SIDECHAIN_PROTO:-services/morph_chain/protocol.privnet.yml}"
|
||||||
BLOCK_DURATION=`grep SecondsPerBlock < $SIDECHAIN_PROTO | awk '{print $2}'`
|
BLOCK_DURATION=$(grep SecondsPerBlock < "$SIDECHAIN_PROTO" | awk '{print $2}') \
|
||||||
NETMAP_ADDR=`bin/resolve.sh netmap.neofs`
|
|| die "Cannot fetch block duration"
|
||||||
|
NETMAP_ADDR=$(bin/resolve.sh netmap.neofs) || die "Cannot resolve netmap.neofs"
|
||||||
|
|
||||||
# Fetch current epoch value
|
# Fetch current epoch value
|
||||||
EPOCH=`${NEOGO} contract testinvokefunction -r \
|
EPOCH=$(${NEOGO} contract testinvokefunction \
|
||||||
http://morph-chain.${LOCAL_DOMAIN}:30333 \
|
-r "http://morph-chain.${LOCAL_DOMAIN}:30333" "${NETMAP_ADDR}" epoch \
|
||||||
${NETMAP_ADDR} \
|
| grep 'value' | awk -F'"' '{ print $4 }') \
|
||||||
epoch | grep 'value' | awk -F'"' '{ print $4 }'`
|
|| die "Cannot fetch epoch from netmap contract"
|
||||||
|
|
||||||
echo "Updating NeoFS epoch to $((EPOCH+1))"
|
echo "Updating NeoFS epoch to $((EPOCH+1))"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \
|
./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \
|
||||||
-w ${WALLET_IMG} \
|
-w ${WALLET_IMG} \
|
||||||
-a ${ADDR} \
|
-a ${ADDR} \
|
||||||
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
|
-r http://morph-chain.${LOCAL_DOMAIN}:30333 \
|
||||||
${NETMAP_ADDR} \
|
${NETMAP_ADDR} \
|
||||||
newEpoch int:$((EPOCH+1)) -- ${ADDR}:Global
|
newEpoch int:$((EPOCH+1)) -- ${ADDR}:Global
|
||||||
|
|
||||||
# Wait one Morph block to ensure the transaction broadcasted
|
# Wait one Morph block to ensure the transaction broadcasted
|
||||||
|
# shellcheck disable=SC2086
|
||||||
sleep $BLOCK_DURATION
|
sleep $BLOCK_DURATION
|
||||||
|
|
Loading…
Reference in a new issue