Skip to content

Commit

Permalink
eth_getBlockReceipts
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfranblanco committed Nov 28, 2023
1 parent 24452dc commit 5e38191
Show file tree
Hide file tree
Showing 8 changed files with 3,587 additions and 1,321 deletions.
3 changes: 2 additions & 1 deletion src/Nethereum.ClassDiagrams/Nethereum.ClassDiagrams.csproj
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Nethereum.ClassDiagrams</RootNamespace>
<AssemblyName>Nethereum.ClassDiagrams</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
21 changes: 19 additions & 2 deletions src/Nethereum.RPC/ApiMethods.cs
@@ -1,6 +1,21 @@
namespace Nethereum.RPC
{
public enum UnsupportedApiMethods {eth_signTransaction}
public enum UnsupportedApiMethods {
eth_signTransaction,
engine_exchangeCapabilities,
engine_exchangeTransitionConfigurationV1,
engine_forkchoiceUpdatedV1,
engine_forkchoiceUpdatedV2,
engine_forkchoiceUpdatedV3,
engine_getPayloadBodiesByHashV1,
engine_getPayloadBodiesByRangeV1,
engine_getPayloadV1,
engine_getPayloadV2,
engine_getPayloadV3,
engine_newPayloadV1,
engine_newPayloadV2,
engine_newPayloadV3,
}
public enum ApiMethods
{
net_listening,
Expand Down Expand Up @@ -31,6 +46,7 @@ public enum ApiMethods
eth_estimateGas,
eth_getBlockByHash,
eth_getBlockByNumber,
eth_getBlockReceipts,
eth_getTransactionByHash,
eth_getTransactionByBlockHashAndIndex,
eth_getTransactionByBlockNumberAndIndex,
Expand Down Expand Up @@ -101,6 +117,7 @@ public enum ApiMethods
wallet_switchEthereumChain,
wallet_watchAsset,
eth_signTypedData_v4,
personal_sign,
personal_sign

}
}
63 changes: 63 additions & 0 deletions src/Nethereum.RPC/Eth/Blocks/EthGetBlockReceiptsByNumber.cs
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Nethereum.Hex.HexTypes;
using Nethereum.JsonRpc.Client;
using Nethereum.RPC.Eth.DTOs;

namespace Nethereum.RPC.Eth.Blocks
{
public class EthGetBlockReceiptsByNumber : RpcRequestResponseHandler<TransactionReceipt[]>, IEthGetBlockReceiptsByNumber
{
public EthGetBlockReceiptsByNumber(IClient client)
: base(client, ApiMethods.eth_getBlockReceipts.ToString())
{
}

public Task<TransactionReceipt[]> SendRequestAsync(BlockParameter blockParameter, object id = null)
{
if (blockParameter == null) throw new ArgumentNullException(nameof(blockParameter));
return base.SendRequestAsync(id, blockParameter, true);
}

public Task<TransactionReceipt[]> SendRequestAsync(HexBigInteger number, object id = null)
{
if (number == null) throw new ArgumentNullException(nameof(number));
return base.SendRequestAsync(id, number, true);
}

public RpcRequestResponseBatchItem<EthGetBlockReceiptsByNumber, TransactionReceipt[]> CreateBatchItem(HexBigInteger number, object id)
{
return new RpcRequestResponseBatchItem<EthGetBlockReceiptsByNumber, TransactionReceipt[]>(this, BuildRequest(number, id));
}

#if !DOTNET35
public async Task<List<TransactionReceipt[]>> SendBatchRequestAsync(params HexBigInteger[] numbers)
{
var batchRequest = new RpcRequestResponseBatch();
for (int i = 0; i < numbers.Length; i++)
{
batchRequest.BatchItems.Add(CreateBatchItem(numbers[i], i));
}

var response = await Client.SendBatchRequestAsync(batchRequest);
return response.BatchItems.Select(x => ((RpcRequestResponseBatchItem<EthGetBlockReceiptsByNumber, TransactionReceipt[]>)x).Response).ToList();

}
#endif

public RpcRequest BuildRequest(HexBigInteger number, object id = null)
{
if (number == null) throw new ArgumentNullException(nameof(number));
return base.BuildRequest(id, number, true);
}

public RpcRequest BuildRequest(BlockParameter blockParameter, object id = null)
{
if (blockParameter == null) throw new ArgumentNullException(nameof(blockParameter));
return base.BuildRequest(id, blockParameter, true);
}
}
}
20 changes: 20 additions & 0 deletions src/Nethereum.RPC/Eth/Blocks/IEthGetBlockReceiptsByNumber.cs
@@ -0,0 +1,20 @@
using Nethereum.Hex.HexTypes;
using Nethereum.JsonRpc.Client;
using Nethereum.RPC.Eth.DTOs;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Nethereum.RPC.Eth.Blocks
{
public interface IEthGetBlockReceiptsByNumber
{
RpcRequest BuildRequest(BlockParameter blockParameter, object id = null);
RpcRequest BuildRequest(HexBigInteger number, object id = null);
RpcRequestResponseBatchItem<EthGetBlockReceiptsByNumber, TransactionReceipt[]> CreateBatchItem(HexBigInteger number, object id);
#if !DOTNET35
Task<List<TransactionReceipt[]>> SendBatchRequestAsync(params HexBigInteger[] numbers);
#endif
Task<TransactionReceipt[]> SendRequestAsync(BlockParameter blockParameter, object id = null);
Task<TransactionReceipt[]> SendRequestAsync(HexBigInteger number, object id = null);
}
}
2 changes: 2 additions & 0 deletions src/Nethereum.RPC/Eth/Services/EthApiBlockService.cs
Expand Up @@ -14,6 +14,7 @@ public EthApiBlockService(IClient client) : base(client)
GetBlockWithTransactionsByNumber = new EthGetBlockWithTransactionsByNumber(client);
GetBlockWithTransactionsHashesByHash = new EthGetBlockWithTransactionsHashesByHash(client);
GetBlockWithTransactionsHashesByNumber = new EthGetBlockWithTransactionsHashesByNumber(client);
GetBlockReceiptsByNumber = new EthGetBlockReceiptsByNumber(client);
}

public IEthBlockNumber GetBlockNumber { get; private set; }
Expand All @@ -24,5 +25,6 @@ public EthApiBlockService(IClient client) : base(client)
public IEthGetBlockWithTransactionsByNumber GetBlockWithTransactionsByNumber { get; private set; }
public IEthGetBlockWithTransactionsHashesByHash GetBlockWithTransactionsHashesByHash { get; private set; }
public IEthGetBlockWithTransactionsHashesByNumber GetBlockWithTransactionsHashesByNumber { get; private set; }
public IEthGetBlockReceiptsByNumber GetBlockReceiptsByNumber { get; private set; }
}
}
1 change: 1 addition & 0 deletions src/Nethereum.RPC/Eth/Services/IEthApiBlockService.cs
Expand Up @@ -11,5 +11,6 @@ public interface IEthApiBlockService
IEthGetBlockWithTransactionsByNumber GetBlockWithTransactionsByNumber { get; }
IEthGetBlockWithTransactionsHashesByHash GetBlockWithTransactionsHashesByHash { get; }
IEthGetBlockWithTransactionsHashesByNumber GetBlockWithTransactionsHashesByNumber { get; }
IEthGetBlockReceiptsByNumber GetBlockReceiptsByNumber { get; }
}
}
18 changes: 15 additions & 3 deletions tests/Nethereum.RPC.UnitTests/OpenRpcTests.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -45,14 +46,21 @@ public void ShouldHaveAllMethodsListedInApiMethodsWhenNotUnsupported()
{
var openRpc = GetOpenRpc();
JArray methods = (JArray) openRpc["methods"];
var failed = false;
foreach (var method in methods)
{
var methodName = method["name"].ToString();
if (!Enum.TryParse(methodName, out UnsupportedApiMethods unsupportedApiMethod))
{
Assert.True(Enum.TryParse(methodName, out ApiMethods apiMethod));
if (!Enum.TryParse(methodName, out ApiMethods apiMethod))
{
Debug.WriteLine(methodName);
failed = true;
};
}
}

Assert.False(failed);
}

[Fact]
Expand All @@ -70,7 +78,7 @@ public void ShouldHaveAllComponentsMapped()
if (!simpleMappings.ContainsKey(schemaName))
{
var complexValidators = complexMappings.Where(x => x.Name == schemaName);
if(!complexValidators.Any()) throw new Exception("Complex Object Not Mapped");
if(!complexValidators.Any()) throw new Exception("Complex Object Not Mapped: " + schemaName);
foreach (var complexTypeValidation in complexValidators)
{
if (!complexTypeValidation.Ignored)
Expand Down Expand Up @@ -210,6 +218,7 @@ public List<ComplexTypeValidation> ComplexComponentTypeMappings()
list.Add(new ComplexTypeValidation { Name = "StorageProof", Type = typeof(StorageProof), Ignored = false });
list.Add(new ComplexTypeValidation { Name = "Access list result", Type = typeof(AccessListGasUsed), Ignored = true });
list.Add(new ComplexTypeValidation { Name = "BadBlock", Type = typeof(BadBlock), Ignored = false });
list.Add(new ComplexTypeValidation { Name = "notFound", Ignored = true });

return list;

Expand All @@ -222,11 +231,14 @@ public List<ComplexTypeValidation> ComplexComponentTypeMappings()
mappings.Add("address", typeof(string));
mappings.Add("addresses", typeof(string[]));
mappings.Add("byte", typeof(string));
mappings.Add("bytes", typeof(string));
mappings.Add("bytesMax32", typeof(string));
mappings.Add("bytes", typeof(string));
mappings.Add("bytes48", typeof(string));
mappings.Add("bytes8", typeof(string));
mappings.Add("bytes32", typeof(string));
mappings.Add("bytes256", typeof(string));
mappings.Add("bytes65", typeof(string));
mappings.Add("ratio", typeof(HexBigInteger));
mappings.Add("uint", typeof(HexBigInteger));
mappings.Add("uint64", typeof(HexBigInteger));
mappings.Add("uint256", typeof(HexBigInteger));
Expand Down

0 comments on commit 5e38191

Please sign in to comment.