Skip to content

Commit

Permalink
update getTokenSupply() to use CAST in sql queries
Browse files Browse the repository at this point in the history
- fixes issues with amounts being returned in scientific E notation instead of integer/decimal
  • Loading branch information
jdogresorg committed Aug 23, 2023
1 parent 7562f48 commit 47b88e6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions indexer/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,10 @@ function getTokenSupply( $tick=null ){
$tick_id = $tick;
if($type==='string' && !is_numeric($tick))
$tick_id = createTicker($tick);
// Get Credits
$sql = "SELECT SUM(amount) as credits FROM credits WHERE tick_id='{$tick_id}'";
// Get info on decimal precision
$decimals = getTokenDecimalPrecision($tick_id);
// Get Credits
$sql = "SELECT CAST(SUM(amount) AS DECIMAL(60,$decimals)) as credits FROM credits WHERE tick_id='{$tick_id}'";
$results = $mysqli->query($sql);
if($results){
if($results->num_rows){
Expand All @@ -1238,7 +1240,7 @@ function getTokenSupply( $tick=null ){
byeLog('Error while trying to get list of credits');
}
// Get Debits
$sql = "SELECT SUM(amount) as debits FROM debits WHERE tick_id='{$tick_id}'";
$sql = "SELECT CAST(SUM(amount) AS DECIMAL(60,$decimals)) as debits FROM debits WHERE tick_id='{$tick_id}'";
$results = $mysqli->query($sql);
if($results){
if($results->num_rows){
Expand All @@ -1248,12 +1250,10 @@ function getTokenSupply( $tick=null ){
} else {
byeLog('Error while trying to get list of debits');
}
$decimals = getTokenDecimalPrecision($tick_id);
$supply = bcsub($credits, $debits, $decimals);
$supply = bcsub($credits, $debits, $decimals);
return $supply;
}


// Handle doing VERY lose validation on an address
function isCryptoAddress( $address=null ){
$len = strlen($address);
Expand Down

0 comments on commit 47b88e6

Please sign in to comment.