1use crate::crypto::KeyTypeId;
21
22pub const ED25519: KeyTypeId = KeyTypeId(*b"ed25");
24pub const SR25519: KeyTypeId = KeyTypeId(*b"sr25");
26pub const ECDSA: KeyTypeId = KeyTypeId(*b"ecds");
28pub const BANDERSNATCH: KeyTypeId = KeyTypeId(*b"band");
30pub const BLS377: KeyTypeId = KeyTypeId(*b"bls7");
32pub const BLS381: KeyTypeId = KeyTypeId(*b"bls8");
34pub const ECDSA_BLS377: KeyTypeId = KeyTypeId(*b"ecb7");
36pub const ECDSA_BLS381: KeyTypeId = KeyTypeId(*b"ecb8");
38
39#[macro_export]
64macro_rules! wasm_export_functions {
65 (
66 $(
67 fn $name:ident (
68 $( $arg_name:ident: $arg_ty:ty ),* $(,)?
69 ) $( -> $ret_ty:ty )? { $( $fn_impl:tt )* }
70 )*
71 ) => {
72 $(
73 $crate::wasm_export_functions! {
74 @IMPL
75 fn $name (
76 $( $arg_name: $arg_ty ),*
77 ) $( -> $ret_ty )? { $( $fn_impl )* }
78 }
79 )*
80 };
81 (@IMPL
82 fn $name:ident (
83 $( $arg_name:ident: $arg_ty:ty ),*
84 ) { $( $fn_impl:tt )* }
85 ) => {
86 #[no_mangle]
87 #[allow(unreachable_code)]
88 #[cfg(not(feature = "std"))]
89 pub fn $name(input_data: *mut u8, input_len: usize) -> u64 {
90 let input: &[u8] = if input_len == 0 {
91 &[0u8; 0]
92 } else {
93 unsafe {
94 ::core::slice::from_raw_parts(input_data, input_len)
95 }
96 };
97
98 {
99 let ($( $arg_name ),*) : ($( $arg_ty ),*) = $crate::Decode::decode(
100 &mut &input[..],
101 ).expect("Input data is correctly encoded");
102
103 (|| { $( $fn_impl )* })()
104 }
105
106 $crate::to_substrate_wasm_fn_return_value(&())
107 }
108 };
109 (@IMPL
110 fn $name:ident (
111 $( $arg_name:ident: $arg_ty:ty ),*
112 ) $( -> $ret_ty:ty )? { $( $fn_impl:tt )* }
113 ) => {
114 #[no_mangle]
115 #[allow(unreachable_code)]
116 #[cfg(not(feature = "std"))]
117 pub fn $name(input_data: *mut u8, input_len: usize) -> u64 {
118 let input: &[u8] = if input_len == 0 {
119 &[0u8; 0]
120 } else {
121 unsafe {
122 ::core::slice::from_raw_parts(input_data, input_len)
123 }
124 };
125
126 let output $( : $ret_ty )? = {
127 let ($( $arg_name ),*) : ($( $arg_ty ),*) = $crate::Decode::decode(
128 &mut &input[..],
129 ).expect("Input data is correctly encoded");
130
131 (|| { $( $fn_impl )* })()
132 };
133
134 $crate::to_substrate_wasm_fn_return_value(&output)
135 }
136 };
137}
138
139#[cfg(feature = "std")]
144#[derive(Clone)]
145pub struct TaskExecutor(futures::executor::ThreadPool);
146
147#[cfg(feature = "std")]
148impl TaskExecutor {
149 pub fn new() -> Self {
151 let mut builder = futures::executor::ThreadPoolBuilder::new();
152 Self(builder.pool_size(8).create().expect("Failed to create thread pool"))
153 }
154}
155
156#[cfg(feature = "std")]
157impl Default for TaskExecutor {
158 fn default() -> Self {
159 Self::new()
160 }
161}
162
163#[cfg(feature = "std")]
164impl crate::traits::SpawnNamed for TaskExecutor {
165 fn spawn_blocking(
166 &self,
167 _name: &'static str,
168 _group: Option<&'static str>,
169 future: futures::future::BoxFuture<'static, ()>,
170 ) {
171 self.0.spawn_ok(future);
172 }
173 fn spawn(
174 &self,
175 _name: &'static str,
176 _group: Option<&'static str>,
177 future: futures::future::BoxFuture<'static, ()>,
178 ) {
179 self.0.spawn_ok(future);
180 }
181}
182
183#[cfg(feature = "std")]
184impl crate::traits::SpawnEssentialNamed for TaskExecutor {
185 fn spawn_essential_blocking(
186 &self,
187 _: &'static str,
188 _: Option<&'static str>,
189 future: futures::future::BoxFuture<'static, ()>,
190 ) {
191 self.0.spawn_ok(future);
192 }
193 fn spawn_essential(
194 &self,
195 _: &'static str,
196 _: Option<&'static str>,
197 future: futures::future::BoxFuture<'static, ()>,
198 ) {
199 self.0.spawn_ok(future);
200 }
201}