add rpc.sh wrapper, move console attach wrapper to attach.sh

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2021-03-19 12:52:00 +01:00
parent 704d1e3d57
commit c3df0ac68c
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
6 changed files with 59 additions and 17 deletions

View File

@ -4,7 +4,7 @@
- import_tasks: trusted_peers.yml
- import_tasks: container.yml
- import_tasks: firewall.yml
- import_tasks: wrapper.yml
- import_tasks: wrappers.yml
- import_tasks: save_enode.yml
- import_tasks: consul.yml
when: geth_consul_enabled

View File

@ -1,6 +0,0 @@
---
- name: Create geth attach wrapper
template:
src: geth-attach-wrapper.sh
dest: '/usr/local/bin/ageth-{{ geth_cont_name }}'
mode: 0755

16
tasks/wrappers.yml Normal file
View File

@ -0,0 +1,16 @@
---
- name: Create Geth console attach wrapper
template:
src: 'attach.sh.j2'
dest: '{{ geth_cont_vol }}/attach.sh'
owner: 'root'
group: 'docker'
mode: 0750
- name: Create Geth JSON RPC wrapper script
template:
src: 'rpc.sh.j2'
dest: '{{ geth_cont_vol }}/rpc.sh'
owner: 'root'
group: 'docker'
mode: 0750

12
templates/attach.sh.j2 Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
GETH_CONT_NAME="{{ geth_cont_name }}"
GETH_RPC_PORT="{{ geth_rpc_port }}"
GETH_RPC_ADDR="localhost"
GETH_RPC_URL="http://${GETH_RPC_ADDR}:${GETH_RPC_PORT}"
if [[ -z "$@" ]]; then
docker exec -it "${GETH_CONT_NAME}" geth attach "${GETH_RPC_URL}"
else
docker exec "${GETH_CONT_NAME}" geth attach "${GETH_RPC_URL}" --exec "$@"
fi

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
GETH_RPC_PORT="{{ geth_rpc_port }}"
GETH_CONT_NAME="{{ geth_cont_name }}"
if [[ -z "$@" ]]; then
docker exec -it "${GETH_CONT_NAME}" geth attach "http://localhost:${GETH_RPC_PORT}"
else
docker exec "${GETH_CONT_NAME}" geth attach "http://localhost:${GETH_RPC_PORT}" --exec "$@"
fi

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

@ -0,0 +1,30 @@
#!/usr/bin/env bash
URL="http://localhost:{{ geth_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 .