forked from NethermindEth/nethermind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecificBlockReadOnlyStateProvider.cs
More file actions
38 lines (29 loc) · 1.54 KB
/
SpecificBlockReadOnlyStateProvider.cs
File metadata and controls
38 lines (29 loc) · 1.54 KB
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
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using System.Runtime.CompilerServices;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Evm.State;
using Nethermind.State;
namespace Nethermind.Blockchain
{
public class SpecificBlockReadOnlyStateProvider(IStateReader stateReader, BlockHeader? baseBlock) : IReadOnlyStateProvider
{
private readonly IStateReader _stateReader = stateReader ?? throw new ArgumentNullException(nameof(stateReader));
public Hash256 StateRoot => BaseBlock?.StateRoot ?? Keccak.EmptyTreeHash;
public virtual BlockHeader? BaseBlock { get; } = baseBlock;
public bool TryGetAccount(Address address, out AccountStruct account) => _stateReader.TryGetAccount(BaseBlock, address, out account);
public bool IsContract(Address address) => TryGetAccount(address, out AccountStruct account) && account.IsContract;
[SkipLocalsInit]
public byte[]? GetCode(Address address)
{
TryGetAccount(address, out AccountStruct account);
return !account.HasCode ? [] : _stateReader.GetCode(account.CodeHash);
}
public byte[]? GetCode(in ValueHash256 codeHash) => _stateReader.GetCode(in codeHash);
public bool AccountExists(Address address) => _stateReader.TryGetAccount(BaseBlock, address, out _);
[SkipLocalsInit]
public bool IsDeadAccount(Address address) => !TryGetAccount(address, out AccountStruct account) || account.IsEmpty;
}
}