Skip to content

Commit

Permalink
Add API method to return just the circulating supply
Browse files Browse the repository at this point in the history
This returns the available supply minus the deposit supply
  • Loading branch information
Fuzzbawls committed Jul 25, 2017
1 parent f6bc9db commit 200e794
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions pages/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ <h4>Supported APIs</h4>
<li><strong><a href="/q/height">height</a></strong> &ndash; current height (incl. genesis block)</li>
<li><strong><a href="/q/reward">reward</a></strong> &ndash; current block reward</li>
<li><strong><a href="/q/supply">supply</a></strong> &ndash; total available supply</li>
<li><strong><a href="/q/circulatingsupply">circulatingsupply</a></strong> &ndash; total circulating supply</li>
</ul>
</div>
</div>
Expand Down
66 changes: 66 additions & 0 deletions q/circulatingsupply/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

$data_string = '{"jsonrpc":"2.0","id":"test","method":"getlastblockheader","params":" "}';

$ch = curl_init('http://192.168.1.15:24888/json_rpc');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);

$result = curl_exec($ch);

// print_r($result);

// Decode the response
$responseData = json_decode($result, TRUE);

// Print the date from the response
// print_r($responseData);

$hash = $responseData['result']['block_header']['hash'];

//print_r($hash);
curl_close($ch);

$data_string2 = '{"jsonrpc":"2.0","id":"test","method":"f_block_json","params":{"hash":"'.$hash.'"}}';


$ch2 = curl_init('http://192.168.1.15:24888/json_rpc');
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch2, CURLOPT_POSTFIELDS, $data_string2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string2))
);

$block = curl_exec($ch2);

// Decode the response
$blockData = json_decode($block, TRUE);


$supply = $blockData[result][block][alreadyGeneratedCoins];

$supply = number_format($supply / 1000000, 6, ".", "");

curl_close($ch2);

$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch3, CURLOPT_URL, 'http://192.168.1.15:24888/getinfo');
$result = curl_exec($ch3);
$getinfo = json_decode($result, TRUE);
curl_close($ch3);

$depamnt = $getinfo['full_deposit_amount'];

$depamnt = number_format($depamnt / 1000000, 6, ".", "");

print_r($supply - $depamnt);
?>
3 changes: 2 additions & 1 deletion q/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<li><a href="height">height/</a></li>
<li><a href="reward">reward/</a></li>
<li><a href="supply">supply/</a></li>
</ul>
<li><a href="circulatingsupply">circulatingsupply/</a></li>
</ul>

0 comments on commit 200e794

Please sign in to comment.