Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Add optional argument Address in parity_pendingTransactions (Nethermi…
Browse files Browse the repository at this point in the history
  • Loading branch information
smartprogrammer93 authored and Andrew-Pohl committed Oct 7, 2022
1 parent 39b7b36 commit 4e5b164
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,24 @@ public async Task parity_pendingTransactions()
Assert.AreEqual(expectedResult, serialized);
}

[Test]
public async Task parity_pendingTransactions_With_Address()
{
await Task.Delay(100);
string serialized = RpcTest.TestSerializedRequest(_parityRpcModule, "parity_pendingTransactions", "0x0000000000000000000000000000000000000002");
string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[{\"hash\":\"0xd4720d1b81c70ed4478553a213a83bd2bf6988291677f5d05c6aae0b287f947e\",\"nonce\":\"0x0\",\"blockHash\":null,\"blockNumber\":null,\"transactionIndex\":null,\"from\":\"0x0000000000000000000000000000000000000002\",\"to\":\"0x0000000000000000000000000000000000000000\",\"value\":\"0x1\",\"gasPrice\":\"0x1\",\"gas\":\"0x5208\",\"input\":\"0x\",\"raw\":\"0xf85f8001825208940000000000000000000000000000000000000000018025a0ef2effb79771cbe42fc7f9cc79440b2a334eedad6e528ea45c2040789def4803a0515bdfe298808be2e07879faaeacd0ad17f3b13305b9f971647bbd5d5b584642\",\"creates\":null,\"publicKey\":\"0x15a1cc027cfd2b970c8aa2b3b22dfad04d29171109f6502d5fb5bde18afe86dddd44b9f8d561577527f096860ee03f571cc7f481ea9a14cb48cc7c20c964373a\",\"chainId\":\"0x1\",\"condition\":null,\"r\":\"0xef2effb79771cbe42fc7f9cc79440b2a334eedad6e528ea45c2040789def4803\",\"s\":\"0x515bdfe298808be2e07879faaeacd0ad17f3b13305b9f971647bbd5d5b584642\",\"v\":\"0x25\",\"standardV\":\"0x0\"}],\"id\":67}";
Assert.AreEqual(expectedResult, serialized);
}

[Test]
public async Task parity_pendingTransactions_With_Address_Empty_Result()
{
await Task.Delay(100);
string serialized = RpcTest.TestSerializedRequest(_parityRpcModule, "parity_pendingTransactions", "0x0000000000000000000000000000000000000005");
string expectedResult = "{\"jsonrpc\":\"2.0\",\"result\":[],\"id\":67}";
Assert.AreEqual(expectedResult, serialized);
}

[Test]
public void parity_getBlockReceipts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace Nethermind.JsonRpc.Modules.Parity
[RpcModule(ModuleType.Parity)]
public interface IParityRpcModule : IRpcModule
{
[JsonRpcMethod(Description = "Returns a list of transactions currently in the queue.",
[JsonRpcMethod(Description = "Returns a list of transactions currently in the queue. If address is provided, returns transactions only with given sender address.",
IsImplemented = true,
ExampleResponse = "{\"hash\":\"0x9372fe18622fd45569ef117644d4cda4af51d11bb3c72fa27690e78c9b0d7808\",\"nonce\":\"0x11b55\",\"blockHash\":null,\"blockNumber\":null,\"transactionIndex\":null,\"from\":\"0x89a3fc1d3c68f927be68d3de139980940a89fc80\",\"to\":\"0x89a3fc1d3c68f927be68d3de139980940a89fc80\",\"value\":\"0x0\",\"gasPrice\":\"0x3b9aca08\",\"gas\":\"0x7530\",\"input\":\"0x2f47e6a5c13bb151cad6f7297ceb6a197a9be6fdb3acbcfe1df3cad362525932\",\"raw\":\"0xf88683011b55843b9aca088275309489a3fc1d3c68f927be68d3de139980940a89fc8080a02f47e6a5c13bb151cad6f7297ceb6a197a9be6fdb3acbcfe1df3cad3625259322ba04cfe3030a781f8af08ebe69286a4fab707f00ce4e535c392ba8249527bdae5e5a002203d6802596ff141506437f7ae72b4391b2bdffafba45f8cb561cf5d24b456\",\"creates\":null,\"publicKey\":\"0xf409402c0b151206bb98e1031630681df4c046f0c278f920174daa14a34549fa2da52016ca659c0fe254c542fc3034c5a8da9f4d145fec6150db5ed19b4bc7ce\",\"chainId\":4,\"condition\":null,\"r\":\"0x4cfe3030a781f8af08ebe69286a4fab707f00ce4e535c392ba8249527bdae5e5\",\"s\":\"0x02203d6802596ff141506437f7ae72b4391b2bdffafba45f8cb561cf5d24b456\",\"v\":\"0x2b\",\"standardV\":\"0x0\"}, (...)")]
ResultWrapper<ParityTransaction[]> parity_pendingTransactions();
ResultWrapper<ParityTransaction[]> parity_pendingTransactions([JsonRpcParameter(ExampleValue = "[\"0x78467cada5f1883e79fcf0f3ebfa50abeec8c820\"]")] Address? address = null);

[JsonRpcMethod(Description = "Get receipts from all transactions from particular block, more efficient than fetching the receipts one-by-one.",
IsImplemented = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ public ParityRpcModule(
_peerManager = peerManager ?? throw new ArgumentNullException(nameof(peerManager));
}

public ResultWrapper<ParityTransaction[]> parity_pendingTransactions()
=> ResultWrapper<ParityTransaction[]>.Success(_txPool.GetPendingTransactions().Where(pt => pt.SenderAddress != null)
public ResultWrapper<ParityTransaction[]> parity_pendingTransactions(Address? address = null)
{
IEnumerable<Transaction> enumerable = address == null
? _txPool.GetPendingTransactions()
: _txPool.GetPendingTransactionsBySender(address);
return ResultWrapper<ParityTransaction[]>.Success(enumerable
.Select(t => new ParityTransaction(t, Rlp.Encode(t).Bytes,
t.IsSigned ? _ecdsa.RecoverPublicKey(t.Signature, t.Hash) : null)).ToArray());
t.IsSigned ? _ecdsa.RecoverPublicKey(t.Signature, t.Hash) : null)).ToArray());
}

public ResultWrapper<ReceiptForRpc[]> parity_getBlockReceipts(BlockParameter blockParameter)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Nethermind/Nethermind.TxPool/ITxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public interface ITxPool
/// </summary>
/// <returns></returns>
IDictionary<Address, Transaction[]> GetPendingTransactionsBySender();

/// <summary>
/// from a specific sender, sorted by nonce and later tx pool sorting
/// </summary>
/// <returns></returns>
Transaction[] GetPendingTransactionsBySender(Address address);
void AddPeer(ITxPoolPeer peer);
void RemovePeer(PublicKey nodeId);
AcceptTxResult SubmitTx(Transaction tx, TxHandlingOptions handlingOptions);
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.TxPool/NullTxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ private NullTxPool() { }

public Transaction[] GetOwnPendingTransactions() => Array.Empty<Transaction>();

public Transaction[] GetPendingTransactionsBySender(Address address) => Array.Empty<Transaction>();

public IDictionary<Address, Transaction[]> GetPendingTransactionsBySender() => new Dictionary<Address, Transaction[]>();

public void AddPeer(ITxPoolPeer peer) { }
Expand All @@ -55,6 +57,7 @@ public bool TryGetPendingTransaction(Keccak hash, out Transaction? transaction)
public UInt256 ReserveOwnTransactionNonce(Address address) => UInt256.Zero;
public UInt256 GetLatestPendingNonce(Address address) => 0;


public event EventHandler<TxEventArgs> NewDiscovered
{
add { }
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.TxPool/TxPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public TxPool(
public IDictionary<Address, Transaction[]> GetPendingTransactionsBySender() =>
_transactions.GetBucketSnapshot();

public Transaction[] GetPendingTransactionsBySender(Address address) =>
_transactions.GetBucketSnapshot(address);

internal Transaction[] GetOwnPendingTransactions() => _broadcaster.GetSnapshot();

private void OnHeadChange(object? sender, BlockReplacementEventArgs e)
Expand Down

0 comments on commit 4e5b164

Please sign in to comment.