2021-03-19 11:52:00 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-03-25 12:56:04 +00:00
|
|
|
# vim: set ft=sh:
|
|
|
|
set -euo pipefail
|
2021-03-19 11:52:00 +00:00
|
|
|
|
|
|
|
URL="http://localhost:{{ geth_rpc_port }}/"
|
|
|
|
|
|
|
|
METHOD="$1"
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ -z "${METHOD}" ]]; then
|
|
|
|
echo "No method specified!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-03-25 12:56:04 +00:00
|
|
|
if [[ -n "${@}" ]]; then
|
|
|
|
PARAMS=$(printf '%s\",\"' "${@}")
|
|
|
|
PARAMS="\"${PARAMS_STR%%\",\"}\""
|
2021-03-19 11:52:00 +00:00
|
|
|
else
|
2021-03-25 12:56:04 +00:00
|
|
|
PARAMS=''
|
2021-03-19 11:52:00 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
PAYLOAD="{
|
|
|
|
\"id\": 1,
|
|
|
|
\"jsonrpc\": \"2.0\",
|
|
|
|
\"method\": \"${METHOD}\",
|
2021-03-25 12:56:04 +00:00
|
|
|
\"params\": [${PARAMS}]
|
2021-03-19 11:52:00 +00:00
|
|
|
}"
|
|
|
|
|
|
|
|
curl -s -X POST \
|
|
|
|
-H "Content-type:application/json" \
|
|
|
|
--data "${PAYLOAD}" \
|
2021-03-25 12:56:04 +00:00
|
|
|
"${URL}" | \
|
|
|
|
jq -e '., if .error != null then null|halt_error(2) else halt end'
|