Skip to content

Commit

Permalink
Merge pull request #111 from DennisPitallano/feature/#77
Browse files Browse the repository at this point in the history
Add Get BNB Smart Chain Daily Total Gas Used
  • Loading branch information
DennisPitallano authored Mar 4, 2022
2 parents 15cb76b + 23f7756 commit d526fbd
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BscScan.NetCore/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ internal static class GasTrackerModuleAction
{
public const string GAS_ORACLE = "gasoracle";
public const string DAILY_AVG_GAS_LIMIT = "dailyavggaslimit";
public const string DAILY_GAS_USED = "dailygasused";
}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions src/BscScan.NetCore/Contracts/IBscScanGasTrackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public interface IBscScanGasTrackerService
/// <param name="request">DailyAverageGasLimitRequest</param>
/// <returns>Returns the historical daily average gas limit of the BNB Smart Chain network.</returns>
Task<DailyAverageGasLimit?> GetDailyAverageGasLimit(DailyAverageGasLimitRequest request);

/// <summary>
/// Get BNB Smart Chain Daily Total Gas Used 🅰🅿🅸 🅿🆁🅾
/// </summary>
/// <param name="request">BnbSmartChainDailyTotalGasUsed</param>
/// <returns>Returns the total amount of gas used daily for transactions on the BNB Smart Chain network.</returns>
Task<BnbSmartChainDailyTotalGasUsed?> GetBnbSmartChainDailyTotalGasUsed(BnbSmartChainDailyTotalGasUsedRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Request.GasTracker;

/// <summary>
/// BnbSmartChainDailyTotalGasUsed
/// </summary>
public class BnbSmartChainDailyTotalGasUsedRequest
{
/// <summary>
/// the starting date in yyyy-MM-dd format, eg. 2021-08-01
/// </summary>
[JsonIgnore]
public DateOnly StartDate { get; set; }

/// <summary>
/// the ending date in yyyy-MM-dd format, eg. 2021-08-28
/// </summary>
[JsonIgnore]
public DateOnly EndDate { get; set; }

/// <summary>
/// the sorting preference, use asc to sort by ascending and desc to sort by descending (default is asc)
/// </summary>
[JsonIgnore]
public Sort Sort { get; set; } = Sort.Asc;

/// <summary>
/// the starting date in yyyy-MM-dd format, eg. 2021-08-01
/// </summary>
[JsonPropertyName("startdate")]
public string? StartDateParam => StartDate.ToString("yyyy-MM-dd");

/// <summary>
/// the ending date in yyyy-MM-dd format, eg. 2021-08-28
/// </summary>
[JsonPropertyName("enddate")]
public string? EndDateParam => EndDate.ToString("yyyy-MM-dd");

/// <summary>
/// the sorting preference, use asc to sort by ascending and desc to sort by descending (default is asc)
/// </summary>

[JsonPropertyName("sort")]
public string SortParam => Sort.ToString().ToLower();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.GasTracker;

/// <summary>
/// BnbSmartChainDailyTotalGasUsed
/// </summary>
public class BnbSmartChainDailyTotalGasUsed : BaseResponse
{
/// <summary>
/// List of BnbSmartChainDailyTotalGasUsedData
/// </summary>
[JsonPropertyName("result")]
public IEnumerable<BnbSmartChainDailyTotalGasUsedData>? Result { get; set; }
}

/// <summary>
/// BnbSmartChainDailyTotalGasUsedData
/// </summary>
public class BnbSmartChainDailyTotalGasUsedData
{
/// <summary>
/// UTCDate
/// </summary>
[JsonPropertyName("UTCDate")]
public string? UtcDate { get; set; }

/// <summary>
/// unixTimeStamp
/// </summary>
[JsonPropertyName("unixTimeStamp")]
public string? UnixTimeStamp { get; set; }

/// <summary>
/// gasLimit
/// </summary>
[JsonPropertyName("gasUsed")]
public string? GasUsed { get; set; }
}
13 changes: 13 additions & 0 deletions src/BscScan.NetCore/Services/BscScanGasTrackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ public BscScanGasTrackerService(HttpClient bscScanHttpClient, BscScanConfigurati
var result = await JsonSerializer.DeserializeAsync<DailyAverageGasLimit>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<BnbSmartChainDailyTotalGasUsed?> GetBnbSmartChainDailyTotalGasUsed(BnbSmartChainDailyTotalGasUsedRequest request)
{
var queryParameters = $"{_bscScanStatsModule}{request.ToRequestParameters(GasTrackerModuleAction.DAILY_GAS_USED)}";
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<BnbSmartChainDailyTotalGasUsed>(responseStream);
return result;
}
}

0 comments on commit d526fbd

Please sign in to comment.