add rpc.sh wrapper script for calling JSON RPC

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-03-24 09:26:08 +01:00
parent 4f04bd279b
commit 3cd399520c
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
2 changed files with 40 additions and 2 deletions

View File

@ -10,7 +10,7 @@
- '{{ beacon_node_cont_vol }}/data'
- '{{ beacon_node_secrets_path }}'
- name: 'Create netkey file (optional)'
- name: Create netkey file (optional)
copy:
dest: '{{ beacon_node_cont_vol }}/{{ beacon_node_netkey_cont_path }}'
content: '{{ beacon_node_netkey }}'
@ -19,7 +19,14 @@
mode: 0600
when: beacon_node_netkey is defined
- name: Create JSON RPC wrapper script
template:
src: 'rpc.sh.j2'
dest: '{{ beacon_node_cont_vol }}/rpc.sh'
owner: 'root'
group: 'docker'
mode: 0750
- name: Verify network name
assert:
that: '{{ beacon_node_network in ["toledo", "pyrmont", "prater", "mainnet"] }}'

31
templates/rpc.sh.j2 Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env bash
# vim: set ft=sh:
URL="http://localhost:{{ beacon_node_rpc_port }}/"
METHOD="$1"
shift
PARAMS=("$@")
if [[ -z "${METHOD}" ]]; then
echo "No method specified!" >&2
exit 1
fi
if [[ -n "${PARAMS}" ]]; then
PARAMS_STR=$(printf '%s\",\"' "${PARAMS[@]}")
PARAMS_STR="\"${PARAMS_STR%%\",\"}\""
else
PARAMS_STR=''
fi
PAYLOAD="{
\"id\": 1,
\"jsonrpc\": \"2.0\",
\"method\": \"${METHOD}\",
\"params\": [${PARAMS_STR}]
}"
curl -s -X POST \
-H "Content-type:application/json" \
--data "${PAYLOAD}" \
"${URL}" | jq .