From 1d63b69af3cf64bab158834d118e657e143015c7 Mon Sep 17 00:00:00 2001 From: DennisPitallano Date: Sun, 27 Feb 2022 03:03:54 +0800 Subject: [PATCH 1/4] Add eth_sendRawTransaction Submits a pre-signed transaction for broadcast to the BNB Smart Chain network. --- src/BscScan.NetCore/Constants/Constants.cs | 2 ++ .../Contracts/IBscScanGethProxyService.cs | 7 +++++ .../Proxy/BlockTransactionCountByNumber.cs | 23 +++++++++++++-- .../Response/Proxy/SendRawTransaction.cs | 28 +++++++++++++++++++ .../Models/Response/Proxy/TransactionCount.cs | 23 +++++++++++++-- .../Services/BscScanGethProxyService.cs | 14 ++++++++++ 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs diff --git a/src/BscScan.NetCore/Constants/Constants.cs b/src/BscScan.NetCore/Constants/Constants.cs index d5a5d09..c05e076 100644 --- a/src/BscScan.NetCore/Constants/Constants.cs +++ b/src/BscScan.NetCore/Constants/Constants.cs @@ -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"; } @@ -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 diff --git a/src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs b/src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs index a25c332..4acc2f3 100644 --- a/src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs +++ b/src/BscScan.NetCore/Contracts/IBscScanGethProxyService.cs @@ -53,5 +53,12 @@ public interface IBscScanGethProxyService /// the string pre-defined block parameter, either earliest, pending or latest /// Returns the number of transactions performed by an address. Task EthGetTransactionCount(string address, Tag tag = Tag.Latest); + + /// + /// eth_sendRawTransaction + /// + /// the string representing the signed raw transaction data to broadcast. + /// Submits a pre-signed transaction for broadcast to the BNB Smart Chain network. + Task EthSendRawTransaction(string hex); } } diff --git a/src/BscScan.NetCore/Models/Response/Proxy/BlockTransactionCountByNumber.cs b/src/BscScan.NetCore/Models/Response/Proxy/BlockTransactionCountByNumber.cs index 512ebb7..4c08f99 100644 --- a/src/BscScan.NetCore/Models/Response/Proxy/BlockTransactionCountByNumber.cs +++ b/src/BscScan.NetCore/Models/Response/Proxy/BlockTransactionCountByNumber.cs @@ -1,9 +1,28 @@ -namespace BscScan.NetCore.Models.Response.Proxy +using System.Text.Json.Serialization; + +namespace BscScan.NetCore.Models.Response.Proxy { /// /// BlockTransactionCountByNumber /// - public class BlockTransactionCountByNumber: EthBlockNumber + public class BlockTransactionCountByNumber { + /// + /// JsonRpc + /// + [JsonPropertyName("jsonrpc")] + public string? JsonRpc { get; set; } + + /// + /// Id + /// + [JsonPropertyName("id")] + public int Id { get; set; } + + /// + /// result + /// + [JsonPropertyName("result")] + public string? Result { get; set; } } } diff --git a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs new file mode 100644 index 0000000..a797661 --- /dev/null +++ b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; + +namespace BscScan.NetCore.Models.Response.Proxy +{ + /// + /// SendRawTransaction + /// + public class SendRawTransaction + { + /// + /// JsonRpc + /// + [JsonPropertyName("jsonrpc")] + public string? JsonRpc { get; set; } + + /// + /// Id + /// + [JsonPropertyName("id")] + public int Id { get; set; } + + /// + /// result + /// + [JsonPropertyName("result")] + public string? Result { get; set; } + } +} diff --git a/src/BscScan.NetCore/Models/Response/Proxy/TransactionCount.cs b/src/BscScan.NetCore/Models/Response/Proxy/TransactionCount.cs index 9e3f7f5..da1c402 100644 --- a/src/BscScan.NetCore/Models/Response/Proxy/TransactionCount.cs +++ b/src/BscScan.NetCore/Models/Response/Proxy/TransactionCount.cs @@ -1,9 +1,28 @@ -namespace BscScan.NetCore.Models.Response.Proxy +using System.Text.Json.Serialization; + +namespace BscScan.NetCore.Models.Response.Proxy { /// /// TransactionCount /// - public class TransactionCount : EthBlockNumber + public class TransactionCount { + /// + /// JsonRpc + /// + [JsonPropertyName("jsonrpc")] + public string? JsonRpc { get; set; } + + /// + /// Id + /// + [JsonPropertyName("id")] + public int Id { get; set; } + + /// + /// result + /// + [JsonPropertyName("result")] + public string? Result { get; set; } } } diff --git a/src/BscScan.NetCore/Services/BscScanGethProxyService.cs b/src/BscScan.NetCore/Services/BscScanGethProxyService.cs index 167b705..7af8aef 100644 --- a/src/BscScan.NetCore/Services/BscScanGethProxyService.cs +++ b/src/BscScan.NetCore/Services/BscScanGethProxyService.cs @@ -100,5 +100,19 @@ public BscScanGethProxyService(HttpClient bscScanHttpClient, BscScanConfiguratio var result = await JsonSerializer.DeserializeAsync(responseStream); return result; } + + /// + public async Task 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(responseStream); + return result; + } } } From e91165c36e1fad2a1ad51713a83df5f9ea97360d Mon Sep 17 00:00:00 2001 From: DennisPitallano Date: Sun, 27 Feb 2022 03:24:29 +0800 Subject: [PATCH 2/4] Update model --- .../Response/Proxy/SendRawTransaction.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs index a797661..9c5e6ac 100644 --- a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs +++ b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs @@ -24,5 +24,28 @@ public class SendRawTransaction /// [JsonPropertyName("result")] public string? Result { get; set; } + + + /// + /// Error + /// + [JsonPropertyName("error")] + public Error? Error { get; set; } + } + + /// + /// Error + /// + public class Error + { + /// + /// Code + /// + public int Code { get; set; } + + /// + /// Message + /// + public string? Message { get; set; } } } From 07667966ebdbdc8b5d90cdb9dd1ba87340568268 Mon Sep 17 00:00:00 2001 From: DennisPitallano Date: Sun, 27 Feb 2022 03:27:35 +0800 Subject: [PATCH 3/4] add jsonpropertyname --- src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs index 9c5e6ac..28771f1 100644 --- a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs +++ b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs @@ -41,11 +41,13 @@ public class Error /// /// Code /// + [JsonPropertyName("Code")] public int Code { get; set; } /// /// Message /// + [JsonPropertyName("message")] public string? Message { get; set; } } } From 29e4318e9fbf2cd504670b51c41dfab060557dcf Mon Sep 17 00:00:00 2001 From: DennisPitallano Date: Sun, 27 Feb 2022 03:29:48 +0800 Subject: [PATCH 4/4] update jsonproperty --- src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs index 28771f1..26b0c7d 100644 --- a/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs +++ b/src/BscScan.NetCore/Models/Response/Proxy/SendRawTransaction.cs @@ -41,7 +41,7 @@ public class Error /// /// Code /// - [JsonPropertyName("Code")] + [JsonPropertyName("code")] public int Code { get; set; } ///