-
Notifications
You must be signed in to change notification settings - Fork 3
/
update_governance_info.sh
executable file
·175 lines (145 loc) · 6.08 KB
/
update_governance_info.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# Blacklisted words
BLACKLIST=("Airdrop" "airdrop" "AIRDROP")
# Check if PROPOSAL_TEXT contains any blacklisted word
contains_blacklisted_word() {
local text="$1"
for word in "${BLACKLIST[@]}"; do
if [[ "$text" == *"$word"* ]]; then
return 0
fi
done
return 1
}
# Function to fetch proposals with pagination
fetch_proposals() {
local endpoint="$1"
local next_key="$2"
local url="$endpoint/cosmos/gov/v1beta1/proposals"
# If next_key is provided, append it to the URL
if [ -n "$next_key" ]; then
url="$url?pagination.key=$next_key"
fi
local response=$(curl -s "$url")
local proposals=$(echo "$response" | jq -c '.proposals[]')
# Print the proposals to stdout
echo "$proposals"
# Check for pagination.next_key in the response
local new_next_key=$(echo "$response" | jq -r '.pagination.next_key')
# If next_key exists, recursively fetch the next page
if [ "$new_next_key" != "null" ]; then
fetch_proposals "$endpoint" "$new_next_key"
fi
}
# Loop through each chain in chains.json
jq -c '.chains[]' chains.json | while read chain; do
# Extract necessary details from the chain object
CHAIN_NAME=$(echo $chain | jq -r '.name')
OPERATOR_ACCOUNT=$(echo $chain | jq -r '.operator_account')
CHAIN_ID=$(echo $chain | jq -r '.chain_id')
if [ "$CHAIN_NAME" == "radix" ] || [ "$CHAIN_NAME" == "nomic" ]; then
echo "Skipping chain: $CHAIN_NAME"
continue
fi
echo "Processing chain: $CHAIN_NAME"
REST_ENDPOINT="https://rest.cosmos.directory:443/$CHAIN_NAME"
# Fetch all proposals using pagination
echo "Fetching all proposals for $CHAIN_NAME..."
ALL_PROPOSALS=$(fetch_proposals "$REST_ENDPOINT")
# Filter active proposals
ACTIVE_PROPOSALS=$(echo "$ALL_PROPOSALS" | jq -c 'select(.status == "PROPOSAL_STATUS_VOTING_PERIOD")')
ACTIVE_PROPOSALS_COUNT=$(echo "$ALL_PROPOSALS" | jq -c 'select(.status == "PROPOSAL_STATUS_VOTING_PERIOD")' | wc -l)
echo "active proposals: $ACTIVE_PROPOSALS_COUNT"
# Create MD file
OUTPUT_FILE="${CHAIN_NAME}_service_Governance.md"
rm $OUTPUT_FILE || true
echo "## Active Proposals" >> $OUTPUT_FILE
echo "- Chain ID: \`$CHAIN_ID\`"
echo "" >> $OUTPUT_FILE
# Add table headers
{
echo "| Proposal ID | Proposal Title | Voting End Time | VOTED |"
echo "|-------------|----------------|-----------------|-------|"
} >> $OUTPUT_FILE
if [ -n "$ACTIVE_PROPOSALS" ]; then
echo "$ACTIVE_PROPOSALS" | while read proposal; do
PROPOSAL_ID=$(echo $proposal | jq -r '.proposal_id')
if [ -z $PROPOSAL_ID ]; then
continue
fi
PROPOSAL_TITLE=$(echo $proposal | jq -r '.content.title')
VOTING_START_TIME=$(echo $proposal | jq -r '.voting_start_time')
VOTING_END_TIME=$(echo $proposal | jq -r '.voting_end_time')
PROPOSAL_TEXT=$(echo $proposal | jq -r '.content.description')
echo "processing proposal $PROPOSAL_ID"
# Fetch vote details for the operator
echo "Fetching vote details"
VOTE=$(curl -s "$REST_ENDPOINT/cosmos/gov/v1beta1/proposals/$PROPOSAL_ID/votes/$OPERATOR_ACCOUNT" | jq -r '.vote.option')
# resolve vote
VOTE_OPTION="unknown"
if [ -z "$VOTE" ] || [[ "$VOTE" == *"null"* ]]; then
VOTE_OPTION="⏳ NOT VOTED"
else
if [[ "$VOTE" == "VOTE_OPTION_YES" ]]; then
VOTE_OPTION="✅ YES"
elif [[ "$VOTE" == "VOTE_OPTION_NO" ]]; then
VOTE_OPTION="❌ NO"
elif [[ "$VOTE" == "VOTE_OPTION_ABSTAIN" ]]; then
VOTE_OPTION="🤷♂️ ABSTAIN"
else
if [[ "$VOTE" == *"VOTE_OPTION"* ]]; then
VOTE_OPTION=$(echo "VOTE_OPTION_ABSTAIN" | awk -F'_' '{print $3}')
fi
fi
fi
# Add table row for the proposal
echo "| $PROPOSAL_ID | $PROPOSAL_TITLE | $(date -d "$VOTING_END_TIME" +"%a %b %d %Y %T UTC") | $VOTE_OPTION |" >> $OUTPUT_FILE
done
echo "" >> $OUTPUT_FILE
echo "---" >> $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
echo "$ACTIVE_PROPOSALS" | while read proposal; do
echo "Fetching proposal details"
PROPOSAL_ID=$(echo $proposal | jq -r '.proposal_id')
if [ -z $PROPOSAL_ID ]; then
continue
fi
PROPOSAL_TITLE=$(echo $proposal | jq -r '.content.title')
VOTING_START_TIME=$(echo $proposal | jq -r '.voting_start_time')
VOTING_END_TIME=$(echo $proposal | jq -r '.voting_end_time')
PROPOSAL_TEXT=$(echo $proposal | jq -r '.content.description')
# Add detailed proposal info below the table
{
echo "### 🗳 $PROPOSAL_ID: $PROPOSAL_TITLE"
echo "- Voting Start: $(date -d "$VOTING_START_TIME" +"%a %b %d %Y %T UTC")"
echo "- Voting End: $(date -d "$VOTING_END_TIME" +"%a %b %d %Y %T UTC")"
echo ""
echo "<details>"
if contains_blacklisted_word "$PROPOSAL_TITLE" || contains_blacklisted_word "$PROPOSAL_TEXT"; then
echo "<summary>Text hidden (blacklist match)</summary>"
echo " "
else
echo "<summary>Proposal Text</summary>"
echo " "
echo "$PROPOSAL_TEXT"
fi
echo "</details>"
echo ""
echo "---"
echo ""
} >> $OUTPUT_FILE
echo "Saved details to $OUTPUT_FILE"
done
# remove last 3 lines
sed -i '$d' $OUTPUT_FILE && sed -i '$d' $OUTPUT_FILE && sed -i '$d' $OUTPUT_FILE
else
# put some info that there are currently no active proposals
echo " " >> $OUTPUT_FILE
echo "No current active proposals found for $CHAIN_NAME" >> $OUTPUT_FILE
fi
done
# move files to respective chain folders
for file in *_service_Governance.md; do
CHAINNAME="${file%_service_Governance.md}"
mv "$file" "./chains/$CHAINNAME/service_Governance.md"
done