sp_domains/
core_api.rs

1#[cfg(not(feature = "std"))]
2extern crate alloc;
3
4use crate::{BlockFees, DomainAllowlistUpdates, Transfers};
5#[cfg(not(feature = "std"))]
6use alloc::vec::Vec;
7use domain_runtime_primitives::{
8    opaque, Balance, CheckExtrinsicsValidityError, DecodeExtrinsicError,
9};
10use sp_runtime::generic::Era;
11use sp_runtime::traits::{Block as BlockT, NumberFor};
12use sp_runtime::Digest;
13use sp_weights::Weight;
14use subspace_core_primitives::U256;
15use subspace_runtime_primitives::Moment;
16
17sp_api::decl_runtime_apis! {
18    /// Base API that every domain runtime must implement.
19    pub trait DomainCoreApi {
20        /// Extracts the optional signer per extrinsic.
21        fn extract_signer(
22            extrinsics: Vec<<Block as BlockT>::Extrinsic>,
23        ) -> Vec<(Option<opaque::AccountId>, Block::Extrinsic)>;
24
25        fn is_within_tx_range(
26            extrinsic: &Block::Extrinsic,
27            bundle_vrf_hash: &U256,
28            tx_range: &U256,
29        ) -> bool;
30
31        /// Returns the storage root after initializing the block.
32        fn initialize_block_with_post_state_root(header: &Block::Header) -> Vec<u8>;
33
34        /// Returns the storage root after applying the extrinsic.
35        fn apply_extrinsic_with_post_state_root(extrinsic: Block::Extrinsic) -> Vec<u8>;
36
37        /// Returns an encoded extrinsic aiming to upgrade the runtime using given code.
38        fn construct_set_code_extrinsic(code: Vec<u8>) -> Vec<u8>;
39
40        /// Returns an encoded extrinsic to set timestamp.
41        fn construct_timestamp_extrinsic(moment: Moment) -> Block::Extrinsic;
42
43        /// Returns an encoded extrinsic to set domain transaction byte fee.
44        fn construct_consensus_chain_byte_fee_extrinsic(consensus_chain_byte_fee: Balance) -> Block::Extrinsic;
45
46        /// Returns an extrinsic to update chain allowlist.
47        fn construct_domain_update_chain_allowlist_extrinsic(updates: DomainAllowlistUpdates) -> Block::Extrinsic;
48
49        /// Returns true if the extrinsic is an inherent extrinsic.
50        fn is_inherent_extrinsic(extrinsic: &Block::Extrinsic) -> bool;
51
52        /// Checks the validity of array of extrinsics + pre_dispatch
53        /// returning failure on first extrinsic that fails runtime call.
54        /// IMPORTANT: Change `CHECK_EXTRINSICS_AND_DO_PRE_DISPATCH_METHOD_NAME` constant when this method name is changed
55        fn check_extrinsics_and_do_pre_dispatch(uxts: Vec<Block::Extrinsic>, block_number: NumberFor<Block>,
56            block_hash: Block::Hash) -> Result<(), CheckExtrinsicsValidityError>;
57
58        /// Decodes the domain specific extrinsic from the opaque extrinsic.
59        fn decode_extrinsic(
60            opaque_extrinsic: sp_runtime::OpaqueExtrinsic,
61        ) -> Result<Block::Extrinsic, DecodeExtrinsicError>;
62
63        /// Returns extrinsic Era if present.
64        fn extrinsic_era(
65          extrinsic: &Block::Extrinsic
66        ) -> Option<Era>;
67
68        /// Returns the extrinsic weight.
69        fn extrinsic_weight(ext: &Block::Extrinsic) -> Weight;
70
71        /// The accumulated transaction fee of all transactions included in the block.
72        fn block_fees() -> BlockFees<Balance>;
73
74        /// Returns the block digest.
75        fn block_digest() -> Digest;
76
77        /// Returns the consumed weight of the block.
78        fn block_weight() -> Weight;
79
80        /// Returns the transfers for this domain in the block.
81        fn transfers() -> Transfers<Balance>;
82
83        /// Returns the storage key for the Transfers on Domain.
84        fn transfers_storage_key() -> Vec<u8>;
85
86        /// Returns the storage key for the `CollectedBlockFees` on Domain.
87        fn block_fees_storage_key() -> Vec<u8>;
88    }
89}