Proposals Watcher
<?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);
?>Last updated