1#![cfg_attr(not(feature = "std"), no_std)]
3
4use domain_runtime_primitives::{maximum_domain_block_weight, Balance, EthereumAccountId};
5use frame_support::parameter_types;
6use frame_support::sp_runtime::app_crypto::sp_core::U256;
7use frame_support::sp_runtime::Perbill;
8use parity_scale_codec::{Decode, Encode};
9use sp_domains::PermissionedActionAllowedBy;
10#[cfg(feature = "std")]
11use sp_inherents::{Error, InherentData};
12use sp_inherents::{InherentIdentifier, IsFatalError};
13use sp_weights::constants::WEIGHT_REF_TIME_PER_SECOND;
14use sp_weights::Weight;
15
16pub const GAS_PER_SECOND: u64 = 40_000_000;
19
20pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND.div_ceil(GAS_PER_SECOND);
23
24parameter_types! {
25 pub const GasLimitPovSizeRatio: u64 = 4;
26 pub const GasPerByte: Balance = 625;
30 pub const StorageFeeRatio: Perbill = Perbill::from_percent(30);
32 pub BlockGasLimit: U256 = U256::from(
34 maximum_domain_block_weight().ref_time() / WEIGHT_PER_GAS
35 );
36 pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
37}
38
39pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"dmnevmtr";
41
42#[derive(Debug, Encode)]
43#[cfg_attr(feature = "std", derive(Decode))]
44pub enum InherentError {
45 MissingRuntimeCall,
46 InvalidRuntimeCall,
47 IncorrectRuntimeCall,
48}
49
50impl IsFatalError for InherentError {
51 fn is_fatal_error(&self) -> bool {
52 true
53 }
54}
55
56#[derive(Debug, Encode, Decode)]
58pub struct InherentType {
59 pub maybe_call: Option<PermissionedActionAllowedBy<EthereumAccountId>>,
61}
62
63#[cfg(feature = "std")]
65pub struct InherentDataProvider {
66 data: InherentType,
67}
68
69#[cfg(feature = "std")]
70impl InherentDataProvider {
71 pub fn new(maybe_call: Option<PermissionedActionAllowedBy<EthereumAccountId>>) -> Self {
73 Self {
74 data: InherentType { maybe_call },
75 }
76 }
77
78 pub fn data(&self) -> &InherentType {
80 &self.data
81 }
82}
83
84#[cfg(feature = "std")]
85#[async_trait::async_trait]
86impl sp_inherents::InherentDataProvider for InherentDataProvider {
87 async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
88 inherent_data.put_data(INHERENT_IDENTIFIER, &self.data)
89 }
90
91 async fn try_handle_error(
92 &self,
93 identifier: &InherentIdentifier,
94 error: &[u8],
95 ) -> Option<Result<(), Error>> {
96 if *identifier != INHERENT_IDENTIFIER {
97 return None;
98 }
99
100 let error = InherentError::decode(&mut &*error).ok()?;
101
102 Some(Err(Error::Application(Box::from(format!("{error:?}")))))
103 }
104}
105
106sp_api::decl_runtime_apis! {
107 pub trait EvmTrackerApi {
109 fn construct_evm_contract_creation_allowed_by_extrinsic(decoded_argument: PermissionedActionAllowedBy<EthereumAccountId>) -> Block::Extrinsic;
111 }
112}