Skip to content

Commit

Permalink
added SLP token type to SLPToken class + increased default (fallback)…
Browse files Browse the repository at this point in the history
… decimals to 9
  • Loading branch information
Ekliptor authored and Ekliptor committed Sep 19, 2020
1 parent d82e602 commit f6f6517
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/BlockchainApi/BchdProtoGatewayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ public function getSlpAddressDetails(string $address, string $tokenID): ?SlpToke
$curTokenID = bin2hex(base64_decode($output->slp_token->token_id));
if ($curTokenID !== $tokenID)
continue;
$slpAddress->balanceSat += (int)$output->slp_token->amount;
$slpAddress->balance += (int)$output->slp_token->amount;
}
$slpAddress->balance = CashP::fromSatoshis($slpAddress->balanceSat);
if ($slpAddress->decimals > 0)
$slpAddress->balance /= $slpAddress->decimals;
$slpAddress->transactions = $this->getAddressTransactions($address);

return $slpAddress;
Expand Down Expand Up @@ -217,6 +218,9 @@ protected function addTokenMetadata(SlpToken $token, array $bchdTokenMetadata):
$id = bin2hex(base64_decode($meta->token_id));
if ($id !== $token->id)
continue;

// Type 1 and NFT1 Group types same, its just the versionType field is 0x01 and 0x81
// NFT1 Child different
$type = $meta->token_type;
$typeKey = "type$type";
$typeInfo = $meta->$typeKey;
Expand All @@ -225,7 +229,15 @@ protected function addTokenMetadata(SlpToken $token, array $bchdTokenMetadata):
if (isset($typeInfo->decimals)) // not present with all tokens
$token->decimals = $typeInfo->decimals;
else
$token->decimals = 8;
$token->decimals = 9;

// add the token type
if (isset($meta->type1))
$token->type = 'type1';
else if (isset($meta->nft1_group))
$token->type = 'nft1_group';
else if (isset($meta->nft1_child))
$token->type = 'nft1_child';
return;
}
$this->logError("Unable to find desired token metadata", $bchdTokenMetadata);
Expand Down
2 changes: 2 additions & 0 deletions src/BlockchainApi/Structs/SlpToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class SlpToken {
public $name = '';
/** @var string */
public $symbol = '';
/** @var string: type1|nft1_group|nft1_child */
public $type = 'type1';
/** @var string */
public $documentHash = '';
/** @var string */
Expand Down

0 comments on commit f6f6517

Please sign in to comment.