cfx_vm_types/
env.rs

1// Copyright 2019-2020 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5// Copyright 2015-2018 Parity Technologies (UK) Ltd.
6// This file is part of Parity.
7
8// Parity is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// Parity is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
20
21// Copyright 2019 Conflux Foundation. All rights reserved.
22// Conflux is free software and distributed under GNU General Public License.
23// See http://www.gnu.org/licenses/
24
25//! Environment information for transaction execution.
26
27use std::collections::BTreeMap;
28
29use cfx_types::{Address, Space, SpaceMap, H256, U256};
30use primitives::BlockNumber;
31
32/// Information concerning the execution environment for a
33/// message-call/contract-creation.
34#[derive(Debug, Clone, Default)]
35pub struct Env {
36    /// Chain ID
37    pub chain_id: BTreeMap<Space, u32>,
38    /// The block number.
39    pub number: BlockNumber,
40    /// The block author.
41    pub author: Address,
42    /// The block timestamp.
43    pub timestamp: u64,
44    /// The block difficulty.
45    pub difficulty: U256,
46    /// The block gas limit.
47    pub gas_limit: U256,
48    /// The last block hash.
49    pub last_hash: H256,
50    /// The total gas used in the block following execution of the transaction.
51    pub accumulated_gas_used: U256,
52    /// The epoch height.
53    pub epoch_height: u64,
54    /// PoS view number.
55    pub pos_view: Option<u64>,
56    /// Finalized epoch number by PoS view.
57    pub finalized_epoch: Option<u64>,
58    /// The transaction_epoch_bound used to verify if a transaction has
59    /// expired.
60    pub transaction_epoch_bound: u64,
61    /// Base gas price in CIP-1559, equals to 0 if CIP-1559 has not been
62    /// activated
63    pub base_gas_price: SpaceMap<U256>,
64    /// Base gas price to miner according to in CIP-137
65    pub burnt_gas_price: SpaceMap<U256>,
66    /// Transaction hash for the executing transaction, required by CIP-152
67    pub transaction_hash: H256,
68    #[cfg(feature = "align_evm")]
69    /// Blob gas fee, required by EIP-4844 (for test only)
70    pub blob_gas_fee: U256,
71}
72
73#[cfg(test)]
74mod tests {
75    use super::*;
76
77    #[test]
78    fn it_can_be_created_as_default() {
79        let default_env = Env::default();
80
81        assert_eq!(default_env.number, 0);
82        assert_eq!(default_env.author, Address::default());
83        assert_eq!(default_env.timestamp, 0);
84        assert_eq!(default_env.difficulty, 0.into());
85        assert_eq!(default_env.gas_limit, 0.into());
86        assert_eq!(default_env.last_hash, H256::zero());
87        assert_eq!(default_env.accumulated_gas_used, 0.into());
88    }
89}