Proposals Watcher
Scan for new Upgrade proposals once every 30 minutes
Code is in PHP
This code scans for new upgrade proposals once every 30 minutes and outputs the data to a .json file (example - gov_proposals.json)
<?php
$jsonFilePath = '/var/www/html/gov/gov_proposals.json';
$jsonContents = file_get_contents($jsonFilePath);
$existingProposals = json_decode($jsonContents, true);
$final = $existingProposals;
$chains = [
"axelar",
"acrechain",
"canto",
"kujira",
"mars",
"meme",
"migaloo",
"oraichain",
"planq",
"provenance",
"stride",
"tenet",
"terra2",
"haqq"
];
foreach ($chains as $chain) {
$api = "https://rest.cosmos.directory/". $chain . "/cosmos/gov/v1beta1/proposals";
$rpc = "https://rpc.cosmos.directory/". $chain;
$ch = curl_init($api . '?proposal_status=2');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
$result = json_decode($resp, true);
if($result['code'] === 2)
{
$api = "https://rest.cosmos.directory/". $chain . "/cosmos/gov/v1/proposals";
$rpc = "https://rpc.cosmos.directory/". $chain;
$ch = curl_init($api . '?proposal_status=2');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
$result = json_decode($resp, true);
}
foreach ($result['proposals'] as $proposal) {
$pid = $proposal['proposal_id'];
if($pid === null) $pid = $proposal['id'];
$type = $proposal['content']['@type'];
$newProposal = [
"chain" => ucfirst($chain),
"pid" => $pid,
"rpc" => $rpc,
"api" => $api . '/' . $pid,
];
$exists = false;
foreach ($existingProposals as $existingProposal) {
if ($existingProposal['chain'] === $newProposal['chain'] && $existingProposal['pid'] === $newProposal['pid']) {
$exists = true;
break;
}
}
if (!$exists) {
$final[] = $newProposal;
}
}
}
echo json_encode($final, JSON_UNESCAPED_SLASHES);
?>Create a .sh file called ``gov_proposals.sh``
Setup a cronjob to run the above code once every 30 mins.
Now, gov_proposals.json will contain the following:
Update Status & Current Block number once every 5 Minutes
Read the gov_proposals.json file once every 5 minutes, update the status of the proposal, and update current block number of the blockchain.
Code is in PHP.
Create a .sh file called ``gov_updates.sh``
Setup a cronjob to run the above code once every 5 mins.
Last updated