Skip to content

Commit

Permalink
Merge branch 'feature/#62' into Manual-Test
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisPitallano committed Feb 28, 2022
2 parents 62edd41 + fbcc71f commit 48f5efc
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/BscScan.NetCore/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ internal static class ProxyModuleAction
public const string ETH_GET_TRANSACTION_RECEIPT = "eth_getTransactionReceipt";
public const string ETH_CALL = "eth_call";
public const string ETH_GET_CODE = "eth_getCode";
public const string ETH_GET_STORAGE_AT = "eth_getStorageAt";
}


Expand All @@ -93,6 +94,7 @@ internal static class BscQueryParam
public const string Hex = "hex={value}";
public const string To = "to={value}";
public const string Data = "data={value}";
public const string Position = "position={value}";
}

internal static class MimeTypes
Expand Down
12 changes: 11 additions & 1 deletion src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface IBscScanGethProxyService
/// eth_getBlockByNumber
/// </summary>
/// <param name="tag">the block number, in hex eg. 0xC36B3C</param>
/// when true, returns full transaction objects and their information, when false only returns a list of transactions.</param>
/// when true, returns full transaction objects and their information, when false only returns a list of transactions.
/// <returns>Returns information about a block by block number.</returns>
Task<BlockByNumber?> EthGetBlockByNumber(string tag);

Expand Down Expand Up @@ -84,5 +84,15 @@ public interface IBscScanGethProxyService
/// <param name="tag">the string pre-defined block parameter, either earliest, pending or latest</param>
/// <returns>Returns code at a given address.</returns>
Task<EthCode?> EthGetCode(string address, Tag tag = Tag.Latest);

/// <summary>
/// eth_getStorageAt
/// Note: This endpoint is still experimental and may have potential issues
/// </summary>
/// <param name="address">the string representing the address to get code</param>
/// <param name="position">the hex code of the position in storage, eg 0x0</param>
/// <param name="tag">the string pre-defined block parameter, either earliest, pending or latest</param>
/// <returns>Returns the value from a storage position at a given address.</returns>
Task<EthStorageAt?> EthGetStorageAt(string address,string position, Tag tag = Tag.Latest);
}
}
2 changes: 1 addition & 1 deletion src/BscScan.NetCore/Models/Response/Proxy/EthCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
///
/// EthCode
/// </summary>
public class EthCode
{
Expand Down
28 changes: 28 additions & 0 deletions src/BscScan.NetCore/Models/Response/Proxy/EthStorageAt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
/// EthStorageAt
/// </summary>
public class EthStorageAt
{
/// <summary>
/// JsonRpc
/// </summary>
[JsonPropertyName("jsonrpc")]
public string? JsonRpc { get; set; }

/// <summary>
/// Id
/// </summary>
[JsonPropertyName("id")]
public int Id { get; set; }

/// <summary>
/// result
/// </summary>
[JsonPropertyName("result")]
public string? Result { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/BscScan.NetCore/Services/BscScanGethProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,21 @@ public BscScanGethProxyService(HttpClient bscScanHttpClient, BscScanConfiguratio
var result = await JsonSerializer.DeserializeAsync<EthCode>(responseStream);
return result;
}

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

0 comments on commit 48f5efc

Please sign in to comment.