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
56
57
58
59
60
61
62
63
64
//! Runtime call context.
use std::sync::Arc;

use crate::{
    consensus::{
        beacon::EpochTime,
        roothash::{Header, RoundResults},
        state::ConsensusState,
        LightBlock,
    },
    protocol::Protocol,
    storage::MKVS,
};

/// Transaction context.
pub struct Context<'a> {
    /// Low-level access to the underlying Runtime Host Protocol.
    pub protocol: Arc<Protocol>,
    /// Consensus light block.
    pub consensus_block: &'a LightBlock,
    /// Consensus state tree.
    pub consensus_state: ConsensusState,
    /// Runtime state.
    pub runtime_state: &'a mut dyn MKVS,
    /// The block header accompanying this transaction.
    pub header: &'a Header,
    /// Epoch corresponding to the currently processed block.
    pub epoch: EpochTime,
    /// Results of processing the previous successful round.
    pub round_results: &'a RoundResults,
    /// The maximum number of messages that can be emitted in this round.
    pub max_messages: u32,
    /// Flag indicating whether to only perform transaction check rather than
    /// running the transaction.
    pub check_only: bool,
}

impl<'a> Context<'a> {
    /// Construct new transaction context.
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        protocol: Arc<Protocol>,
        consensus_block: &'a LightBlock,
        consensus_state: ConsensusState,
        runtime_state: &'a mut dyn MKVS,
        header: &'a Header,
        epoch: EpochTime,
        round_results: &'a RoundResults,
        max_messages: u32,
        check_only: bool,
    ) -> Self {
        Self {
            protocol,
            consensus_block,
            consensus_state,
            runtime_state,
            header,
            epoch,
            round_results,
            max_messages,
            check_only,
        }
    }
}