diem_state_view/lib.rs
1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8#![forbid(unsafe_code)]
9
10//! This crate defines [`trait StateView`](StateView).
11
12use diem_crypto::HashValue;
13use diem_types::term_state::PosState;
14
15/// A read-only snapshot of the global PoS state, passed to the VM for
16/// transaction execution.
17pub trait StateView: Sync {
18 /// For logging and debugging purpose, identifies what this view is
19 /// for.
20 fn id(&self) -> StateViewId { StateViewId::Miscellaneous }
21
22 /// Returns the PoS state for this view.
23 fn pos_state(&self) -> &PosState;
24}
25
26#[derive(Copy, Clone)]
27pub enum StateViewId {
28 /// Executor applying a block.
29 BlockExecution { block_id: HashValue },
30 /// For test, db-bootstrapper, etc.
31 Miscellaneous,
32}