Add Starknet support to blocknumber.sh

- Detect Starknet paths and use starknet_getBlockWithTxHashes
- Return decimal block_number directly instead of hex conversion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
rob
2026-01-15 09:11:39 +00:00
parent 63b720f1e9
commit 6917005776

View File

@@ -23,15 +23,30 @@ for path in $pathlist; do
RPC_URL="https://$DOMAIN/$path" RPC_URL="https://$DOMAIN/$path"
response_file=$(mktemp) response_file=$(mktemp)
http_status_code=$(curl --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' $RPC_URL) # Detect Starknet vs Ethereum based on path
if echo "$path" | grep -qi "starknet"; then
rpc_method='{"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":1}'
is_starknet=true
else
rpc_method='{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}'
is_starknet=false
fi
http_status_code=$(curl --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data "$rpc_method" $RPC_URL)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [[ $http_status_code -eq 200 ]]; then if [[ $http_status_code -eq 200 ]]; then
response=$(cat "$response_file") response=$(cat "$response_file")
latest_block_number=$(echo "$response" | jq -r '.result.number') if $is_starknet; then
latest_block_number_decimal=$((16#${latest_block_number#0x})) # Starknet returns decimal block_number
latest_block_number_decimal=$(echo "$response" | jq -r '.result.block_number')
else
# Ethereum returns hex number
latest_block_number=$(echo "$response" | jq -r '.result.number')
latest_block_number_decimal=$((16#${latest_block_number#0x}))
fi
echo "$latest_block_number_decimal" echo "$latest_block_number_decimal"