Skip to content

Commit

Permalink
Merge pull request #93 from DennisPitallano/feature/#58
Browse files Browse the repository at this point in the history
Add eth_sendRawTransaction
  • Loading branch information
DennisPitallano authored Feb 26, 2022
2 parents 3027bae + 29e4318 commit a20a478
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 4 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 @@ -69,6 +69,7 @@ internal static class ProxyModuleAction
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";
public const string ETH_SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
}


Expand All @@ -86,6 +87,7 @@ internal static class BscQueryParam
public const string Tag = "tag={value}";
public const string Boolean = "boolean={value}";
public const string Index = "index={value}";
public const string Hex = "hex={value}";
}

internal static class MimeTypes
Expand Down
7 changes: 7 additions & 0 deletions src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ public interface IBscScanGethProxyService
/// <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);

/// <summary>
/// eth_sendRawTransaction
/// </summary>
/// <param name="hex">the string representing the signed raw transaction data to broadcast.</param>
/// <returns>Submits a pre-signed transaction for broadcast to the BNB Smart Chain network.</returns>
Task<SendRawTransaction?> EthSendRawTransaction(string hex);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
namespace BscScan.NetCore.Models.Response.Proxy
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
/// BlockTransactionCountByNumber
/// </summary>
public class BlockTransactionCountByNumber: EthBlockNumber
public class BlockTransactionCountByNumber
{
/// <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; }
}
}
53 changes: 53 additions & 0 deletions src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
/// SendRawTransaction
/// </summary>
public class SendRawTransaction
{
/// <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; }


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

/// <summary>
/// Error
/// </summary>
public class Error
{
/// <summary>
/// Code
/// </summary>
[JsonPropertyName("code")]
public int Code { get; set; }

/// <summary>
/// Message
/// </summary>
[JsonPropertyName("message")]
public string? Message { get; set; }
}
}
23 changes: 21 additions & 2 deletions src/BscScan.NetCore/Models/Response/Proxy/TransactionCount.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
namespace BscScan.NetCore.Models.Response.Proxy
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
/// TransactionCount
/// </summary>
public class TransactionCount : EthBlockNumber
public class TransactionCount
{
/// <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; }
}
}
14 changes: 14 additions & 0 deletions src/BscScan.NetCore/Services/BscScanGethProxyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,19 @@ public BscScanGethProxyService(HttpClient bscScanHttpClient, BscScanConfiguratio
var result = await JsonSerializer.DeserializeAsync<TransactionCount>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<SendRawTransaction?> EthSendRawTransaction(string hex)
{
var queryParameters = $"{_bscScanModule}".AddAction(ProxyModuleAction.ETH_SEND_RAW_TRANSACTION)
.AddQuery(BscQueryParam.Hex.AppendValue(hex));
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<SendRawTransaction>(responseStream);
return result;
}
}
}

0 comments on commit a20a478

Please sign in to comment.