-
Notifications
You must be signed in to change notification settings - Fork 437
/
GetPayloadBodiesV1Handler.cs
55 lines (50 loc) · 2.06 KB
/
GetPayloadBodiesV1Handler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 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/>.
//
using System.Collections.Generic;
using System.Threading.Tasks;
using Nethermind.Blockchain;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.JsonRpc;
using Nethermind.Logging;
using Nethermind.Merge.Plugin.Data.V1;
namespace Nethermind.Merge.Plugin.Handlers.V1
{
public class GetPayloadBodiesV1Handler : IAsyncHandler<Keccak[], ExecutionPayloadBodyV1Result[]>
{
private readonly IBlockTree _blockTree;
private readonly ILogger _logger;
public GetPayloadBodiesV1Handler(IBlockTree blockTree, ILogManager logManager)
{
_blockTree = blockTree;
_logger = logManager.GetClassLogger();
}
public Task<ResultWrapper<ExecutionPayloadBodyV1Result[]>> HandleAsync(Keccak[] blockHashes)
{
List<ExecutionPayloadBodyV1Result> payloadBodies = new();
foreach (Keccak hash in blockHashes)
{
Block? block = _blockTree.FindBlock(hash);
if (block is not null)
{
payloadBodies.Add(new ExecutionPayloadBodyV1Result(block.Transactions));
}
}
return Task.FromResult(ResultWrapper<ExecutionPayloadBodyV1Result[]>.Success(payloadBodies.ToArray()));
}
}
}