Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,47 @@ public void Pool_content_produces_transactions_with_ChainId()
rpcTxA!.ChainId.Should().BeNull();
rpcTxB!.ChainId.Should().Be(SomeChainId);
}

[Test]
public void Pool_contentFrom_returns_pending_and_queued_transactions_for_address()
{
Transaction txPending = Build.A.Transaction
.WithType(TxType.Legacy)
.TestObject;
Transaction txQueued = Build.A.Transaction
.WithType(TxType.Legacy)
.TestObject;

ITxPoolInfoProvider txPoolInfoProvider = Substitute.For<ITxPoolInfoProvider>();
txPoolInfoProvider.GetInfo(TestItem.AddressA).Returns(new TxPoolInfo(
pending: new()
{
{
new AddressAsKey(TestItem.AddressA), new Dictionary<ulong, Transaction>
{
{ 1, txPending }
}
}
},
queued: new()
{
{
new AddressAsKey(TestItem.AddressA), new Dictionary<ulong, Transaction>
{
{ 5, txQueued }
}
}
}
));

ISpecProvider specProvider = Substitute.For<ISpecProvider>();
TxPoolRpcModule txPoolRpcModule = new(txPoolInfoProvider, specProvider);

TxPoolContentFrom result = txPoolRpcModule.txpool_contentFrom(TestItem.AddressA).Data;

result.Pending.Should().ContainKey(1ul);
result.Pending[1ul].Should().BeOfType<LegacyTransactionForRpc>();
result.Queued.Should().ContainKey(5ul);
result.Queued[5ul].Should().BeOfType<LegacyTransactionForRpc>();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;

namespace Nethermind.JsonRpc.Modules.TxPool
{
[RpcModule(ModuleType.TxPool)]
Expand All @@ -18,5 +20,8 @@ public interface ITxPoolRpcModule : IRpcModule
IsImplemented = true,
ExampleResponse = "{\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea\":{\"20\":\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea: 0 wei + 6721975 × 140000000000 gas\",\"21\":\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea: 0 wei + 6721975 × 140000000000 gas\",\"22\":\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea: 0 wei + 6721975 × 140000000000 gas\",\"23\":\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea: 0 wei + 6700000 × 140000000000 gas\",\"24\":\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea: 0 wei + 6700000 × 140000000000 gas\",\"27\":\"0xb49928fcb10123e451cfe63aa47edcaea0f8aeea: 0 wei + 6700000 × 140000000000 gas\"},\"0xc51db3339a7603f70b347a0b9680554f777d1f3c\":{\"82\":\"0xc51db3339a7603f70b347a0b9680554f777d1f3c: 0 wei + 4500000 × 10000000000 gas\"},\"0x084dd4aefc6853253573fee9f5fcc23e849d164c\":{\"17\":\"0x084dd4aefc6853253573fee9f5fcc23e849d164c: 0 wei + 28472169 × 1000000008 gas\"}}")]
ResultWrapper<TxPoolInspection> txpool_inspect();

[JsonRpcMethod(Description = "Returns tx pool content from a specific address.", IsImplemented = true, ExampleResponse = "{\"pending\":{\"806\":{\"hash\":\"0xaf953a2d01f55cfe080c0c94150a60105e8ac3d51153058a1f03dd239dd08586\",\"nonce\":\"0x326\",\"blockHash\":null,\"blockNumber\":null,\"transactionIndex\":null,\"from\":\"0x0216d5032f356960cd3749c31ab34eeff21b3395\",\"to\":\"0x7f69a91a3cf4be60020fb58b893b7cbb65376db8\",\"value\":\"0x19a99f0cf456000\",\"gasPrice\":\"0xba43b7400\",\"gas\":\"0x5208\",\"input\":\"0x\",\"type\":\"0x0\"}},\"queued\":{}}")]
ResultWrapper<TxPoolContentFrom> txpool_contentFrom([JsonRpcParameter(ExampleValue = "0x0216d5032f356960cd3749c31ab34eeff21b3395")] Address address);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System.Collections.Generic;
using System.Linq;
using Nethermind.Core;
using Nethermind.Facade.Eth;
using Nethermind.Facade.Eth.RpcTransaction;
using Nethermind.TxPool;

namespace Nethermind.JsonRpc.Modules.TxPool
{
public class TxPoolContentFrom
{
private static readonly IReadOnlyDictionary<ulong, TransactionForRpc> _emptyDictionary = new Dictionary<ulong, TransactionForRpc>();

public TxPoolContentFrom(TxPoolInfo info, ulong chainId, Address address)
{
TransactionForRpcContext extraData = new(chainId);
Pending = info.Pending.TryGetValue(address, out var pending)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, StatelessInputGen/StatelessInputGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, StatelessInputGen/StatelessInputGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Publish Nethermind.Runner [linux-arm64]

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Publish Nethermind.Runner [linux-x64]

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Check code lint

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008) [/home/runner/work/nethermind/nethermind/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj]

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (debug, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (debug, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (4of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.History.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (3of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (1of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Era1.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (2of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Config.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.KeyStore.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Wallet.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Network.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Network.Dns.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Taiko.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.JsonRpc.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Facade.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.JsonRpc.TraceStore.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Trie.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Abi.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 20 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Mining.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)
? pending.ToDictionary(v => v.Key, v => TransactionForRpc.FromTransaction(v.Value, extraData))
: _emptyDictionary;
Queued = info.Queued.TryGetValue(address, out var queued)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, StatelessInputGen/StatelessInputGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, StatelessInputGen/StatelessInputGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Publish Nethermind.Runner [linux-arm64]

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.slnx)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Publish Nethermind.Runner [linux-x64]

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Check code lint

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008) [/home/runner/work/nethermind/nethermind/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj]

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (debug, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Build (debug, EthereumTests)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (4of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.History.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (3of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (1of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Era1.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Ethereum.Blockchain.Pyspec.Test (2of4) (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Config.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.KeyStore.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Wallet.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Network.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Network.Dns.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Taiko.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.JsonRpc.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Facade.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.JsonRpc.TraceStore.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Trie.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Abi.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.Mining.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)

Check failure on line 23 in src/Nethermind/Nethermind.JsonRpc/Modules/TxPool/TxPoolContentFrom.cs

View workflow job for this annotation

GitHub Actions / Run Nethermind.HealthChecks.Test (windows-latest)

Use explicit type instead of 'var' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0008)
? queued.ToDictionary(v => v.Key, v => TransactionForRpc.FromTransaction(v.Value, extraData))
: _emptyDictionary;
}

public IReadOnlyDictionary<ulong, TransactionForRpc> Pending { get; set; }
public IReadOnlyDictionary<ulong, TransactionForRpc> Queued { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.TxPool;

Expand Down Expand Up @@ -29,5 +30,12 @@ public ResultWrapper<TxPoolInspection> txpool_inspect()
TxPoolInfo poolInfo = txPoolInfoProvider.GetInfo();
return ResultWrapper<TxPoolInspection>.Success(new TxPoolInspection(poolInfo));
}

public ResultWrapper<TxPoolContentFrom> txpool_contentFrom(Address address)
{
TxPoolInfo poolInfo = txPoolInfoProvider.GetInfo(address);
ulong chainId = specProvider.ChainId;
return ResultWrapper<TxPoolContentFrom>.Success(new TxPoolContentFrom(poolInfo, chainId, address));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ public void Setup()
_infoProvider = new TxPoolInfoProvider(_stateReader, _txPool);
}

[Test]
public void should_return_valid_pending_and_queued_transactions_for_address()
{
uint nonce = 3;
_stateReader.GetNonce(_address).Returns(nonce);
Transaction[] transactions = GetTransactions();

_txPool.GetPendingTransactionsBySender(_address).Returns(transactions);
TxPoolInfo info = _infoProvider.GetInfo(_address);

info.Pending.Count.Should().Be(1);
info.Queued.Count.Should().Be(1);

KeyValuePair<AddressAsKey, IDictionary<ulong, Transaction>> pending = info.Pending.First();
pending.Key.Value.Should().Be(_address);
pending.Value.Count.Should().Be(3);
VerifyNonceAndTransactions(pending.Value, 3);
VerifyNonceAndTransactions(pending.Value, 4);
VerifyNonceAndTransactions(pending.Value, 5);

KeyValuePair<AddressAsKey, IDictionary<ulong, Transaction>> queued = info.Queued.First();
queued.Key.Value.Should().Be(_address);
queued.Value.Count.Should().Be(4);
VerifyNonceAndTransactions(queued.Value, 1);
VerifyNonceAndTransactions(queued.Value, 2);
VerifyNonceAndTransactions(queued.Value, 8);
VerifyNonceAndTransactions(queued.Value, 9);
}

[Test]
public void should_return_valid_pending_and_queued_transactions()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.TxPool/ITxPoolInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;

namespace Nethermind.TxPool
{
public interface ITxPoolInfoProvider
{
TxPoolInfo GetInfo();
TxPoolInfo GetInfo(Address address);
}
}
40 changes: 40 additions & 0 deletions src/Nethermind/Nethermind.TxPool/TxPoolInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;
using Nethermind.Core;
Expand All @@ -10,9 +11,48 @@ namespace Nethermind.TxPool
{
public class TxPoolInfoProvider(IAccountStateProvider accountStateProvider, ITxPool txPool) : ITxPoolInfoProvider
{
private static readonly Dictionary<AddressAsKey, IDictionary<ulong, Transaction>> _emptyAddressMap = [];

public TxPoolInfoProvider(IChainHeadInfoProvider chainHeadInfoProvider, ITxPool txPool) : this(chainHeadInfoProvider.ReadOnlyStateProvider, txPool) { }

public TxPoolInfo GetInfo(Address address)
{
Transaction[] transactions = txPool.GetPendingTransactionsBySender(address);

if (transactions.Length == 0)
return new TxPoolInfo([], []);

Array.Sort(transactions, static (a, b) => a.Nonce.CompareTo(b.Nonce));

UInt256 accountNonce = accountStateProvider.GetNonce(address);
UInt256 expectedNonce = accountNonce;
Dictionary<ulong, Transaction>? pending = null;
Dictionary<ulong, Transaction>? queued = null;

foreach (Transaction transaction in transactions)
{
ulong transactionNonce = (ulong)transaction.Nonce;
if (transaction.Nonce == expectedNonce)
{
(pending ??= new()).Add(transactionNonce, transaction);
expectedNonce = transaction.Nonce + 1;
}
else
{
(queued ??= new()).Add(transactionNonce, transaction);
}
}

Dictionary<AddressAsKey, IDictionary<ulong, Transaction>> pendingTransactions = pending is not null
? new(1) { [address] = pending }
: _emptyAddressMap;
Dictionary<AddressAsKey, IDictionary<ulong, Transaction>> queuedTransactions = queued is not null
? new(1) { [address] = queued }
: _emptyAddressMap;

return new TxPoolInfo(pendingTransactions, queuedTransactions);
}

public TxPoolInfo GetInfo()
{
// only std txs are picked here. Should we add blobs?
Expand Down
Loading