Skip to content

Commit

Permalink
add cleanupHolders() function
Browse files Browse the repository at this point in the history
  • Loading branch information
jdogresorg committed Apr 29, 2024
1 parent 1c31dee commit 9c85437
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 3 additions & 12 deletions indexer/includes/actions/dividend.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,9 @@ function btnsDividend($params=null, $data=null, $error=null){
// Remove SOURCE address from the TICK holders list
unset($holders[$data->SOURCE]);

// Handle TICK and DIVIDEND_TICK divisibility mismatches by cleaning up the holders list
if(!$error && $divisible!=$divisible2){
foreach($holders as $addr => $amount){

// Convert amount to integer
$holders[$addr] = bcadd($amount,0,0);

// Remove any 0 quantity records
if($holders[$addr]<1)
unset($holders[$addr]);
}
}
// Handle TICK and DIVIDEND_TICK divisibility mismatches by cleaning up the holders list (only deal with integer amounts)
if(!$error && $divisible!=$divisible2)
$holders = cleanupHolders($holders);

// Determine total amount of TICK
$data->HOLDER_TOTAL = 0;
Expand Down
12 changes: 11 additions & 1 deletion indexer/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,7 @@ function setActionParams($data=null, $params=null, $format=null){
// @param {tick} string Ticker name
// @param {block_index} integer Block Index
// @param {tx_index} integer tx_index of transaction
// TODO: Add support for 'escrowed' tokens (dispensers, orders, bets)
function getHolders( $tick=null, $block_index=null, $tx_index=null ){
global $mysqli, $dbase;
$holders = [];
Expand Down Expand Up @@ -2518,7 +2519,6 @@ function getAddressOwnership($address=null, $block_index=null, $tx_index=null){
return $data;
}


// Create record in `sweeps` table
function createSweep( $data=null ){
global $mysqli;
Expand Down Expand Up @@ -2646,4 +2646,14 @@ function processTransactionCreditsDebits($action=null, $data=null){
}
}

// Handle cleaning up the holders list to only deal with integer amounts
function cleanupHolders($holders){
foreach($holders as $addr => $amount){
$holders[$addr] = bcadd($amount,0,0);
if($holders[$addr]<1)
unset($holders[$addr]);
}
return $holders;
}

?>

0 comments on commit 9c85437

Please sign in to comment.