Skip to content

Commit

Permalink
Merge pull request #16 from jdogresorg/btns420-indexer
Browse files Browse the repository at this point in the history
v0.10.1 release
  • Loading branch information
jdogresorg authored Aug 23, 2023
2 parents d72cb49 + f5e400a commit e7db8f4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion docs/actions/ISSUE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
7 changes: 7 additions & 0 deletions indexer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions indexer/includes/actions/issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ 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)';

// Verify DECIMAL min/max
if(!$error && isset($data->DECIMALS) && ($data->DECIMALS < MIN_TOKEN_DECIMALS || $data->DECIMALS > MAX_TOKEN_DECIMALS))
$error = 'invalid: DECIMALS (min/max)';
Expand Down
4 changes: 2 additions & 2 deletions indexer/includes/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions indexer/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1228,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 @@ -1240,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 @@ -1250,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 e7db8f4

Please sign in to comment.