Skip to content

Commit

Permalink
Merge branch 'feature/#68' into Manual-Test
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisPitallano committed Mar 3, 2022
2 parents 39dbeea + 893af30 commit 311bd61
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/BscScan.NetCore/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal static class TokenModuleAction
public const string TOKEN_SUPPLY = "tokensupply";
public const string TOKEN_C_SUPPLY = "tokenCsupply";
public const string TOKEN_BALANCE = "tokenbalance";
public const string TOKEN_HOLDER_LIST = "tokenholderlist";
}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion src/BscScan.NetCore/Contracts/IBscScanTokensService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BscScan.NetCore.Models.Response.Tokens;
using BscScan.NetCore.Models.Request.Tokens;
using BscScan.NetCore.Models.Response.Tokens;

namespace BscScan.NetCore.Contracts
{
Expand Down Expand Up @@ -28,5 +29,12 @@ public interface IBscScanTokensService
/// <param name="address">the string representing the address to check for token balance</param>
/// <returns>Returns the current balance of a BEP-20 token of an address.</returns>
Task<TokenAccountBalance?> GetBep20TokenAccountBalanceByContractAddress(string contractAddress, string address);

/// <summary>
/// Get Token Holder List by Contract Address 🅰🅿🅸 🅿🆁🅾
/// </summary>
/// <param name="request">TokenHolderListRequest</param>
/// <returns></returns>
Task<TokenHolderList?> GetTokenHolderListByContractAddress(TokenHolderListRequest request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Request.Tokens
{
/// <summary>
/// TokenHolderListRequest
/// </summary>
public class TokenHolderListRequest
{
/// <summary>
/// the contract address of the BEP-20 token
/// </summary>
[JsonPropertyName("contractaddress")]
public string? ContractAddress { get; set; }
/// <summary>
/// the integer page number, if pagination is enabled (default is 1)
/// </summary>
[JsonPropertyName("page")]
public int Page { get; set; } = 1;

/// <summary>
/// the number of transactions displayed per page (default is 10)
/// </summary>
[JsonPropertyName("offset")]
public int OffSet { get; set; } = 10;
}
}
35 changes: 35 additions & 0 deletions src/BscScan.NetCore/Models/Response/Tokens/TokenHolderList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Tokens
{
/// <summary>
/// TokenHolderList
/// </summary>
public class TokenHolderList : BaseResponse
{
/// <summary>
/// List of TokenHolderListItem
/// </summary>
[JsonPropertyName("result")]
public IEnumerable<TokenHolderListItem>? Result { get; set; }
}

/// <summary>
/// TokenHolderListItem
/// </summary>
public class TokenHolderListItem
{
/// <summary>
/// TokenHolderAddress
/// </summary>
[JsonPropertyName("TokenHolderAddress")]
public string? TokenHolderAddress { get; set; }

/// <summary>
/// TokenHolderQuantity
/// </summary>
[JsonPropertyName("TokenHolderQuantity")]
public string? TokenHolderQuantity { 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 @@ -4,6 +4,7 @@
using BscScan.NetCore.Contracts;
using BscScan.NetCore.Extensions;
using BscScan.NetCore.Models;
using BscScan.NetCore.Models.Request.Tokens;
using BscScan.NetCore.Models.Response.Tokens;

namespace BscScan.NetCore.Services
Expand Down Expand Up @@ -67,5 +68,18 @@ public BscScanTokensService(HttpClient bscScanHttpClient, BscScanConfiguration b
var result = await JsonSerializer.DeserializeAsync<TokenAccountBalance>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<TokenHolderList?> GetTokenHolderListByContractAddress(TokenHolderListRequest request)
{
var queryParameters = $"{_bscScanModuleToken}{request.ToRequestParameters(TokenModuleAction.TOKEN_HOLDER_LIST)}";
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<TokenHolderList>(responseStream);
return result;
}
}
}

0 comments on commit 311bd61

Please sign in to comment.