Skip to content

Commit

Permalink
New scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mplatt8 committed May 29, 2024
1 parent 56f7bfb commit 46acb3f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ export RPC_HOST="127.0.0.1"
export RPC_PORT="18443"
export CONFIG_FILE="$HOME/.drivechain/drivechain.conf"



function drivechain_rpc {
local method=$1
local params=$2
local response=$(curl --user "${RPC_USER}:${RPC_PASSWORD}" -s -d '{"jsonrpc": "1.0", "id":"curltest", "method": "'"${method}"'", "params": ['"${params}"'] }' -H 'Content-Type: application/json' http://${RPC_HOST}:${RPC_PORT}/)

local error=$(echo $response | grep -o '"error":[^,}]*')
if [ -n "$error" ]; then
echo "RPC call failed: $error"
return 1
else
local result=$(echo $response | sed -n 's/.*"result":\([^,}]*\).*/\1/p')
echo "RPC call successful: $result"
echo $result
return 0
fi
}

function startdrivechain {
if [ $REINDEX -eq 1 ]; then
echo "drivechain will be reindexed"
Expand All @@ -17,7 +36,7 @@ function startdrivechain {

# Check if drivechain has started using curl
for i in {1..5}; do
curl --user "${RPC_USER}:${RPC_PASSWORD}" -d '{"method": "getblockcount", "params": []}' http://${RPC_HOST}:${RPC_PORT}/ > /dev/null
drivechain_rpc "getblockcount" > /dev/null
if [ $? -eq 0 ]; then
echo "drivechain curl successfully started"
break
Expand Down

0 comments on commit 46acb3f

Please sign in to comment.