Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add token.totalSupply to token balances and token transfers
Browse files Browse the repository at this point in the history
MS committed Sep 11, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3510d2c commit 1c1b8f7
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tzkt.Api/Models/Tokens/TokenInfo.cs
Original file line number Diff line number Diff line change
@@ -24,6 +24,11 @@ public class TokenInfo
/// </summary>
public string Standard { get; set; }

/// <summary>
/// Total number of existing tokens (raw value, not divided by `decimals`). In historical token balances this field is omitted.
/// </summary>
public string TotalSupply { get; set; }

/// <summary>
/// Token metadata.
/// **[sortable]**
18 changes: 18 additions & 0 deletions Tzkt.Api/Repositories/TokensRepository.cs
Original file line number Diff line number Diff line change
@@ -268,6 +268,7 @@ async Task<IEnumerable<dynamic>> QueryTokenBalancesAsync(TokenBalanceFilter filt
tb.""ContractId"" as ""tContractId"",
t.""TokenId"" as ""tTokenId"",
t.""Tags"" as ""tTags"",
t.""TotalSupply"" as ""tTotalSupply"",
t.""Metadata"" as ""tMetadata""";
if (fields != null)
{
@@ -292,6 +293,7 @@ async Task<IEnumerable<dynamic>> QueryTokenBalancesAsync(TokenBalanceFilter filt
columns.Add(@"tb.""ContractId"" as ""tContractId""");
columns.Add(@"t.""TokenId"" as ""tTokenId""");
columns.Add(@"t.""Tags"" as ""tTags""");
columns.Add(@"t.""TotalSupply"" as ""tTotalSupply""");
columns.Add(@"t.""Metadata"" as ""tMetadata""");
}
else
@@ -303,6 +305,7 @@ async Task<IEnumerable<dynamic>> QueryTokenBalancesAsync(TokenBalanceFilter filt
case "contract": columns.Add(@"tb.""ContractId"" as ""tContractId"""); break;
case "tokenId": columns.Add(@"t.""TokenId"" as ""tTokenId"""); break;
case "standard": columns.Add(@"t.""Tags"" as ""tTags"""); break;
case "totalSupply": columns.Add(@"t.""TotalSupply"" as ""tTotalSupply"""); break;
case "metadata":
if (subField.Path == null)
{
@@ -409,6 +412,7 @@ public async Task<IEnumerable<TokenBalance>> GetTokenBalances(TokenBalanceFilter
Contract = Accounts.GetAlias(row.tContractId),
TokenId = row.tTokenId,
Standard = TokenStandards.ToString(row.tTags),
TotalSupply = row.tTotalSupply,
Metadata = (RawJson)row.tMetadata
}
});
@@ -474,6 +478,7 @@ public async Task<object[][]> GetTokenBalances(TokenBalanceFilter filter, Pagina
Contract = Accounts.GetAlias(row.tContractId),
TokenId = row.tTokenId,
Standard = TokenStandards.ToString(row.tTags),
TotalSupply = row.tTotalSupply,
Metadata = (RawJson)row.tMetadata
};
break;
@@ -501,6 +506,10 @@ public async Task<object[][]> GetTokenBalances(TokenBalanceFilter filter, Pagina
foreach (var row in rows)
result[j++][i] = TokenStandards.ToString(row.tTags);
break;
case "token.totalSupply":
foreach (var row in rows)
result[j++][i] = row.tTotalSupply;
break;
case "token.metadata":
foreach (var row in rows)
result[j++][i] = (RawJson)row.tMetadata;
@@ -533,6 +542,7 @@ async Task<IEnumerable<dynamic>> QueryTokenTransfersAsync(TokenTransferFilter fi
tr.""ContractId"" as ""tContractId"",
t.""TokenId"" as ""tTokenId"",
t.""Tags"" as ""tTags"",
t.""TotalSupply"" as ""tTotalSupply"",
t.""Metadata"" as ""tMetadata""";
if (fields != null)
{
@@ -558,6 +568,7 @@ async Task<IEnumerable<dynamic>> QueryTokenTransfersAsync(TokenTransferFilter fi
columns.Add(@"tr.""ContractId"" as ""tContractId""");
columns.Add(@"t.""TokenId"" as ""tTokenId""");
columns.Add(@"t.""Tags"" as ""tTags""");
columns.Add(@"t.""TotalSupply"" as ""tTotalSupply""");
columns.Add(@"t.""Metadata"" as ""tMetadata""");
}
else
@@ -569,6 +580,7 @@ async Task<IEnumerable<dynamic>> QueryTokenTransfersAsync(TokenTransferFilter fi
case "contract": columns.Add(@"tr.""ContractId"" as ""tContractId"""); break;
case "tokenId": columns.Add(@"t.""TokenId"" as ""tTokenId"""); break;
case "standard": columns.Add(@"t.""Tags"" as ""tTags"""); break;
case "totalSupply": columns.Add(@"t.""TotalSupply"" as ""tTotalSupply"""); break;
case "metadata":
if (subField.Path == null)
{
@@ -680,6 +692,7 @@ public async Task<IEnumerable<TokenTransfer>> GetTokenTransfers(TokenTransferFil
Contract = Accounts.GetAlias(row.tContractId),
TokenId = row.tTokenId,
Standard = TokenStandards.ToString(row.tTags),
TotalSupply = row.tTotalSupply,
Metadata = (RawJson)row.tMetadata
}
});
@@ -757,6 +770,7 @@ public async Task<object[][]> GetTokenTransfers(TokenTransferFilter filter, Pagi
Contract = Accounts.GetAlias(row.tContractId),
TokenId = row.tTokenId,
Standard = TokenStandards.ToString(row.tTags),
TotalSupply = row.tTotalSupply,
Metadata = (RawJson)row.tMetadata
};
break;
@@ -784,6 +798,10 @@ public async Task<object[][]> GetTokenTransfers(TokenTransferFilter filter, Pagi
foreach (var row in rows)
result[j++][i] = TokenStandards.ToString(row.tTags);
break;
case "token.totalSupply":
foreach (var row in rows)
result[j++][i] = row.tTotalSupply;
break;
case "token.metadata":
foreach (var row in rows)
result[j++][i] = (RawJson)row.tMetadata;

0 comments on commit 1c1b8f7

Please sign in to comment.