1#![cfg_attr(not(feature = "std"), no_std)]
3
4#[cfg(not(feature = "std"))]
5extern crate alloc;
6
7#[cfg(not(feature = "std"))]
8use alloc::vec::Vec;
9use parity_scale_codec::{Decode, Encode};
10#[cfg(feature = "std")]
11use sp_inherents::{Error, InherentData};
12use sp_inherents::{InherentIdentifier, IsFatalError};
13
14pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"dmnsudo_";
16
17#[derive(Debug, Encode)]
18#[cfg_attr(feature = "std", derive(Decode))]
19pub enum InherentError {
20 MissingRuntimeCall,
21 InvalidRuntimeCall,
22 IncorrectRuntimeCall,
23}
24
25impl IsFatalError for InherentError {
26 fn is_fatal_error(&self) -> bool {
27 true
28 }
29}
30
31#[derive(Debug, Encode, Decode)]
33pub struct InherentType {
34 pub maybe_call: Option<Vec<u8>>,
36}
37
38#[cfg(feature = "std")]
40pub struct InherentDataProvider {
41 data: InherentType,
42}
43
44#[cfg(feature = "std")]
45impl InherentDataProvider {
46 pub fn new(maybe_call: Option<Vec<u8>>) -> Self {
48 Self {
49 data: InherentType { maybe_call },
50 }
51 }
52
53 pub fn data(&self) -> &InherentType {
55 &self.data
56 }
57}
58
59#[cfg(feature = "std")]
60#[async_trait::async_trait]
61impl sp_inherents::InherentDataProvider for InherentDataProvider {
62 async fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> {
63 inherent_data.put_data(INHERENT_IDENTIFIER, &self.data)
64 }
65
66 async fn try_handle_error(
67 &self,
68 identifier: &InherentIdentifier,
69 error: &[u8],
70 ) -> Option<Result<(), Error>> {
71 if *identifier != INHERENT_IDENTIFIER {
72 return None;
73 }
74
75 let error = InherentError::decode(&mut &*error).ok()?;
76
77 Some(Err(Error::Application(Box::from(format!("{error:?}")))))
78 }
79}
80
81pub trait IntoRuntimeCall<RuntimeCall> {
83 fn runtime_call(call: Vec<u8>) -> RuntimeCall;
84}
85
86sp_api::decl_runtime_apis! {
87 pub trait DomainSudoApi {
89 fn is_valid_sudo_call(extrinsic: Vec<u8>) -> bool;
92
93 fn construct_domain_sudo_extrinsic(inner: Vec<u8>) -> Block::Extrinsic;
95 }
96}