Skip to content

Commit

Permalink
Merge pull request #4 from 01node/new-sdk
Browse files Browse the repository at this point in the history
improved sdk compatibility
  • Loading branch information
JiuKelo authored Mar 6, 2024
2 parents 864575a + f1ca383 commit 5cc36bb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
52 changes: 38 additions & 14 deletions proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def sendTelegramMessage(message):
url = f"https://api.telegram.org/bot{config['telegram']['token']}/sendMessage?chat_id={config['telegram']['chat_id']}&text={message}"
headers = { 'Accept': 'application/json' }
data = requests.get(url, headers=headers).text
data = requests.get(url, headers=headers, timeout=5).text

def debugPrint(output):
if config['loglevel'].upper() == "DEBUG":
Expand All @@ -21,19 +21,43 @@ def debugPrint(output):
debugPrint(f"Proposals with status {status}")
for network in config['networks']:
debugPrint(f" For netowrk {network}")
url = f"{config['networks'][network]['lcd']}/cosmos/gov/v1beta1/proposals?proposal_status={config['status'][status]}"
url = f"{config['networks'][network]['lcd']}/cosmos/gov/{config['networks'][network]['sdkVersion']}/proposals?proposal_status={config['status'][status]}"
debugPrint(f"{url}")
headers = { 'Accept': 'application/json' }
data = requests.get(url, headers=headers).text
try:
data = requests.get(url, headers=headers, timeout=5).text
except:
print(f"Unable to get data for network {network}, please check manually")
sendTelegramMessage(f"Unable to get data for network {network}, please check manually")
continue
proposals=json.loads(data)
for proposal in proposals['proposals']:
url = f"{config['networks'][network]['lcd']}/gov/proposals/{proposal['proposal_id']}/votes/{config['networks'][network]['voter']}"
data = requests.get(url, headers=headers).text
vote_data = json.loads(data)
try:
vote = vote_data['result']['options'][0]['option']
except:
vote = "DID_NOT_VOTE"
message=f"There is a proposal for {network.upper()} network on which you DID NOT vote\n\nProposal ID: {proposal['proposal_id']} -> {config['networks'][network]['proposal_link']}/{proposal['proposal_id']}"
sendTelegramMessage(message)
debugPrint(f" Porposal {proposal['proposal_id']} -> {vote}")
if "proposals" in proposals.keys():
for proposal in proposals['proposals']:
if config['networks'][network]['sdkVersion'] == "v1":
proposalId = proposal['id']
elif config['networks'][network]['sdkVersion'] == "v1beta1":
proposalId = proposal['proposal_id']

if config['networks'][network]['cosmosPrefix'] == "true":
cosmosPrefix = "cosmos/"
else:
cosmosPrefix = ""

url = f"{config['networks'][network]['lcd']}/{cosmosPrefix}gov/{config['networks'][network]['sdkVersion']}/proposals/{proposalId}/votes/{config['networks'][network]['voter']}"
debugPrint(url)
data = requests.get(url, headers=headers, timeout=5).text
vote_data = json.loads(data)
try:
vote = vote_data[config['networks'][network]['voteTag']]['options'][0]['option']
except:
vote = "DID_NOT_VOTE"
message=f"There is a proposal for {network.upper()} network on which {config['networks'][network]['pretyName']} DID NOT vote\n\nProposal ID: {proposalId} -> {config['networks'][network]['proposalLink']}/{proposalId}"
debugPrint(message)
sendTelegramMessage(message)
debugPrint(f" Porposal {proposalId} -> {vote}")
else:
print(f" Something wrong checking proposals for {network}. Please check manually")
sendTelegramMessage(f" Something wrong checking proposals for {network}. Please check manually")
continue
debugPrint("\n")

16 changes: 12 additions & 4 deletions proposals.toml.sample
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
loglevel = "info"
# loglevel = "debug"

[networks]
[networks.terra]
voter = "" # The Terra address you want to check if voted
lcd = "https://lcd.terra.dev"
proposal_link="https://station.terra.money/proposal"
[networks.osmosis]
voter = "osmo17mggn4znyeyg25wd7498qxl7r2jhgue8368hzp" # The address you want to monitor
lcd = "https://rest.cosmos.directory/osmosis" # LCD link for the network you want to monitor
proposalLink="https://www.mintscan.io/osmosis/proposals" # The "base" link where you usually check the porosals
cosmosPrefix = "true" # Depening on how cosmos-sdk is implemented you may need a cosmos prexif
voteTag = "vote" # Depening on how cosmos-sdk is implemented this can be "result" or "vote"
sdkVersion = "v1" # The SDK version used for LCD (usually "v1" or "v1beta1")
pretyName = "01node" # A Prety Name for the key you want to monitor (this will show up in alerts)

[telegram]
token = "" # Telegram Bot Token
Expand All @@ -16,3 +21,6 @@ VOTING_PERIOD = 2
# PASSED = 3
# REJECTED = 4
# FAILED = 5



0 comments on commit 5cc36bb

Please sign in to comment.