Skip to content

Commit

Permalink
remove TransactionJson, use instead TransactionForRpc
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke26 committed Oct 31, 2024
1 parent 482fa5d commit 6e27266
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 89 deletions.
42 changes: 36 additions & 6 deletions tools/Evm/Evm/t8n/JsonTypes/InputData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

using Ethereum.Test.Base;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Crypto;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Serialization.Rlp;

namespace Evm.t8n.JsonTypes;
Expand All @@ -12,22 +15,49 @@ public class InputData
{
public Dictionary<Address, AccountState>? Alloc { get; set; }
public EnvJson? Env { get; set; }
public TransactionJson[]? Txs { get; set; }
public TransactionForRpc[]? Txs { get; set; }
public TransactionMetaData[]? TransactionMetaDataList { get; set; }
public string? TxRlp { get; set; }

public Transaction[] GetTransactions(TxDecoder decoder)
{
Transaction[] transactions = [];
List<Transaction> transactions = [];
if (TxRlp is not null)
{
RlpStream rlp = new(Bytes.FromHexString(TxRlp));
transactions = decoder.DecodeArray(rlp);
transactions = decoder.DecodeArray(rlp).ToList();
}
else if (Txs is not null)
else if (Txs is not null && TransactionMetaDataList is not null)
{
transactions = Txs.Select(txInfo => txInfo.ConvertToTx()).ToArray();
for (int i = 0; i < Txs.Length; i++)
{
var tx = Txs[i].ToTransaction();
tx.SenderAddress = null; // t8n does not accept SenderAddress from input, so need to reset senderAddress

var txLegacy = (LegacyTransactionForRpc) Txs[i];

var secretKey = TransactionMetaDataList[i].SecretKey;

if (secretKey is not null)
{
var privateKey = new PrivateKey(secretKey);
tx.SenderAddress = privateKey.Address;

EthereumEcdsa ecdsa = new(tx.ChainId ?? TestBlockchainIds.ChainId);

ecdsa.Sign(privateKey, tx, TransactionMetaDataList[i].Protected ?? true);
}
else if (txLegacy.R.HasValue && txLegacy.S.HasValue && txLegacy.V.HasValue)
{
tx.Signature = new Signature(txLegacy.R.Value, txLegacy.S.Value, txLegacy.V.Value.ToUInt64(null));
}

tx.Hash = tx.CalculateHash();

transactions.Add(tx);
}
}

return transactions;
return transactions.ToArray();
}
}
81 changes: 0 additions & 81 deletions tools/Evm/Evm/t8n/JsonTypes/TransactionJson.cs

This file was deleted.

10 changes: 10 additions & 0 deletions tools/Evm/Evm/t8n/JsonTypes/TransactionMetaData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Evm.t8n.JsonTypes;

public class TransactionMetaData
{
public bool? Protected { get; set; }
public byte[]? SecretKey { get; set; }
}
5 changes: 3 additions & 2 deletions tools/Evm/Evm/t8n/T8NInputReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Evm.t8n.Errors;
using Evm.t8n.JsonTypes;
using Nethermind.Core;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.Serialization.Json;
using TransactionJson = Evm.t8n.JsonTypes.TransactionJson;

namespace Evm.t8n;

Expand Down Expand Up @@ -40,7 +40,8 @@ public static InputData ReadInputData(T8NCommandArguments arguments)
switch (Path.GetExtension(arguments.InputTxs))
{
case ".json":
inputData.Txs = LoadDataFromFile<TransactionJson[]>(arguments.InputTxs, "txs");
inputData.Txs = LoadDataFromFile<TransactionForRpc[]>(arguments.InputTxs, "txs");
inputData.TransactionMetaDataList = LoadDataFromFile<TransactionMetaData[]>(arguments.InputTxs, "txs");
break;
case ".rlp":
inputData.TxRlp = File.ReadAllText(arguments.InputTxs).Replace("\"", "").Replace("\n", "");
Expand Down

0 comments on commit 6e27266

Please sign in to comment.