Skip to content

Commit

Permalink
Merge pull request #44 from DennisPitallano/feature/#33
Browse files Browse the repository at this point in the history
Add Get Estimated Block Countdown Time by BlockNo
  • Loading branch information
DennisPitallano committed Feb 21, 2022
2 parents 89f130a + b9c7a6e commit 13f2e4c
Show file tree
Hide file tree
Showing 4 changed files with 70 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 @@ -49,6 +49,7 @@ internal static class TransactionsModuleAction
internal static class BlocksModuleAction
{
public const string GET_BLOCK_REWARD = "getblockreward";
public const string GET_BLOCK_COUNT_DOWN= "getblockcountdown";
}


Expand Down
7 changes: 7 additions & 0 deletions src/BscScan.NetCore/Contracts/IBscScanBlocksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ public interface IBscScanBlocksService
/// <param name="blockNo">the integer block number to check block rewards for eg. 12697906</param>
/// <returns>Returns the block reward awarded for validating a certain block.</returns>
Task<BlockRewards?> GetBlockRewardsByBlockNo(string blockNo);

/// <summary>
/// Get Estimated Block Countdown Time by BlockNo
/// </summary>
/// <param name="blockNo">the integer block number to estimate time remaining to be validated eg. 12697906</param>
/// <returns>Returns the estimated time remaining, in seconds, until a certain block is validated.</returns>
Task<EstimatedBlockCountdownTime?> GetEstimatedBlockCountdownTimeByBlockNo(string blockNo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Blocks
{
/// <summary>
/// EstimatedBlockCountdownTime Model
/// </summary>
public class EstimatedBlockCountdownTime : BaseResponse
{
/// <summary>
/// EstimatedBlockCountdownTimeData
/// </summary>
[JsonPropertyName("result")]
public EstimatedBlockCountdownTimeData? Result { get; set; }
}

/// <summary>
/// EstimatedBlockCountdownTimeData Model
/// </summary>
public class EstimatedBlockCountdownTimeData
{

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

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

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

/// <summary>
/// EstimateTimeInSec
/// </summary>
[JsonPropertyName("EstimateTimeInSec")]
public string? EstimateTimeInSec { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/BscScan.NetCore/Services/BscScanBlocksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,20 @@ public BscScanBlocksService(HttpClient bscScanHttpClient, BscScanConfiguration b
var result = await JsonSerializer.DeserializeAsync<BlockRewards>(responseStream);
return result;
}


/// <inheritdoc />
public async Task<EstimatedBlockCountdownTime?> GetEstimatedBlockCountdownTimeByBlockNo(string blockNo)
{
var queryParameters = $"{_bscScanModule}".AddAction(BlocksModuleAction.GET_BLOCK_COUNT_DOWN)
.AddQuery(BscQueryParam.BlockNo.AppendValue(blockNo));
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<EstimatedBlockCountdownTime>(responseStream);
return result;
}
}
}

0 comments on commit 13f2e4c

Please sign in to comment.