Skip to content

Commit

Permalink
fix receipts serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria committed Oct 14, 2022
1 parent dd198ef commit 3e0c07d
Showing 1 changed file with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -36,17 +36,36 @@ public ReceiptsMessageSerializer(ISpecProvider specProvider)

public void Serialize(IByteBuffer byteBuffer, ReceiptsMessage message)
{
Rlp rlp = Rlp.Encode(message.TxReceipts.Select(
b => b == null
? Rlp.OfEmptySequence
: Rlp.Encode(
b.Select(
n => n == null
? Rlp.OfEmptySequence
: _decoder.Encode(n, _specProvider.GetSpec(n.BlockNumber).IsEip658Enabled ? RlpBehaviors.Eip658Receipts : RlpBehaviors.None)).ToArray())).ToArray());
int totalLength = GetLength(message, out int contentLength);

RlpStream rlpStream = new NettyRlpStream(byteBuffer);
rlpStream.Encode(rlp);
byteBuffer.EnsureWritable(totalLength, true);
NettyRlpStream stream = new(byteBuffer);
stream.StartSequence(contentLength);

foreach (TxReceipt?[]? txReceipts in message.TxReceipts)
{
if (txReceipts is null)
{
stream.Encode(Rlp.OfEmptySequence);
continue;
}

foreach (TxReceipt? txReceipt in txReceipts)
{
if (txReceipt is null)
{
stream.Encode(Rlp.OfEmptySequence);
continue;
}

_decoder.Encode(stream, txReceipt,
_specProvider.GetSpec(txReceipt.BlockNumber).IsEip658Enabled
? RlpBehaviors.Eip658Receipts
: RlpBehaviors.None);
}


}
}

public ReceiptsMessage Deserialize(IByteBuffer byteBuffer)
Expand Down

0 comments on commit 3e0c07d

Please sign in to comment.