sp_domains/
core_api.rs

1#[cfg(not(feature = "std"))]
2extern crate alloc;
3
4use crate::DomainAllowlistUpdates;
5use crate::execution_receipt::{BlockFees, Transfers};
6#[cfg(not(feature = "std"))]
7use alloc::vec::Vec;
8use domain_runtime_primitives::{
9    Balance, CheckExtrinsicsValidityError, DecodeExtrinsicError, opaque,
10};
11use sp_runtime::Digest;
12use sp_runtime::generic::Era;
13use sp_runtime::traits::NumberFor;
14use sp_weights::Weight;
15use subspace_core_primitives::U256;
16use subspace_runtime_primitives::{ExtrinsicFor, Moment};
17
18sp_api::decl_runtime_apis! {
19    /// Base API that every domain runtime must implement.
20    #[api_version(2)]
21    // `allow(clippy::ptr_arg` is needed because Clippy complains to replace `&Vec<T>` with `&[T]`
22    // but the latter fails to compile.
23    #[allow(clippy::ptr_arg)]
24    pub trait DomainCoreApi {
25        /// Extracts the optional signer per extrinsic.
26        fn extract_signer(
27            extrinsics: Vec<ExtrinsicFor<Block>>,
28        ) -> Vec<(Option<opaque::AccountId>, Block::Extrinsic)>;
29
30        fn is_within_tx_range(
31            extrinsic: &Block::Extrinsic,
32            bundle_vrf_hash: &U256,
33            tx_range: &U256,
34        ) -> bool;
35
36        /// Extract signer of a given list of extrinsic if all of them are within the
37        /// tx range, otherwise return the index if the first tx not in the tx range.
38        fn extract_signer_if_all_within_tx_range(
39            extrinsic: &Vec<Block::Extrinsic>,
40            bundle_vrf_hash: &U256,
41            tx_range: &U256,
42        ) -> Result<Vec<Option<opaque::AccountId>> , u32>;
43
44        /// Returns the storage root after initializing the block.
45        fn initialize_block_with_post_state_root(header: &Block::Header) -> Vec<u8>;
46
47        /// Returns the storage root after applying the extrinsic.
48        fn apply_extrinsic_with_post_state_root(extrinsic: Block::Extrinsic) -> Vec<u8>;
49
50        /// Returns an encoded extrinsic aiming to upgrade the runtime using given code.
51        fn construct_set_code_extrinsic(code: Vec<u8>) -> Vec<u8>;
52
53        /// Returns an encoded extrinsic to set timestamp.
54        fn construct_timestamp_extrinsic(moment: Moment) -> Block::Extrinsic;
55
56        /// Returns an encoded extrinsic to set domain transaction byte fee.
57        fn construct_consensus_chain_byte_fee_extrinsic(consensus_chain_byte_fee: Balance) -> Block::Extrinsic;
58
59        /// Returns an extrinsic to update chain allowlist.
60        fn construct_domain_update_chain_allowlist_extrinsic(updates: DomainAllowlistUpdates) -> Block::Extrinsic;
61
62        /// Returns true if the extrinsic is an inherent extrinsic.
63        fn is_inherent_extrinsic(extrinsic: &Block::Extrinsic) -> bool;
64
65        /// Find the first inherent extrinsic
66        fn find_first_inherent_extrinsic(extrinsics: &Vec<Block::Extrinsic>) -> Option<u32>;
67
68        /// Checks the validity of array of extrinsics + pre_dispatch
69        /// returning failure on first extrinsic that fails runtime call.
70        /// IMPORTANT: Change `CHECK_EXTRINSICS_AND_DO_PRE_DISPATCH_METHOD_NAME` constant when this method name is changed
71        fn check_extrinsics_and_do_pre_dispatch(uxts: Vec<Block::Extrinsic>, block_number: NumberFor<Block>,
72            block_hash: Block::Hash) -> Result<(), CheckExtrinsicsValidityError>;
73
74        /// Decodes the domain specific extrinsic from the opaque extrinsic.
75        fn decode_extrinsic(
76            opaque_extrinsic: sp_runtime::OpaqueExtrinsic,
77        ) -> Result<Block::Extrinsic, DecodeExtrinsicError>;
78
79        /// Decodes a list of domain extrinsics from opaque extrinsics, returning all extrinsics
80        /// up to the first undecodable tx. (Or the full list if all are decodable.)
81        fn decode_extrinsics_prefix(
82            opaque_extrinsics: Vec<sp_runtime::OpaqueExtrinsic>,
83        ) -> Vec<Block::Extrinsic>;
84
85        /// Returns extrinsic Era if present.
86        fn extrinsic_era(
87          extrinsic: &Block::Extrinsic
88        ) -> Option<Era>;
89
90        /// Returns the extrinsic weight.
91        fn extrinsic_weight(ext: &Block::Extrinsic) -> Weight;
92
93        /// Returns the sum of a given set of extrinsics weight.
94        fn extrinsics_weight(ext: &Vec<Block::Extrinsic>) -> Weight;
95
96        /// The accumulated transaction fee of all transactions included in the block.
97        fn block_fees() -> BlockFees<Balance>;
98
99        /// Returns the block digest.
100        fn block_digest() -> Digest;
101
102        /// Returns the consumed weight of the block.
103        fn block_weight() -> Weight;
104
105        /// Returns the transfers for this domain in the block.
106        fn transfers() -> Transfers<Balance>;
107
108        /// Returns the storage key for the Transfers on Domain.
109        fn transfers_storage_key() -> Vec<u8>;
110
111        /// Returns the storage key for the `CollectedBlockFees` on Domain.
112        fn block_fees_storage_key() -> Vec<u8>;
113    }
114}