cfx_executor/internal_contract/contracts/
mod.rs

1// Copyright 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
5mod admin;
6mod context;
7pub(super) mod cross_space;
8mod future;
9pub(super) mod params_control;
10pub(super) mod pos;
11mod sponsor;
12mod staking;
13pub(super) mod system_storage;
14
15mod preludes {
16    pub(super) use keccak_hash::keccak;
17    #[cfg(test)]
18    pub(super) use rustc_hex::FromHex;
19
20    pub(super) use cfx_statedb::Result as DbResult;
21    pub(super) use cfx_types::{Address, H256};
22    pub(super) use primitives::BlockNumber;
23    pub(super) use sha3_macro::keccak;
24
25    #[cfg(test)]
26    pub(super) use crate::{check_event_signature, check_func_signature};
27    pub(super) use crate::{
28        group_impl_is_active, impl_function_type, make_function_table,
29        make_solidity_contract, make_solidity_event, make_solidity_function,
30        spec::CommonParams,
31    };
32    pub(super) use cfx_vm_types::{self as vm, ActionParams, Spec};
33
34    pub(super) use super::super::components::{
35        activation::IsActive,
36        context::InternalRefContext,
37        contract::{InternalContractTrait, SolFnTable},
38        event::SolidityEventTrait,
39        function::{
40            ExecutionTrait, InterfaceTrait, PreExecCheckConfTrait,
41            SimpleExecutionTrait, SolidityFunctionTrait, UpfrontPaymentTrait,
42        },
43        trap_result::InternalTrapResult,
44    };
45}
46
47/// All Built-in contracts. All these addresses will be initialized as an
48/// internal contract in the genesis block of test mode.
49pub fn all_internal_contracts() -> Vec<Box<dyn super::InternalContractTrait>> {
50    vec![
51        Box::new(admin::AdminControl::instance()),
52        Box::new(staking::Staking::instance()),
53        Box::new(sponsor::SponsorWhitelistControl::instance()),
54        Box::new(context::Context::instance()),
55        Box::new(pos::PoSRegister::instance()),
56        Box::new(cross_space::CrossSpaceCall::instance()),
57        Box::new(params_control::ParamsControl::instance()),
58        Box::new(system_storage::SystemStorage::instance()),
59        Box::new(future::Reserved3::instance()),
60        Box::new(future::Reserved8::instance()),
61        Box::new(future::Reserved9::instance()),
62        Box::new(future::Reserved11::instance()),
63    ]
64}
65
66use crate::state::State;
67use cfx_statedb::Result as DbResult;
68use cfx_types::{Address, AddressSpaceUtil, U256};
69use primitives::storage::STORAGE_LAYOUT_REGULAR_V0;
70
71pub fn initialize_internal_contract_accounts(
72    state: &mut State, addresses: &[Address],
73) -> DbResult<()> {
74    for address in addresses {
75        state.new_contract_with_admin(
76            &address.with_native_space(),
77            /* No admin; admin = */ &Address::zero(),
78            /* balance = */ U256::zero(),
79            Some(STORAGE_LAYOUT_REGULAR_V0),
80            false,
81        )?;
82    }
83    Ok(())
84}