update RPC scripts to support weaver
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
844fc81680
commit
a7d3a3fee8
@ -24,6 +24,8 @@ HOODI_RPC=(
|
|||||||
"https://rpc.sentio.xyz/hoodi"
|
"https://rpc.sentio.xyz/hoodi"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
HOODI_GATEKEEPER="0xc9D5f50e17eeEAF39E0D0cDbbcF4B04FA4A4Bbd6"
|
||||||
|
|
||||||
show_help() {
|
show_help() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: $(basename "$0") [OPTIONS]
|
Usage: $(basename "$0") [OPTIONS]
|
||||||
@ -58,20 +60,66 @@ spinner() {
|
|||||||
tput cnorm
|
tput cnorm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pad32() {
|
||||||
|
local h="$1"
|
||||||
|
h="${h#0x}"
|
||||||
|
printf "%064s" "$h" | tr ' ' '0'
|
||||||
|
}
|
||||||
|
|
||||||
|
build_calldata() {
|
||||||
|
local selector="$1"
|
||||||
|
local at_block="$2"
|
||||||
|
local s_hex
|
||||||
|
local b_hex
|
||||||
|
|
||||||
|
s_hex=$(printf "%x" 0)
|
||||||
|
b_hex=$(printf "%x" "$at_block")
|
||||||
|
|
||||||
|
echo "0x${selector#0x}$(pad32 "$s_hex")$(pad32 "$b_hex")"
|
||||||
|
}
|
||||||
|
|
||||||
|
decode_get_root() {
|
||||||
|
local res_json="$1"
|
||||||
|
local hex
|
||||||
|
|
||||||
|
hex=$(echo "$res_json" | grep -o '"result":"[^"]*' | cut -d'"' -f4)
|
||||||
|
if [[ -z "$hex" || "$hex" == "null" ]]; then
|
||||||
|
echo "ERROR"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
hex="${hex#0x}"
|
||||||
|
if (( ${#hex} < 128 )); then
|
||||||
|
echo "ERROR"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local word1="${hex:0:64}"
|
||||||
|
local word2="${hex:64:64}"
|
||||||
|
local num
|
||||||
|
|
||||||
|
num=$(printf "%d" "0x$word2" 2>/dev/null)
|
||||||
|
[[ -z "$num" ]] && num="$word2"
|
||||||
|
echo "0x${word1} ${num}"
|
||||||
|
}
|
||||||
|
|
||||||
check_network() {
|
check_network() {
|
||||||
local name=$1
|
local name=$1
|
||||||
shift
|
local gatekeeper=$2
|
||||||
|
shift 2
|
||||||
local rpcs=("$@")
|
local rpcs=("$@")
|
||||||
local target_dir="${OUT_DIR:-/tmp}"
|
local target_dir="${OUT_DIR:-/tmp}"
|
||||||
local tmp_file="${target_dir}/$(date +%s)_${name,,}"
|
local tmp_file="${target_dir}/$(date +%s)_${name,,}"
|
||||||
|
|
||||||
|
local root_width=66
|
||||||
|
local sess_width=6
|
||||||
local max_len=0
|
local max_len=0
|
||||||
for e in "${rpcs[@]}"; do (( ${#e} > max_len )) && max_len=${#e}; done
|
for e in "${rpcs[@]}"; do (( ${#e} > max_len )) && max_len=${#e}; done
|
||||||
[[ $max_len -lt 20 ]] && max_len=20
|
[[ $max_len -lt 20 ]] && max_len=20
|
||||||
|
|
||||||
local total_width=$(( max_len + 32 ))
|
local total_width=$(( max_len + 95 ))
|
||||||
local line=$(printf "%.0s-" $(seq 1 $total_width))
|
local line=$(printf "%.0s-" $(seq 1 $total_width))
|
||||||
local header_fmt="| %-${max_len}s | %-12s | %-10s |\n"
|
local header_fmt="| %-${max_len}s | %-10s | %-${root_width}s | %-${sess_width}s |\n"
|
||||||
|
|
||||||
(
|
(
|
||||||
for endpoint in "${rpcs[@]}"; do
|
for endpoint in "${rpcs[@]}"; do
|
||||||
@ -80,11 +128,15 @@ check_network() {
|
|||||||
hex=$(echo "$res_b" | grep -o '"result":"[^"]*' | cut -d'"' -f4)
|
hex=$(echo "$res_b" | grep -o '"result":"[^"]*' | cut -d'"' -f4)
|
||||||
[[ -n "$hex" && "$hex" != "null" ]] && blk=$(printf "%d" "$hex") || blk="ERROR"
|
[[ -n "$hex" && "$hex" != "null" ]] && blk=$(printf "%d" "$hex") || blk="ERROR"
|
||||||
|
|
||||||
res_l=$(curl -s -X POST -H "Content-Type: application/json" --max-time 10 \
|
root="N/A"
|
||||||
--data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock":"0x1","toBlock":"0x2"}],"id":1}' "$endpoint")
|
if [[ -n "$blk" && "$blk" != "ERROR" ]]; then
|
||||||
echo "$res_l" | grep -q '"result"' && ev="YES" || ev="NO"
|
calldata=$(build_calldata "$SELECTOR" "$blk")
|
||||||
|
payload=$(printf '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"%s","data":"%s"},"latest"],"id":1}' "$gatekeeper" "$calldata")
|
||||||
|
res_c=$(curl -s -X POST -H "Content-Type: application/json" --max-time 10 --data "$payload" "$endpoint")
|
||||||
|
root=$(decode_get_root "$res_c")
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$endpoint|$blk|$ev"
|
echo "$endpoint|$blk|$root"
|
||||||
done
|
done
|
||||||
) > "$tmp_file" &
|
) > "$tmp_file" &
|
||||||
|
|
||||||
@ -94,10 +146,17 @@ check_network() {
|
|||||||
spinner $worker_pid "$name"
|
spinner $worker_pid "$name"
|
||||||
|
|
||||||
local table_output="$line\n"
|
local table_output="$line\n"
|
||||||
table_output+=$(printf "$header_fmt" "Endpoint" "Block" "Events")"\n"
|
table_output+=$(printf "$header_fmt" "Endpoint" "Block" "Merkle Root" "Session")"\n"
|
||||||
table_output+="$line\n"
|
table_output+="$line\n"
|
||||||
while IFS="|" read -r url blk ev; do
|
while IFS="|" read -r url blk root; do
|
||||||
table_output+=$(printf "$header_fmt" "$url" "$blk" "$ev")"\n"
|
if [[ "$root" == *" "* ]]; then
|
||||||
|
hash="${root%% *}"
|
||||||
|
sess="${root##* }"
|
||||||
|
else
|
||||||
|
hash="$root"
|
||||||
|
sess="-"
|
||||||
|
fi
|
||||||
|
table_output+=$(printf "$header_fmt" "$url" "$blk" "$hash" "$sess")"\n"
|
||||||
done < "$tmp_file"
|
done < "$tmp_file"
|
||||||
table_output+="$line"
|
table_output+="$line"
|
||||||
|
|
||||||
@ -111,6 +170,7 @@ check_network() {
|
|||||||
CHOSEN_CHAIN=""
|
CHOSEN_CHAIN=""
|
||||||
BASE_OUT_DIR=""
|
BASE_OUT_DIR=""
|
||||||
CUSTOM_RPCS=""
|
CUSTOM_RPCS=""
|
||||||
|
SELECTOR="d4be7935"
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -132,14 +192,14 @@ if [[ -n "$CUSTOM_RPCS" ]]; then
|
|||||||
check_network "Custom" "${USER_RPC_ARRAY[@]}"
|
check_network "Custom" "${USER_RPC_ARRAY[@]}"
|
||||||
else
|
else
|
||||||
if [ "$CHOSEN_CHAIN" == "sepolia" ]; then
|
if [ "$CHOSEN_CHAIN" == "sepolia" ]; then
|
||||||
check_network "Sepolia" "${SEPOLIA_RPC[@]}"
|
check_network "Sepolia" "$SEPOLIA_GATEKEEPER" "${HOODI_RPC[@]}"
|
||||||
elif [ "$CHOSEN_CHAIN" == "mordor" ]; then
|
elif [ "$CHOSEN_CHAIN" == "mordor" ]; then
|
||||||
check_network "Mordor" "${MORDOR_RPC[@]}"
|
check_network "Mordor" "$MORDOR_GATEKEEPER" "${HOODI_RPC[@]}"
|
||||||
elif [ "$CHOSEN_CHAIN" == "hoodi" ]; then
|
elif [ "$CHOSEN_CHAIN" == "hoodi" ]; then
|
||||||
check_network "Hoodi" "${HOODI_RPC[@]}"
|
check_network "Hoodi" "$HOODI_GATEKEEPER" "${HOODI_RPC[@]}"
|
||||||
else
|
else
|
||||||
check_network "Sepolia" "${SEPOLIA_RPC[@]}"
|
check_network "Sepolia" "$SEPOLIA_GATEKEEPER" "${SEPOLIA_RPC[@]}"
|
||||||
check_network "Mordor" "${MORDOR_RPC[@]}"
|
check_network "Mordor" "$MORDOR_GATEKEEPER" "${MORDOR_RPC[@]}"
|
||||||
check_network "Hoodi" "${HOODI_RPC[@]}"
|
check_network "Hoodi" "$HOODI_GATEKEEPER" "${HOODI_RPC[@]}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user