From 9c85437e4f3aeb2df8e72e4f8992b87a7634ad43 Mon Sep 17 00:00:00 2001 From: J-Dog Date: Mon, 29 Apr 2024 13:28:00 -0700 Subject: [PATCH] add `cleanupHolders()` function --- indexer/includes/actions/dividend.php | 15 +++------------ indexer/includes/functions.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/indexer/includes/actions/dividend.php b/indexer/includes/actions/dividend.php index a0b1456..8efefeb 100644 --- a/indexer/includes/actions/dividend.php +++ b/indexer/includes/actions/dividend.php @@ -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; diff --git a/indexer/includes/functions.php b/indexer/includes/functions.php index 80554bf..e1cfc90 100644 --- a/indexer/includes/functions.php +++ b/indexer/includes/functions.php @@ -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 = []; @@ -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; @@ -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; +} + ?>