From 7562f4819765ce31945ffde4f183ea5f4d3d1a83 Mon Sep 17 00:00:00 2001 From: J-Dog Date: Wed, 23 Aug 2023 11:49:18 -0700 Subject: [PATCH 1/6] update `getAssetInfo()` to only lookup assets using name fixes issue #14 --- indexer/includes/functions.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/indexer/includes/functions.php b/indexer/includes/functions.php index a9dbceb..ff61331 100644 --- a/indexer/includes/functions.php +++ b/indexer/includes/functions.php @@ -930,13 +930,11 @@ function getAssetId($asset=null){ // Handle getting asset information for an asset function getAssetInfo($asset=null){ global $mysqli, $dbase; - $type = gettype($tick); + $type = gettype($asset); $data = false; - if($type==='integer' || is_numeric($asset)){ - $asset_id = $asset; - } else { + // Only do lookup on strings, since all CP assets are strings + if($type=='string') $asset_id = getAssetId($asset); - } if($asset_id){ // Get data from assets table $sql = "SELECT From 47b88e6ae290a8f45c326065f10b2bf6ebe1832f Mon Sep 17 00:00:00 2001 From: J-Dog Date: Wed, 23 Aug 2023 11:57:49 -0700 Subject: [PATCH 2/6] update `getTokenSupply()` to use CAST in sql queries - fixes issues with amounts being returned in scientific E notation instead of integer/decimal --- indexer/includes/functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/indexer/includes/functions.php b/indexer/includes/functions.php index ff61331..42ddf0d 100644 --- a/indexer/includes/functions.php +++ b/indexer/includes/functions.php @@ -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){ @@ -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){ @@ -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); From 4f8c99db9119012f58a5b7fa053efdfe23e0b4b8 Mon Sep 17 00:00:00 2001 From: J-Dog Date: Wed, 23 Aug 2023 12:23:05 -0700 Subject: [PATCH 3/6] set MIN_TOKEN_SUPPLY to 0.000000000000000001 --- indexer/includes/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indexer/includes/config.php b/indexer/includes/config.php index 34de998..bd0d05e 100644 --- a/indexer/includes/config.php +++ b/indexer/includes/config.php @@ -22,7 +22,7 @@ define("RESERVED_TICKS",$reserved); // Min/Max MAX_SUPPLY -define('MIN_TOKEN_SUPPLY',0); +define('MIN_TOKEN_SUPPLY',0.000000000000000001); define('MAX_TOKEN_SUPPLY',1000000000000000000000); // Min/Max DECIMALS From 0c541ea4bdf70e68754ac6383a098115057c53ab Mon Sep 17 00:00:00 2001 From: J-Dog Date: Wed, 23 Aug 2023 12:24:44 -0700 Subject: [PATCH 4/6] Prevent LOCK_SUPPLY if no supply is issued - fixes issue #13 --- indexer/includes/actions/issue.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indexer/includes/actions/issue.php b/indexer/includes/actions/issue.php index d1a2395..ae160bf 100644 --- a/indexer/includes/actions/issue.php +++ b/indexer/includes/actions/issue.php @@ -153,6 +153,10 @@ function btnsIssue( $params=null, $data=null, $error=null){ if(!$error && isset($data->MAX_SUPPLY) && ($data->MAX_SUPPLY < MIN_TOKEN_SUPPLY || $data->MAX_SUPPLY > MAX_TOKEN_SUPPLY)) $error = 'invalid: MAX_SUPPLY (min/max)'; + // Verify SUPPLY is at least MIN_TOKEN_SUPPLY before allowing LOCK_SUPPLY + if(!$error && $data->LOCK_SUPPLY && (($btInfo && $btInfo->SUPPLY < MIN_TOKEN_SUPPLY) || (!$btInfo && $data->MINT_SUPPLY < MIN_TOKEN_SUPPLY))) + $error = 'invalid: LOCK_SUPPLY (no supply)'; + // Verify DECIMAL min/max if(!$error && isset($data->DECIMALS) && ($data->DECIMALS < MIN_TOKEN_DECIMALS || $data->DECIMALS > MAX_TOKEN_DECIMALS)) $error = 'invalid: DECIMALS (min/max)'; From 2b2da670eacde4d2b72ef6a26efdb9ef5abb7ae0 Mon Sep 17 00:00:00 2001 From: J-Dog Date: Wed, 23 Aug 2023 12:25:15 -0700 Subject: [PATCH 5/6] Prevent setting MAX_SUPPLY below current SUPPLY --- indexer/includes/actions/issue.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indexer/includes/actions/issue.php b/indexer/includes/actions/issue.php index ae160bf..c54e914 100644 --- a/indexer/includes/actions/issue.php +++ b/indexer/includes/actions/issue.php @@ -153,6 +153,10 @@ function btnsIssue( $params=null, $data=null, $error=null){ if(!$error && isset($data->MAX_SUPPLY) && ($data->MAX_SUPPLY < MIN_TOKEN_SUPPLY || $data->MAX_SUPPLY > MAX_TOKEN_SUPPLY)) $error = 'invalid: MAX_SUPPLY (min/max)'; + // Verify MAX_SUPPLY is not set below current SUPPLY + if(!$error && isset($data->MAX_SUPPLY) && $data->MAX_SUPPLY < $data->SUPPLY) + $error = 'invalid: MAX_SUPPLY < SUPPLY'; + // Verify SUPPLY is at least MIN_TOKEN_SUPPLY before allowing LOCK_SUPPLY if(!$error && $data->LOCK_SUPPLY && (($btInfo && $btInfo->SUPPLY < MIN_TOKEN_SUPPLY) || (!$btInfo && $data->MINT_SUPPLY < MIN_TOKEN_SUPPLY))) $error = 'invalid: LOCK_SUPPLY (no supply)'; From f5e400a2be1daeed19a7b4cd2bfd2ad19bf51025 Mon Sep 17 00:00:00 2001 From: J-Dog Date: Wed, 23 Aug 2023 12:48:13 -0700 Subject: [PATCH 6/6] v0.10.1 release --- docs/actions/ISSUE.md | 3 ++- indexer/CHANGELOG.md | 7 +++++++ indexer/includes/config.php | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/actions/ISSUE.md b/docs/actions/ISSUE.md index 8bbc661..fd239ac 100644 --- a/docs/actions/ISSUE.md +++ b/docs/actions/ISSUE.md @@ -103,7 +103,8 @@ This example issues a TEST token with a max supply of 100, and a maximum mint of - Additional `TICK` `ISSUE` transactions after first valid `TICK` `ISSUE`, will be considered invalid and ignored, unless broadcast from `token` owners address - `DECIMALS` can not be changed after `token` supply is issued and/or minted - `MAX_SUPPLY` max value is 1,000,000,000,000,000,000,000 (1 Sextillion) -- `LOCK_SUPPLY` can not be set to `1` and permanently locked unless `MAX_SUPPLY` is set to a non-zero number. +- `MAX_SUPPLY` can not be set below existing supply +- `LOCK_SUPPLY` can not be set to `1` and permanently locked until `MIN_TOKEN_SUPPLY` supply exists. ## Notes - `ISSUE` `TICK` with `MAX_SUPPLY` and `MINT_SUPPLY` set to any non `0` value, to mint supply until `MAX_SUPPLY` is reached (owner can mint beyond `MAX_MINT`) diff --git a/indexer/CHANGELOG.md b/indexer/CHANGELOG.md index ca09e2c..d3aaf6a 100644 --- a/indexer/CHANGELOG.md +++ b/indexer/CHANGELOG.md @@ -1,5 +1,12 @@ CHANGELOG --- +0.10.1 +- set MIN_TOKEN_SUPPLY to 0.000000000000000001 +- Prevent LOCK_SUPPLY if no supply is issued +- Prevent setting MAX_SUPPLY below current SUPPLY +- Updated getTokenSupply() to use CAST in sql queries +- Updated getAssetInfo() to only lookup assets using name + 0.10.0 - Initial Release - ISSUE support - LIST support diff --git a/indexer/includes/config.php b/indexer/includes/config.php index bd0d05e..7bcc77a 100644 --- a/indexer/includes/config.php +++ b/indexer/includes/config.php @@ -10,7 +10,7 @@ // BTNS Indexer Version define("VERSION_MAJOR", 0); define("VERSION_MINOR", 10); -define("VERSION_REVISION",0); +define("VERSION_REVISION",1); define("VERSION_STRING", VERSION_MAJOR . '.' . VERSION_MINOR . '.' . VERSION_REVISION); // TICK constants