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

Implement eth_getRawTransactionByHash #7425

Merged
merged 2 commits into from
Sep 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public async Task Eth_get_transaction_by_hash()
Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":{\"hash\":\"0x7126cf20a0ad8bd51634837d9049615c34c1bff5e1a54e5663f7e23109bff48b\",\"nonce\":\"0x2\",\"blockHash\":\"0x29f141925d2d8e357ae5b6040c97aa12d7ac6dfcbe2b20e7b616d8907ac8e1f3\",\"blockNumber\":\"0x3\",\"transactionIndex\":\"0x1\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"value\":\"0x1\",\"gasPrice\":\"0x1\",\"gas\":\"0x5208\",\"input\":\"0x\",\"type\":\"0x0\",\"v\":\"0x25\",\"s\":\"0x575361bb330bf38b9a89dd8279d42a20d34edeaeede9739a7c2bdcbe3242d7bb\",\"r\":\"0xe7c5ff3cba254c4fe8f9f12c3f202150bb9a0aebeee349ff2f4acb23585f56bd\"},\"id\":67}"), serialized.Replace("\"", "\\\""));
}

[Test]
public async Task Eth_get_raw_transaction_by_hash()
{
using Context ctx = await Context.Create();
string serialized = await ctx.Test.TestEthRpc("eth_getRawTransactionByHash", ctx.Test.BlockTree.FindHeadBlock()!.Transactions.Last().Hash!.ToString());
Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":\"f85f020182520894942921b14f1b1c385cd7e0cc2ef7abe5598c8358018025a0e7c5ff3cba254c4fe8f9f12c3f202150bb9a0aebeee349ff2f4acb23585f56bda0575361bb330bf38b9a89dd8279d42a20d34edeaeede9739a7c2bdcbe3242d7bb\",\"id\":67}"), serialized.Replace("\"", "\\\""));
}


[Test]
public async Task eth_maxPriorityFeePerGas_test()
{
Expand Down
21 changes: 18 additions & 3 deletions src/Nethermind/Nethermind.JsonRpc/Modules/Eth/EthRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DotNetty.Buffers;
using Nethermind.Blockchain.Filters;
using Nethermind.Blockchain.Find;
using Nethermind.Blockchain.Receipts;
Expand Down Expand Up @@ -367,18 +368,32 @@ public ResultWrapper<BlockForRpc> eth_getBlockByNumber(BlockParameter blockParam
: new BlockForRpc(block, returnFullTransactionObjects, _specProvider));
}

public Task<ResultWrapper<TransactionForRpc>> eth_getTransactionByHash(Hash256 transactionHash)
public ResultWrapper<TransactionForRpc?> eth_getTransactionByHash(Hash256 transactionHash)
{
(TxReceipt? receipt, Transaction? transaction, UInt256? baseFee) = _blockchainBridge.GetTransaction(transactionHash, checkTxnPool: true);
if (transaction is null)
{
return Task.FromResult(ResultWrapper<TransactionForRpc>.Success(null));
return ResultWrapper<TransactionForRpc?>.Success(null);
}

RecoverTxSenderIfNeeded(transaction);
TransactionForRpc transactionModel = new(receipt?.BlockHash, receipt?.BlockNumber, receipt?.Index, transaction, baseFee);
if (_logger.IsTrace) _logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}");
return Task.FromResult(ResultWrapper<TransactionForRpc>.Success(transactionModel));
return ResultWrapper<TransactionForRpc?>.Success(transactionModel);
}

public ResultWrapper<string?> eth_getRawTransactionByHash(Hash256 transactionHash)
{
Transaction? transaction = _blockchainBridge.GetTransaction(transactionHash, checkTxnPool: true).Transaction;
if (transaction is null)
{
return ResultWrapper<string?>.Success(null);
}

IByteBuffer buffer = PooledByteBufferAllocator.Default.Buffer(TxDecoder.Instance.GetLength(transaction, RlpBehaviors.None));
LukaszRozmej marked this conversation as resolved.
Show resolved Hide resolved
using NettyRlpStream stream = new(buffer);
TxDecoder.Instance.Encode(stream, transaction);
return ResultWrapper<string?>.Success(buffer.AsSpan().ToHexString(false));
LukaszRozmej marked this conversation as resolved.
Show resolved Hide resolved
}

public ResultWrapper<TransactionForRpc[]> eth_pendingTransactions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ ResultWrapper<IReadOnlyList<SimulateBlockResult>> eth_simulateV1([JsonRpcParamet
Description = "Retrieves a transaction by hash",
IsSharable = true,
ExampleResponse = "{\"hash\":\"0xabca23910646013d608ec671de099447ab60b2b7159ad8319c3c088e8d9ea0fa\",\"nonce\":\"0x1a\",\"blockHash\":\"0xcb6756f69e0469acd5e5bb77966be580786ec2c11de85c9ddfd75257010e34f8\",\"blockNumber\":\"0x4dfbc7\",\"transactionIndex\":\"0xb\",\"from\":\"0xe1e7ab1c643dbe5b24739fdf2a5c7c193b54dd99\",\"to\":\"0x0b10e304088b2ba2b2acfd2f72573faad31a13a5\",\"value\":\"0x0\",\"gasPrice\":\"0x2540be400\",\"gas\":\"0xb4a4\",\"data\":\"0x095ea7b300000000000000000000000092c1576845703089cf6c0788379ed81f75f45dd500000000000000000000000000000000000000000000000000000002540be400\",\"input\":\"0x095ea7b300000000000000000000000092c1576845703089cf6c0788379ed81f75f45dd500000000000000000000000000000000000000000000000000000002540be400\",\"type\":\"0x0\",\"v\":\"0x2d\",\"s\":\"0x496d72d435ead8a8a9a865b14d6a102c1a9f848681d050dbbf11c522c612235\",\"r\":\"0xc8350e831203fecc8bff41f5cf858ac1d121e4b4d9e59c1137cc9440516ca9fd\"}")]
Task<ResultWrapper<TransactionForRpc>> eth_getTransactionByHash(
ResultWrapper<TransactionForRpc?> eth_getTransactionByHash(
[JsonRpcParameter(ExampleValue = "\"0xabca23910646013d608ec671de099447ab60b2b7159ad8319c3c088e8d9ea0fa\"")] Hash256 transactionHash);

[JsonRpcMethod(IsImplemented = true,
Description = "Retrieves a transaction RLP by hash",
IsSharable = true)]
public ResultWrapper<string?> eth_getRawTransactionByHash(Hash256 transactionHash);

[JsonRpcMethod(IsImplemented = true,
Description = "Returns the pending transactions list",
IsSharable = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IOptimismEthRpcModule : IEthRpcModule
Description = "Retrieves a transaction by hash",
IsSharable = true,
ExampleResponse = "{\"hash\":\"0xabca23910646013d608ec671de099447ab60b2b7159ad8319c3c088e8d9ea0fa\",\"nonce\":\"0x1a\",\"blockHash\":\"0xcb6756f69e0469acd5e5bb77966be580786ec2c11de85c9ddfd75257010e34f8\",\"blockNumber\":\"0x4dfbc7\",\"transactionIndex\":\"0xb\",\"from\":\"0xe1e7ab1c643dbe5b24739fdf2a5c7c193b54dd99\",\"to\":\"0x0b10e304088b2ba2b2acfd2f72573faad31a13a5\",\"value\":\"0x0\",\"gasPrice\":\"0x2540be400\",\"gas\":\"0xb4a4\",\"data\":\"0x095ea7b300000000000000000000000092c1576845703089cf6c0788379ed81f75f45dd500000000000000000000000000000000000000000000000000000002540be400\",\"input\":\"0x095ea7b300000000000000000000000092c1576845703089cf6c0788379ed81f75f45dd500000000000000000000000000000000000000000000000000000002540be400\",\"type\":\"0x0\",\"v\":\"0x2d\",\"s\":\"0x496d72d435ead8a8a9a865b14d6a102c1a9f848681d050dbbf11c522c612235\",\"r\":\"0xc8350e831203fecc8bff41f5cf858ac1d121e4b4d9e59c1137cc9440516ca9fd\"}")]
new Task<ResultWrapper<OptimismTransactionForRpc?>> eth_getTransactionByHash(
new ResultWrapper<OptimismTransactionForRpc?> eth_getTransactionByHash(
[JsonRpcParameter(ExampleValue = "\"0xabca23910646013d608ec671de099447ab60b2b7159ad8319c3c088e8d9ea0fa\"")] Hash256 transactionHash);

[JsonRpcMethod(IsImplemented = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ public override async Task<ResultWrapper<Hash256>> eth_sendRawTransaction(byte[]
new(txHash, (OptimismTxReceipt)receipt, gasInfo.Value, l1GasInfo.GetTxGasInfo(block.Transactions.First(tx => tx.Hash == txHash)), logIndexStart));
}

public new Task<ResultWrapper<OptimismTransactionForRpc?>> eth_getTransactionByHash(Hash256 transactionHash)
public new ResultWrapper<OptimismTransactionForRpc?> eth_getTransactionByHash(Hash256 transactionHash)
{
(TxReceipt? receipt, Transaction? transaction, UInt256? baseFee) = _blockchainBridge.GetTransaction(transactionHash, checkTxnPool: true);
if (transaction is null)
{
return Task.FromResult(ResultWrapper<OptimismTransactionForRpc?>.Success(null!));
return ResultWrapper<OptimismTransactionForRpc?>.Success(null);
}

RecoverTxSenderIfNeeded(transaction);
OptimismTransactionForRpc transactionModel = new(receipt?.BlockHash, receipt as OptimismTxReceipt, transaction, baseFee);
if (_logger.IsTrace) _logger.Trace($"eth_getTransactionByHash request {transactionHash}, result: {transactionModel.Hash}");
return Task.FromResult(ResultWrapper<OptimismTransactionForRpc?>.Success(transactionModel));
return ResultWrapper<OptimismTransactionForRpc?>.Success(transactionModel);
}

public new ResultWrapper<OptimismTransactionForRpc?> eth_getTransactionByBlockHashAndIndex(Hash256 blockHash,
Expand Down