add rpc.sh script for easier JSON RPC calls

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-07-29 09:13:32 +02:00
parent e00e1041d4
commit 338e74d6e6
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
4 changed files with 40 additions and 0 deletions

View File

@ -6,6 +6,7 @@ beacon_node_service_home: 'C:\Users\{{ beacon_node_service_user_name }}'
beacon_node_service_path: '{{ beacon_node_service_home }}\{{ beacon_node_service_name }}'
beacon_node_service_bin_path: '{{ beacon_node_service_path }}\bin'
beacon_node_service_exe: '{{ beacon_node_service_bin_path }}\nimbus_beacon_node.exe'
beacon_node_rpc_script_path: '{{ beacon_node_service_path }}\rpc.sh'
beacon_node_repo_url: 'https://github.com/status-im/nimbus-eth2.git'
beacon_node_repo_branch: 'stable'

5
tasks/config.yml Normal file
View File

@ -0,0 +1,5 @@
---
- name: Create JSON RPC wrapper script
win_template:
src: 'rpc.sh.j2'
dest: '{{ beacon_node_rpc_script_path }}'

View File

@ -3,6 +3,7 @@
- import_tasks: user.yml
- import_tasks: install.yml
- import_tasks: build.yml
- import_tasks: config.yml
- import_tasks: service.yml
- import_tasks: validators.yml
when: beacon_node_dist_validators_enabled

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

@ -0,0 +1,33 @@
#!/usr/bin/env bash
# vim: set ft=sh:
set -euo pipefail
URL="http://localhost:{{ beacon_node_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.
curl -s -X POST --max-time 10 \
-H "Content-type:application/json" \
--data "${PAYLOAD}" \
"${URL}" | \
jq -e '., if .error != null then null|halt_error(2) else halt end'