-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
TransactionForRpc
(Alternative) (#7483)
Co-authored-by: lukasz.rozmej <[email protected]> Co-authored-by: Ben Adams <[email protected]>
- Loading branch information
1 parent
7c411aa
commit 966113f
Showing
81 changed files
with
2,341 additions
and
1,092 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Nethermind/Nethermind.Core/Extensions/UInt256Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
57
src/Nethermind/Nethermind.Facade/Eth/AccessListItemForRpc.cs
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
src/Nethermind/Nethermind.Facade/Eth/AuthorizationTupleForRpc.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
79 changes: 79 additions & 0 deletions
79
src/Nethermind/Nethermind.Facade/Eth/RpcTransaction/AccessListForRpc.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.