2022-03-04 12:27:09 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# vim: set ft=sh:
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
URL="http://localhost:{{ nimbus_fluffy_rpc_port }}/"
|
|
|
|
|
|
|
|
METHOD="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ -z "${METHOD}" ]]; then
|
|
|
|
echo "No method specified!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -n "${@}" ]]; then
|
|
|
|
PARAMS=$(printf '%s,' "${@}")
|
|
|
|
PARAMS="${@%%,}\""
|
|
|
|
else
|
|
|
|
PARAMS=''
|
|
|
|
fi
|
|
|
|
|
|
|
|
PAYLOAD="{
|
|
|
|
\"id\": 1,
|
|
|
|
\"jsonrpc\": \"2.0\",
|
|
|
|
\"method\": \"${METHOD}\",
|
|
|
|
\"params\": [${PARAMS}]
|
|
|
|
}"
|
|
|
|
|
|
|
|
# The jq script checks if error exists and adjusts exit code.
|
2022-03-15 23:57:13 +00:00
|
|
|
curl -sSf -X POST --max-time 5 \
|
2022-03-04 12:27:09 +00:00
|
|
|
-H "Content-type:application/json" \
|
|
|
|
--data "${PAYLOAD}" \
|
|
|
|
"${URL}" | \
|
|
|
|
jq -e '., if .error != null then null|halt_error(2) else halt end'
|