Skip to content

Instantly share code, notes, and snippets.

@pavelTU
Last active October 12, 2022 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelTU/d59fab088a6237878447bd3d1ecdea65 to your computer and use it in GitHub Desktop.
Save pavelTU/d59fab088a6237878447bd3d1ecdea65 to your computer and use it in GitHub Desktop.
Course on indexers: indexing smart-contract with Que Pasa and displaying data from PostgeSQL
<!DOCTYPE html>
<head>
<title>Signum.loan test</title>
</head>
<body>
<p>Smallest offers on Signum</p>
<?php
$dbhost = 'localhost';
$dbname= 'liquidity';
$dbuser = 'postgres';
$dbpass = '1234';
$dbconn = pg_connect("host=$dbhost dbname=$dbname user=$dbuser password=$dbpass")
or die('Could not connect: ' . pg_last_error());
$sql = 'SELECT "amount", "premium", "deadline", "tx_context_id" FROM "storage.offers" WHERE "amount" IS NOT NULL
AND "lender" IS NOT NULL LIMIT 10 ';
$result = pg_query($dbconn, $sql) or die('Error message: ' . pg_last_error());
echo "<table border='2'>
<tr>
<th>Amount</th>
<th>Premium</th>
<th>Deadline</th>
<th>Lender's APR</th>
<th>Link to NFT</th>
</tr>";
while($row = pg_fetch_array($result))
{
$p = $row['premium']/1000000;
$a = $row['amount']/1000000;
$d = $row['deadline'];
$dd = 365 / $d;
$apr = ceil(($p / $a) * $dd * 100);
$id = $row['tx_context_id'];
$sql2 = 'SELECT "contract", "id_1" FROM "storage.offers.collateral" WHERE "tx_context_id" = ';
$sql2 .= $id;
$result2 = pg_query($dbconn, $sql2) or die('Error message: ' . pg_last_error());
$row2 = pg_fetch_array($result2);
echo "<tr>";
echo "<td>" . $a . " tez </td>";
echo "<td>" . $p . " tez </td>";
echo "<td>" . $d . " days </td>";
echo "<td>" . $apr . "% </td>";
echo "<td><a href=\"https://tzkt.io/" . $row2['contract'] . "/tokens/" . $row2['id_1'] . "/transfers" . "\">Link</a></td>";
echo "</tr>";
};
echo "</table>";
?>
<?php pg_close($dbconn); ?>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment