-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateJSON.sh
executable file
·48 lines (39 loc) · 1.24 KB
/
updateJSON.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
set -euo pipefail # Stricter error handling
# Configuration
readonly JSONLOC="https://www.sentnl.io/wax.json"
readonly WALLET_PW=XXXXXXXXXXXXXXXXXXXXXXX
readonly EXEC="/home/charles/wax-backup/cleos.sh"
readonly BP_FILE=$(mktemp) # Safer temporary file handling
# Cleanup on script exit
trap 'rm -f "$BP_FILE"' EXIT
# Fetch and process JSON in one step
fetch_and_process_json() {
curl -sf "$JSONLOC" | jq -c '.' > "$BP_FILE" || {
echo "Error: Failed to fetch or process JSON from $JSONLOC"
exit 1
}
}
# Update blockchain with new JSON
update_blockchain() {
local producer
producer=$(jq -r '.producer_account_name' "$BP_FILE")
# Prepare JSON payload (more efficient than perl)
local json_payload
json_payload=$(jq -c -R '.' < "$BP_FILE")
# Execute blockchain updates in a controlled manner
{
"$EXEC" wallet unlock --password "$WALLET_PW" > /dev/null &&
"$EXEC" push action producerjson set "{\"owner\":\"$producer\",\"json\":$json_payload}" -p "$producer@active" &&
"$EXEC" wallet lock > /dev/null
} || {
echo "Error: Failed to update blockchain"
return 1
}
}
# Main execution
main() {
fetch_and_process_json
update_blockchain
}
main