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 eth_getTransactionCount #92

Merged
merged 1 commit into from
Feb 26, 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 @@ -68,6 +68,7 @@ internal static class ProxyModuleAction
public const string ETH_GET_BLOCk_TRANSACTION_COUNT_BY_NUMBER = "eth_getBlockTransactionCountByNumber";
public const string ETH_GET_TRANSACTION_BY_HASH = "eth_getTransactionByHash";
public const string ETH_GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX = "eth_getTransactionByBlockNumberAndIndex";
public const string ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
}


Expand Down
11 changes: 10 additions & 1 deletion src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BscScan.NetCore.Models.Response.Proxy;
using BscScan.NetCore.Models;
using BscScan.NetCore.Models.Response.Proxy;

namespace BscScan.NetCore.Contracts
{
Expand Down Expand Up @@ -44,5 +45,13 @@ public interface IBscScanGethProxyService
/// <param name="index">the position of the uncle's index in the block, in hex eg. 0x1</param>
/// <returns></returns>
Task<TransactionByBlockNumberAndIndex?> EthGetTransactionByBlockNumberAndIndex(string tag, string index);

/// <summary>
///
/// </summary>
/// <param name="address">the string representing the address to get transaction count</param>
/// <param name="tag">the string pre-defined block parameter, either earliest, pending or latest</param>
/// <returns>Returns the number of transactions performed by an address.</returns>
Task<TransactionCount?> EthGetTransactionCount(string address, Tag tag = Tag.Latest);
}
}
9 changes: 9 additions & 0 deletions src/BscScan.NetCore/Models/Response/Proxy/TransactionCount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
/// TransactionCount
/// </summary>
public class TransactionCount : EthBlockNumber
{
}
}
15 changes: 15 additions & 0 deletions src/BscScan.NetCore/Services/BscScanGethProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BscScan.NetCore.Constants;
using BscScan.NetCore.Contracts;
using BscScan.NetCore.Extensions;
using BscScan.NetCore.Models;
using BscScan.NetCore.Models.Response.Proxy;

namespace BscScan.NetCore.Services
Expand Down Expand Up @@ -85,5 +86,19 @@ public BscScanGethProxyService(HttpClient bscScanHttpClient, BscScanConfiguratio
var result = await JsonSerializer.DeserializeAsync<TransactionByBlockNumberAndIndex>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<TransactionCount?> EthGetTransactionCount(string address, Tag tag)
{
var queryParameters = $"{_bscScanModule}".AddAction(ProxyModuleAction.ETH_GET_TRANSACTION_COUNT)
.AddQuery(BscQueryParam.Tag.AppendValue(tag.ToString().ToLower())).AddQuery(BscQueryParam.Address.AppendValue(address));
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<TransactionCount>(responseStream);
return result;
}
}
}