oasis_core_runtime/transaction/
context.rs

1//! Runtime call context.
2use std::sync::Arc;
3
4use crate::{
5    consensus::{
6        beacon::EpochTime,
7        roothash::{Header, RoundResults},
8        state::ConsensusState,
9        LightBlock,
10    },
11    protocol::Protocol,
12    storage::MKVS,
13};
14
15/// Transaction context.
16pub struct Context<'a> {
17    /// Low-level access to the underlying Runtime Host Protocol.
18    pub protocol: Arc<Protocol>,
19    /// Consensus light block.
20    pub consensus_block: &'a LightBlock,
21    /// Consensus state tree.
22    pub consensus_state: ConsensusState,
23    /// Runtime state.
24    pub runtime_state: &'a mut dyn MKVS,
25    /// The block header accompanying this transaction.
26    pub header: &'a Header,
27    /// Epoch corresponding to the currently processed block.
28    pub epoch: EpochTime,
29    /// Results of processing the previous successful round.
30    pub round_results: &'a RoundResults,
31    /// The maximum number of messages that can be emitted in this round.
32    pub max_messages: u32,
33    /// Flag indicating whether to only perform transaction check rather than
34    /// running the transaction.
35    pub check_only: bool,
36}
37
38impl<'a> Context<'a> {
39    /// Construct new transaction context.
40    #[allow(clippy::too_many_arguments)]
41    pub fn new(
42        protocol: Arc<Protocol>,
43        consensus_block: &'a LightBlock,
44        consensus_state: ConsensusState,
45        runtime_state: &'a mut dyn MKVS,
46        header: &'a Header,
47        epoch: EpochTime,
48        round_results: &'a RoundResults,
49        max_messages: u32,
50        check_only: bool,
51    ) -> Self {
52        Self {
53            protocol,
54            consensus_block,
55            consensus_state,
56            runtime_state,
57            header,
58            epoch,
59            round_results,
60            max_messages,
61            check_only,
62        }
63    }
64}