-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-sig.sh
executable file
·86 lines (82 loc) · 2.66 KB
/
upload-sig.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Default network value
networkName="ronin-testnet"
# Function to print usage and exit
usage() {
echo "Usage: $0 -c <network>"
echo " -c: Specify the network (ronin-testnet or ronin-mainnet)"
exit 1
}
# Parse command-line options
while getopts "c:" opt; do
case $opt in
c)
case "$OPTARG" in
ronin-testnet)
child_folder="ronin-testnet"
networkName="ronin-testnet"
;;
ronin-mainnet)
child_folder="ronin-mainnet"
networkName="ronin-mainnet"
;;
*)
echo "Unknown network specified: $OPTARG"
usage
;;
esac
;;
*)
usage
;;
esac
done
# Shift the processed options out of the argument list
shift $((OPTIND - 1))
# Define the deployments folder by concatenating it with the child folder
folder="deployments/$child_folder"
# Check if the specified folder exists
if [ ! -d "$folder" ]; then
echo "Error: The specified folder does not exist for the selected network."
exit 1
fi
index=0
for file in "$folder"/*.json; do
# Check if the file exists and is a regular file
if [ -f "$file" ] && [ "$(basename "$file")" != ".chainId" ]; then
# Extract contractName and address from the JSON file
contractName=$(jq -r '.contractName' "$file")
# Check if contractName and address are not empty
if [ -n "$contractName" ]; then
# Increment the index
((index++))
(
# Initialize arrays to store events and errors keys
events_keys=()
errors_keys=()
# Get events and errors JSON data
events=$(forge inspect $contractName events)
errors=$(forge inspect $contractName errors)
# Extract keys and populate the arrays
while read -r key; do
events_keys+=("\"event $key\"")
done <<<"$(echo "$events" | jq -r 'keys[]')"
while read -r key; do
errors_keys+=("\"$key\"")
done <<<"$(echo "$errors" | jq -r 'keys[]')"
# Combine keys from events and errors
all_keys=("${events_keys[@]}" "${errors_keys[@]}")
echo cast upload-signature "${all_keys[@]}"
# Call cast upload-signature
cast upload-signature "${all_keys[@]}"
) &
else
echo "Error: Missing contractName or address in $file"
fi
fi
# Check if index is a multiple of 10, then wait
if [ $((index % 10)) -eq 0 ]; then
wait
fi
done
forge selectors upload --all &
wait