Skip to content

Commit 49b68f1

Browse files
committed
2 parents e147def + 53c0d57 commit 49b68f1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcServiceTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ public void GetBlockByNumberTest()
7272
Assert.AreEqual((BigInteger)2, (response.Result as BlockForRpc)?.Number);
7373
}
7474

75+
[Test]
76+
public void Eth_module_populates_size_when_returning_block_data()
77+
{
78+
IEthModule ethModule = Substitute.For<IEthModule>();
79+
ethModule.eth_getBlockByNumber(Arg.Any<BlockParameter>(), true).ReturnsForAnyArgs(x => ResultWrapper<BlockForRpc>.Success(new BlockForRpc(Build.A.Block.WithNumber(2).TestObject, true)));
80+
JsonRpcResponse response = TestRequest(ethModule, "eth_getBlockByNumber", "0x1b4", "true");
81+
Assert.AreEqual(513L, (response.Result as BlockForRpc)?.Size);
82+
}
83+
7584
[Test]
7685
public void CanHandleOptionalArguments()
7786
{

src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
using Nethermind.Core.Crypto;
2424
using Nethermind.Core.Encoding;
2525
using Nethermind.Core.Extensions;
26+
using Nethermind.Dirichlet.Numerics;
2627
using Nethermind.JsonRpc.Data;
2728

2829
namespace Nethermind.JsonRpc.Modules.Eth
2930
{
3031
public class BlockForRpc
3132
{
33+
private BlockDecoder _blockDecoder = new BlockDecoder();
34+
3235
public BlockForRpc(Block block, bool includeFullTransactionData)
3336
{
3437
Number = block.Number;
@@ -45,7 +48,7 @@ public BlockForRpc(Block block, bool includeFullTransactionData)
4548
Difficulty = block.Difficulty;
4649
TotalDifficulty = block.TotalDifficulty ?? 0;
4750
ExtraData = block.ExtraData;
48-
Size = BigInteger.Zero;
51+
Size = Size = _blockDecoder.GetLength(block, RlpBehaviors.None);
4952
GasLimit = block.GasLimit;
5053
GasUsed = block.GasUsed;
5154
Timestamp = block.Timestamp;
@@ -64,13 +67,13 @@ public BlockForRpc(Block block, bool includeFullTransactionData)
6467
public Keccak StateRoot { get; set; }
6568
public Keccak ReceiptsRoot { get; set; }
6669
public Address Miner { get; set; }
67-
public BigInteger Difficulty { get; set; }
68-
public BigInteger TotalDifficulty { get; set; }
70+
public UInt256 Difficulty { get; set; }
71+
public UInt256 TotalDifficulty { get; set; }
6972
public byte[] ExtraData { get; set; }
70-
public BigInteger Size { get; set; }
71-
public BigInteger GasLimit { get; set; }
72-
public BigInteger GasUsed { get; set; }
73-
public BigInteger Timestamp { get; set; }
73+
public long Size { get; set; }
74+
public long GasLimit { get; set; }
75+
public long GasUsed { get; set; }
76+
public UInt256 Timestamp { get; set; }
7477
public IEnumerable<object> Transactions { get; set; }
7578
public IEnumerable<Keccak> Uncles { get; set; }
7679
}

0 commit comments

Comments
 (0)