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

Refactor TransactionForRpc (Alternative) #7483

Merged
merged 189 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
84178b8
Initial `RpcLegacyTransaction`
emlautarom1 Sep 4, 2024
a2739f4
Change field order
emlautarom1 Sep 5, 2024
af3b042
Support null as `ChainId` through `TransactionBuilder`
emlautarom1 Sep 5, 2024
ec1a21e
Initial `RpcAccessListTransaction`
emlautarom1 Sep 5, 2024
88dd0e3
Add `RandomSignature`s
emlautarom1 Sep 5, 2024
e9994ea
Use `TestItem` random `Signature`s
emlautarom1 Sep 5, 2024
1839a0d
Initial `RpcEIP1559Transaction`
emlautarom1 Sep 5, 2024
2833a9e
Rename `TestCaseSource`
emlautarom1 Sep 5, 2024
3caed48
Fix `DefaultChainId`
emlautarom1 Sep 5, 2024
67ec222
Guarantee Blob transaction invariants
emlautarom1 Sep 5, 2024
0f997c9
Initial `RpcBlobTransaction`
emlautarom1 Sep 5, 2024
5ae394a
Initial `IRpcTransaction`
emlautarom1 Sep 10, 2024
14d3cae
Initial `IRpcTransactionConverter`
emlautarom1 Sep 10, 2024
11c237e
Move `RpcXTransaction` to class hierarchy
emlautarom1 Sep 10, 2024
7580bc4
Merge `RPCXTransactionTests` into a single test
emlautarom1 Sep 10, 2024
b073e50
Rename test class
emlautarom1 Sep 11, 2024
a13fcc0
Initial `RpcOptimismTransaction`
emlautarom1 Sep 11, 2024
48326d5
Add `WithSourceHash` to builder
emlautarom1 Sep 11, 2024
16765be
Initial `RpcAccessList`
emlautarom1 Sep 11, 2024
f673490
Annotate converter instead of registering
emlautarom1 Sep 11, 2024
cdd4f23
Use annotation for `IRpcTransaction`
emlautarom1 Sep 11, 2024
a9f6277
Initial `RpcGenericTransaction`
emlautarom1 Sep 12, 2024
7db803b
Initial JSON deserialization code
emlautarom1 Sep 13, 2024
0fee0cf
Remove `TxReceipt` for now
emlautarom1 Sep 13, 2024
19686a1
Test for member equality in JSON (de)serialization
emlautarom1 Sep 13, 2024
38f2a1f
Introduce `ITransactionConverter<T>`
emlautarom1 Sep 13, 2024
4e040bf
Add `TODO`
emlautarom1 Sep 13, 2024
07690be
Update inline docs
emlautarom1 Sep 13, 2024
92394c1
Whitespace
emlautarom1 Sep 13, 2024
b7c42cf
Delete unused classes
emlautarom1 Sep 13, 2024
fe8e7e7
Define `RpcNethermindTransaction` as base class
emlautarom1 Sep 13, 2024
c76f72f
Inherit from `RpcNethermindTransaction`
emlautarom1 Sep 13, 2024
629dda7
Add `TransactionConverterExtraData`
emlautarom1 Sep 13, 2024
e3c884a
Add `ToTransaction`
emlautarom1 Sep 13, 2024
33213e5
Implement `ToTransaction`
emlautarom1 Sep 13, 2024
115dbfc
Update inline docs
emlautarom1 Sep 13, 2024
fb91767
Remove deprecated fields in Blob transactions
emlautarom1 Sep 13, 2024
90fe6fa
Retrofit `Data ~ Input` fix
emlautarom1 Sep 13, 2024
121e057
Move docs
emlautarom1 Sep 13, 2024
cbc3b7f
Initial `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
3660df5
Change `ChainId` from UInt256 to ulong in JSON DTO
emlautarom1 Sep 16, 2024
5311804
Update inline TODOs
emlautarom1 Sep 16, 2024
f8c0495
Implement remaining `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
dd43cf9
Add `From` field
emlautarom1 Sep 16, 2024
34de464
Add defaults test
emlautarom1 Sep 16, 2024
f8283e4
Add `EnsureDefaults`
emlautarom1 Sep 16, 2024
0b63ce6
Add test ignore
emlautarom1 Sep 16, 2024
eb98675
Forward `baseFee`
emlautarom1 Sep 16, 2024
11b1522
Use `RpcGenericTransaction` approach
emlautarom1 Sep 16, 2024
f4dd96b
Update flow docs
emlautarom1 Sep 16, 2024
8ee417e
Remove JSON constructor
emlautarom1 Sep 16, 2024
422460b
Add `IToTransaction<T>`
emlautarom1 Sep 16, 2024
416a21e
Add `RpcGenericTransaction`
emlautarom1 Sep 16, 2024
e2683f9
Implement `IToTransaction, IFromTransaction`
emlautarom1 Sep 16, 2024
1bb457d
Implement `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
aaf6d53
Remove deleted files
emlautarom1 Sep 16, 2024
443115c
Implement `IToTransaction, IFromTransaction` for OP
emlautarom1 Sep 16, 2024
c431ad9
Add `EnsureDefaults`
emlautarom1 Sep 16, 2024
6cda988
Remove roundtrip tests
emlautarom1 Sep 16, 2024
e2e7691
Test for Nethermind fields
emlautarom1 Sep 16, 2024
5ad5049
Move files
emlautarom1 Sep 16, 2024
825d455
Proper inline docs
emlautarom1 Sep 16, 2024
5f3e553
Rename class
emlautarom1 Sep 16, 2024
79761d0
Fix import
emlautarom1 Sep 16, 2024
1ff3356
Simplify XML reference
emlautarom1 Sep 16, 2024
80264f4
Fix imports
emlautarom1 Sep 16, 2024
e07620d
Make fields `init` only
emlautarom1 Sep 16, 2024
70abd1b
Add transition `RpcGenericTransactionExtensions`
emlautarom1 Sep 16, 2024
aba2970
Preserve nullability
emlautarom1 Sep 16, 2024
70b175c
Simplify accessor
emlautarom1 Sep 16, 2024
93f94a9
Remove `chainId` from `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
a9a06f4
Add more fallback methods durin dev
emlautarom1 Sep 16, 2024
4d88ba9
Remove `IRpcTransaction`
emlautarom1 Sep 16, 2024
e5d576d
Mimic `RpcNethermindTransaction.TransactionConverter`
emlautarom1 Sep 16, 2024
1d13861
Remove duplicated comment
emlautarom1 Sep 16, 2024
8a70ee5
Merge branch 'master' into refactor/individual-transaction-for-rpc
emlautarom1 Sep 16, 2024
04133ef
Fix whitespace
emlautarom1 Sep 16, 2024
4a07b2e
Merge branch 'master' into refactor/individual-transaction-for-rpc
emlautarom1 Sep 18, 2024
28e7173
Revert (again) to class hierarchy deserialization
emlautarom1 Sep 18, 2024
4f115eb
Reorder field initiatlization
emlautarom1 Sep 18, 2024
154512f
Add `From`
emlautarom1 Sep 18, 2024
d52c29a
Use `default`
emlautarom1 Sep 18, 2024
9d587ae
Add `ToTransaction`
emlautarom1 Sep 18, 2024
e51e23a
Assert subclass
emlautarom1 Sep 18, 2024
0df8888
Hide converter classes
emlautarom1 Sep 18, 2024
02e5765
Do not serialize `From` field
emlautarom1 Sep 18, 2024
ff726c8
Change `DefaultChainId` type
emlautarom1 Sep 18, 2024
865102a
Test for type constraint
emlautarom1 Sep 18, 2024
67895c2
Add `blobs`
emlautarom1 Sep 18, 2024
fce6373
Fix Tx Builder
emlautarom1 Sep 18, 2024
c804800
Add JSON constructors
emlautarom1 Sep 18, 2024
182ad70
Update licence year
emlautarom1 Sep 18, 2024
e52c79d
Update `RpcAccessList` tests
emlautarom1 Sep 19, 2024
aec8152
Add `EnsureDefaults`
emlautarom1 Sep 19, 2024
fcb1557
Implement abstract method in `RpcOptimismTransaction`
emlautarom1 Sep 19, 2024
fe90fcf
Add `Nonce` to Optimism
emlautarom1 Sep 19, 2024
a3b80d8
Make `Nonce` nullable
emlautarom1 Sep 19, 2024
8096c9e
Support nullable `StorageKeys`
emlautarom1 Sep 19, 2024
e30d035
Add nullability annotation
emlautarom1 Sep 19, 2024
19abbe0
Remove converter static field
emlautarom1 Sep 19, 2024
aea65b7
Add `Data` as an alias
emlautarom1 Sep 19, 2024
d153056
Add default JSON converters for RPC Transactions
emlautarom1 Sep 19, 2024
8a90075
Support deserializing string wrapped objects
emlautarom1 Sep 20, 2024
f44b4e4
Update main code
emlautarom1 Sep 20, 2024
9f10463
Delete Optimism RPC class
emlautarom1 Sep 20, 2024
cd5b22d
Make `TxType` to `virtual` to ensure invariants
emlautarom1 Sep 20, 2024
8420769
Include `TransactionConverterExtraData`
emlautarom1 Sep 20, 2024
7f72f37
Serialize `From`
emlautarom1 Sep 20, 2024
302a125
Update comparison to use JSON equality
emlautarom1 Sep 20, 2024
9eda9fd
Update comparison to use JSON equality
emlautarom1 Sep 20, 2024
6ee32a1
Use new types
emlautarom1 Sep 20, 2024
fe46fe2
Reintroduce TxType asserts
emlautarom1 Sep 20, 2024
78db619
Use Newtonsoft.JSON for tests
emlautarom1 Sep 20, 2024
4d4628e
Use class instead of record
emlautarom1 Sep 20, 2024
3e44de9
Use Newtonsoft.JSON for tests
emlautarom1 Sep 20, 2024
49521cb
Use Newtonsoft.JSON for tests
emlautarom1 Sep 23, 2024
78fd52f
Use new types
emlautarom1 Sep 23, 2024
8cd3505
Use new types
emlautarom1 Sep 23, 2024
0a6c06a
Update tests
emlautarom1 Sep 23, 2024
5db8814
Test for proper JSON equality
emlautarom1 Sep 23, 2024
cb1c471
Use new types
emlautarom1 Sep 23, 2024
9f4e404
Use new types
emlautarom1 Sep 23, 2024
ec83822
Use new types
emlautarom1 Sep 23, 2024
84022e1
Use new types
emlautarom1 Sep 23, 2024
ce86129
Use new types
emlautarom1 Sep 23, 2024
2ea0629
Reintroduce `UpdateTxType`
emlautarom1 Sep 23, 2024
0cda531
Use new types
emlautarom1 Sep 23, 2024
5ab8eb6
Update base class
emlautarom1 Sep 23, 2024
61bd483
Fix test
emlautarom1 Sep 23, 2024
ed8dc32
Rollback builder changes
emlautarom1 Sep 23, 2024
8d2eb6f
Use new types
emlautarom1 Sep 23, 2024
de52ef9
Rename RpcTransaction
emlautarom1 Sep 23, 2024
80ea178
Rename Optimism transaction
emlautarom1 Sep 23, 2024
5ad37bf
Rename struct
emlautarom1 Sep 23, 2024
0f0d03e
Remove traces from previous naming
emlautarom1 Sep 23, 2024
564ab95
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 23, 2024
4035a07
Use correct code
emlautarom1 Sep 23, 2024
5145de9
Run dotnet format
emlautarom1 Sep 23, 2024
d710e79
Make types explicit
emlautarom1 Sep 23, 2024
b0e9075
Add `Nonce` to Optimism JSON serialization
emlautarom1 Sep 24, 2024
6144dab
1. Move more to generics
LukaszRozmej Sep 24, 2024
e2a9968
remove unneded method
LukaszRozmej Sep 24, 2024
6e801bc
fixes
LukaszRozmej Sep 24, 2024
51bc6bf
whitespace
LukaszRozmej Sep 24, 2024
93ca13b
Reduce code
emlautarom1 Sep 24, 2024
8ac7342
Cleanup docs, naming and nullability annotations
emlautarom1 Sep 24, 2024
bae6ecc
Merge remote-tracking branch 'origin/master' into refactor/transactio…
emlautarom1 Sep 25, 2024
d8a4465
Remove redundant default parameter
emlautarom1 Sep 25, 2024
b617ede
Separate `ITxTyped` from `IFromTransaction`
emlautarom1 Sep 25, 2024
4e90ed8
Inline private method
emlautarom1 Sep 25, 2024
7152b65
Rename tests
emlautarom1 Sep 25, 2024
86c5c77
Merge test suites
emlautarom1 Sep 25, 2024
fa24456
Reintroduce local method for consistency
emlautarom1 Sep 25, 2024
de871bf
Casing
emlautarom1 Sep 25, 2024
112a72c
Inline all JSON equality tests
emlautarom1 Sep 25, 2024
f841207
Move `ShouldSetBaseFee` to class method
emlautarom1 Sep 25, 2024
fa0b53e
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 25, 2024
7c67ad6
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 26, 2024
86d7ce3
Revert interface hierarchy
emlautarom1 Sep 27, 2024
58f2acc
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 27, 2024
40c7ba2
Fix merge
emlautarom1 Sep 27, 2024
d0025fd
Pass `ChainId` to `FromTransaction`
emlautarom1 Sep 27, 2024
992e8e7
Pass `ChainId` to `TxPoolContent`
emlautarom1 Sep 27, 2024
1cb3e4f
Remove `DefaultChainId` hack
emlautarom1 Sep 27, 2024
ac903ad
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 27, 2024
750ad0d
Remove defaulting mechanism for OP transactions
emlautarom1 Sep 30, 2024
f004f26
Reject malformed OP transactions
emlautarom1 Sep 30, 2024
ebb50d2
Initialize serializer once
emlautarom1 Sep 30, 2024
7738c0f
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 30, 2024
7562257
Formatting
emlautarom1 Sep 30, 2024
0690958
Reintroduce laziness to `AccessListForRpc`
emlautarom1 Oct 1, 2024
b785352
Wrap up `Nonce` behavior in OP
emlautarom1 Oct 1, 2024
7c4a9ed
Fix Blob transaction code
emlautarom1 Oct 1, 2024
1c68869
Json Type parsing (#7538)
benaadams Oct 2, 2024
58396a8
Change private `TransactionType` to struct
emlautarom1 Oct 2, 2024
0ff03ac
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 2, 2024
281f6af
Merge branch 'refactor/transaction-for-rpc-hierarchy' of https://gith…
emlautarom1 Oct 2, 2024
42c1b29
Avoid double serialization in tests
emlautarom1 Oct 3, 2024
5002733
Avoid double serialization in RPC tests (#7547)
emlautarom1 Oct 4, 2024
686269f
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 4, 2024
e51b88d
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 8, 2024
0e97573
Add `SetCodeTransactionForRpc`
emlautarom1 Oct 8, 2024
02a3537
Add `AuthorizationListForRpc`
emlautarom1 Oct 8, 2024
52cec69
Do not serialize deprecated fields in SetCode transactions
emlautarom1 Oct 8, 2024
0225a5c
Remove TODO
emlautarom1 Oct 8, 2024
806bb2c
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 9, 2024
c9d0730
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 14, 2024
b6b57bf
Remove nullability annotations
emlautarom1 Oct 14, 2024
2023723
Include Y, R, and yParity fields
emlautarom1 Oct 14, 2024
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
8 changes: 6 additions & 2 deletions src/Nethermind/Nethermind.Api/INethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System;
using Nethermind.Config;
using Nethermind.Core;
using Nethermind.Facade.Eth;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Serialization.Rlp;
using Nethermind.Serialization.Rlp.TxDecoders;
using Nethermind.TxPool;
Expand All @@ -23,12 +25,14 @@ public T Config<T>() where T : IConfig

public static class NethermindApiExtensions
{
public static void RegisterTxType(this INethermindApi api, TxType type, ITxDecoder decoder, ITxValidator validator)
public static void RegisterTxType<T>(this INethermindApi api, ITxDecoder decoder, ITxValidator validator) where T : TransactionForRpc, IFromTransaction<T>
{
ArgumentNullException.ThrowIfNull(api.TxValidator);
if (decoder.Type != T.TxType) throw new ArgumentException($"TxType mismatch decoder: {decoder.Type}, RPC: {T.TxType}");

api.TxValidator.RegisterValidator(type, validator);
api.TxValidator.RegisterValidator(T.TxType, validator);
TxDecoder.Instance.RegisterDecoder(decoder);
TransactionForRpc.RegisterTransactionType<T>();
}
}
}
5 changes: 2 additions & 3 deletions src/Nethermind/Nethermind.Cli.Test/ProofCliModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
using Nethermind.Cli.Modules;
using Nethermind.Core.Crypto;
using Nethermind.Core.Test.Builders;
using Nethermind.Facade.Eth;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.JsonRpc;
using Nethermind.JsonRpc.Client;
using Nethermind.JsonRpc.Data;
using Nethermind.Logging;
using Nethermind.Serialization.Json;
using NSubstitute;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void Get_transaction_receipt(bool includeHeader)
public void Call()
{
Hash256 blockHash = TestItem.KeccakA;
TransactionForRpc tx = new()
LegacyTransactionForRpc tx = new()
{
From = TestItem.AddressA,
To = TestItem.AddressB
Expand Down
19 changes: 10 additions & 9 deletions src/Nethermind/Nethermind.Cli/Modules/EthCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Facade.Eth;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Int256;
using Nethermind.JsonRpc.Data;

namespace Nethermind.Cli.Modules
{
Expand All @@ -20,13 +19,15 @@ public class EthCliModule : CliModuleBase
{
long blockNumber = NodeManager.Post<long>("eth_blockNumber").Result;

TransactionForRpc tx = new();
tx.Value = amountInWei;
tx.Gas = Transaction.BaseTxGasCost;
tx.GasPrice = (UInt256)Engine.JintEngine.GetValue("gasPrice").AsNumber();
tx.To = address;
tx.Nonce = (ulong)NodeManager.Post<long>("eth_getTransactionCount", from, blockNumber).Result;
tx.From = from;
LegacyTransactionForRpc tx = new()
{
Value = amountInWei,
Gas = Transaction.BaseTxGasCost,
GasPrice = (UInt256)Engine.JintEngine.GetValue("gasPrice").AsNumber(),
To = address,
Nonce = (ulong)NodeManager.Post<long>("eth_getTransactionCount", from, blockNumber).Result,
From = from
};

Hash256? keccak = NodeManager.Post<Hash256>("eth_sendTransaction", tx).Result;
return keccak?.Bytes.ToHexString();
Expand Down
10 changes: 10 additions & 0 deletions src/Nethermind/Nethermind.Core.Test/Builders/TestItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ static TestItem()
Keccaks[i - 1] = Keccak.Compute(PublicKeys[i - 1].Bytes);
ValueKeccaks[i - 1] = Keccaks[i - 1];
}

byte[] r = new byte[32];
byte[] s = new byte[32];
r[1] = 1;
s[2] = 2;
RandomSignatureA = new Signature(r, s, 27);
RandomSignatureB = new Signature(r, s, 28);
}

public static Hash256 KeccakFromNumber(int i)
Expand Down Expand Up @@ -93,6 +100,9 @@ public static Hash256 KeccakFromNumber(int i)
public static Address AddressE = PublicKeyE.Address;
public static Address AddressF = PublicKeyF.Address;

public static readonly Signature RandomSignatureA;
public static readonly Signature RandomSignatureB;

public static Withdrawal WithdrawalA_1Eth = new() { Address = AddressA, Index = 1, ValidatorIndex = 2001, AmountInGwei = 1_000_000_000 };
public static Withdrawal WithdrawalB_2Eth = new() { Address = AddressB, Index = 2, ValidatorIndex = 2002, AmountInGwei = 2_000_000_000 };
public static Withdrawal WithdrawalC_3Eth = new() { Address = AddressC, Index = 3, ValidatorIndex = 2003, AmountInGwei = 3_000_000_000 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public TransactionBuilder<T> WithCode(byte[] data)
return this;
}

public TransactionBuilder<T> WithChainId(ulong chainId)
public TransactionBuilder<T> WithChainId(ulong? chainId)
{
TestObjectInternal.ChainId = chainId;
return this;
Expand Down Expand Up @@ -298,6 +298,12 @@ public TransactionBuilder<T> WithIsServiceTransaction(bool isServiceTransaction)
return this;
}

public TransactionBuilder<T> WithSourceHash(Hash256? sourceHash)
{
TestObjectInternal.SourceHash = sourceHash;
return this;
}

public TransactionBuilder<T> From(T item)
{
TestObjectInternal = item;
Expand Down
13 changes: 13 additions & 0 deletions src/Nethermind/Nethermind.Core/Extensions/UInt256Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Nethermind.Int256;

namespace Nethermind.Core.Extensions;

public static class UInt256Extensions
{
// value?.IsZero == false <=> x > 0
public static bool IsPositive(this UInt256? @this) => @this?.IsZero == false;
}
57 changes: 0 additions & 57 deletions src/Nethermind/Nethermind.Facade/Eth/AccessListItemForRpc.cs

This file was deleted.

43 changes: 0 additions & 43 deletions src/Nethermind/Nethermind.Facade/Eth/AuthorizationTupleForRpc.cs

This file was deleted.

6 changes: 5 additions & 1 deletion src/Nethermind/Nethermind.Facade/Eth/BlockForRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Nethermind.Serialization.Rlp;
using System.Text.Json.Serialization;
using System.Runtime.CompilerServices;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Core.ConsensusRequests;

namespace Nethermind.Facade.Eth;
Expand Down Expand Up @@ -78,7 +79,10 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider s
StateRoot = block.StateRoot;
Timestamp = block.Timestamp;
TotalDifficulty = block.TotalDifficulty ?? 0;
Transactions = includeFullTransactionData ? block.Transactions.Select((t, idx) => new TransactionForRpc(block.Hash, block.Number, idx, t, block.BaseFeePerGas)).ToArray() : block.Transactions.Select(t => t.Hash).OfType<object>().ToArray();
Transactions = (includeFullTransactionData
? block.Transactions.Select((t, idx) => TransactionForRpc.FromTransaction(t, block.Hash, block.Number, idx, block.BaseFeePerGas, specProvider.ChainId))
: block.Transactions.Select(t => t.Hash).OfType<object>())
.ToArray();
TransactionsRoot = block.TxRoot;
Uncles = block.Uncles.Select(o => o.Hash);
Withdrawals = block.Withdrawals;
Expand Down
24 changes: 24 additions & 0 deletions src/Nethermind/Nethermind.Facade/Eth/IFromTransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Int256;

namespace Nethermind.Facade.Eth;

public interface IFromTransaction<out T> : ITxTyped where T : TransactionForRpc
{
static abstract T FromTransaction(Transaction tx, TransactionConverterExtraData extraData);
}

public readonly struct TransactionConverterExtraData
{
public ulong? ChainId { get; init; }
public Hash256? BlockHash { get; init; }
public long? BlockNumber { get; init; }
public int? TxIndex { get; init; }
public UInt256? BaseFee { get; init; }
public TxReceipt Receipt { get; init; }
}
11 changes: 11 additions & 0 deletions src/Nethermind/Nethermind.Facade/Eth/ITxTyped.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;

namespace Nethermind.Facade.Eth;

public interface ITxTyped
{
static abstract TxType TxType { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Eip2930;
using Nethermind.Int256;
using Nethermind.Serialization.Json;
using System.Text.Json.Serialization;
using System.Text.Json;
using System;

namespace Nethermind.Facade.Eth.RpcTransaction;

[JsonConverter(typeof(JsonConverter))]
public class AccessListForRpc
{
private readonly IEnumerable<Item> _items;

[JsonConstructor]
public AccessListForRpc() { }

private AccessListForRpc(IEnumerable<Item> items)
{
_items = items;
}

private class Item
{
public Address Address { get; set; }

[JsonConverter(typeof(StorageCellIndexConverter))]
public IEnumerable<UInt256>? StorageKeys { get; set; }

[JsonConstructor]
public Item() { }

public Item(Address address, IEnumerable<UInt256> storageKeys)
{
Address = address;
StorageKeys = storageKeys;
}
}

public static AccessListForRpc FromAccessList(AccessList? accessList) =>
accessList is null
? new AccessListForRpc([])
: new AccessListForRpc(accessList.Select(item => new Item(item.Address, [.. item.StorageKeys])));

public AccessList ToAccessList()
{
AccessList.Builder builder = new();
foreach (Item item in _items)
{
builder.AddAddress(item.Address);
foreach (UInt256 index in item.StorageKeys ?? [])
{
builder.AddStorage(index);
}
}

return builder.Build();
}

public class JsonConverter : JsonConverter<AccessListForRpc>
{
public override AccessListForRpc? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
List<Item>? list = JsonSerializer.Deserialize<List<Item>>(ref reader, options);
return list is null ? null : new AccessListForRpc(list);
}

public override void Write(Utf8JsonWriter writer, AccessListForRpc value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value._items, options);
}
}
}
Loading
Loading