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_getTransactionReceipt #94

Merged
merged 2 commits into from
Feb 28, 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
1 change: 1 addition & 0 deletions src/BscScan.NetCore/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ internal static class ProxyModuleAction
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";
public const string ETH_GET_TRANSACTION_RECEIPT = "eth_getTransactionReceipt";
}


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 @@ -60,5 +60,12 @@ public interface IBscScanGethProxyService
/// <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);

/// <summary>
/// eth_getTransactionReceipt
/// </summary>
/// <param name="txhash">the string representing the hash of the transaction</param>
/// <returns>Returns the receipt of a transaction that has been validated.</returns>
Task<TransactionReceipt?> EthGetTransactionReceipt(string txhash);
}
}
172 changes: 172 additions & 0 deletions src/BscScan.NetCore/Models/Response/Proxy/TransactionReceipt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Proxy
{
/// <summary>
/// TransactionReceipt
/// </summary>
public class TransactionReceipt
{
/// <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 TransactionReceiptData? Result { get; set; }
}

/// <summary>
/// TransactionReceiptData
/// </summary>
public class TransactionReceiptData
{
/// <summary>
/// blockHash
/// </summary>
[JsonPropertyName("blockHash")]
public string? BlockHash { get; set; }

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

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

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

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

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

/// <summary>
/// logs
/// </summary>
[JsonPropertyName("logs")]
public IEnumerable<TransactionReceiptLog>? Logs { get; set; }

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

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

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

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

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

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

/// <summary>
/// TransactionReceiptLog
/// </summary>
public class TransactionReceiptLog
{
/// <summary>
/// address
/// </summary>
[JsonPropertyName("address")]
public string? Address { get; set; }

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

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

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

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

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

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

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

/// <summary>
/// removed
/// </summary>
[JsonPropertyName("removed")]
public bool Removed { 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 @@ -114,5 +114,19 @@ public BscScanGethProxyService(HttpClient bscScanHttpClient, BscScanConfiguratio
var result = await JsonSerializer.DeserializeAsync<SendRawTransaction>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<TransactionReceipt?> EthGetTransactionReceipt(string txhash)
{
var queryParameters = $"{_bscScanModule}".AddAction(ProxyModuleAction.ETH_GET_TRANSACTION_RECEIPT)
.AddQuery(BscQueryParam.TxHash.AppendValue(txhash));
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<TransactionReceipt>(responseStream);
return result;
}
}
}