Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Get BEP-20 Token CirculatingSupply by ContractAddress #101

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BscScan.NetCore/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ internal static class ProxyModuleAction
internal static class TokenModuleAction
{
public const string TOKEN_SUPPLY = "tokensupply";
public const string TOKEN_C_SUPPLY = "tokenCsupply";
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/BscScan.NetCore/Contracts/IBscScanTokensService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ public interface IBscScanTokensService
/// <param name="contractAddress">the contract address of the BEP-20 token</param>
/// <returns>Returns the total supply of a BEP-20 token.</returns>
Task<TokenTotalSupply?> GetBep20TokenTotalSupplyByContractAddress(string contractAddress);

/// <summary>
/// Get BEP-20 Token CirculatingSupply by ContractAddress
/// </summary>
/// <param name="contractAddress">the contract address of the BEP-20 token</param>
/// <returns>Returns the current circulating supply of a BEP-20 token. </returns>
Task<TokenCirculatingSupply?> GetBep20TokenCirculatingSupplyByContractAddress(string contractAddress);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Tokens
{
/// <summary>
/// TokenCirculatingSupply
/// </summary>
public class TokenCirculatingSupply : BaseResponse
{
/// <summary>
/// result
/// </summary>
[JsonPropertyName("result")]
public string? Result { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/BscScan.NetCore/Services/BscScanTokensService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,19 @@ public BscScanTokensService(HttpClient bscScanHttpClient, BscScanConfiguration b
var result = await JsonSerializer.DeserializeAsync<TokenTotalSupply>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<TokenCirculatingSupply?> GetBep20TokenCirculatingSupplyByContractAddress(string contractAddress)
{
var queryParameters = $"{_bscScanModuleStat}".AddAction(TokenModuleAction.TOKEN_C_SUPPLY)
.AddQuery(BscQueryParam.ContractAddress.AppendValue(contractAddress));
using var response = await BscScanHttpClient.GetAsync($"{queryParameters}")
.ConfigureAwait(false);

response.EnsureSuccessStatusCode();
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var result = await JsonSerializer.DeserializeAsync<TokenCirculatingSupply>(responseStream);
return result;
}
}
}