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_sendRawTransaction #93

Merged
merged 4 commits 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
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;
}
}
}