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");
28
29#[macro_export]
54macro_rules! wasm_export_functions {
55 (
56 $(
57 fn $name:ident (
58 $( $arg_name:ident: $arg_ty:ty ),* $(,)?
59 ) $( -> $ret_ty:ty )? { $( $fn_impl:tt )* }
60 )*
61 ) => {
62 $(
63 $crate::wasm_export_functions! {
64 @IMPL
65 fn $name (
66 $( $arg_name: $arg_ty ),*
67 ) $( -> $ret_ty )? { $( $fn_impl )* }
68 }
69 )*
70 };
71 (@IMPL
72 fn $name:ident (
73 $( $arg_name:ident: $arg_ty:ty ),*
74 ) { $( $fn_impl:tt )* }
75 ) => {
76 #[no_mangle]
77 #[allow(unreachable_code)]
78 #[cfg(not(feature = "std"))]
79 pub fn $name(input_data: *mut u8, input_len: usize) -> u64 {
80 let input: &[u8] = if input_len == 0 {
81 &[0u8; 0]
82 } else {
83 unsafe {
84 $crate::tetcore_std::slice::from_raw_parts(input_data, input_len)
85 }
86 };
87
88 {
89 let ($( $arg_name ),*) : ($( $arg_ty ),*) = $crate::Decode::decode(
90 &mut &input[..],
91 ).expect("Input data is correctly encoded");
92
93 $( $fn_impl )*
94 }
95
96 $crate::to_tetcore_wasm_fn_return_value(&())
97 }
98 };
99 (@IMPL
100 fn $name:ident (
101 $( $arg_name:ident: $arg_ty:ty ),*
102 ) $( -> $ret_ty:ty )? { $( $fn_impl:tt )* }
103 ) => {
104 #[no_mangle]
105 #[allow(unreachable_code)]
106 #[cfg(not(feature = "std"))]
107 pub fn $name(input_data: *mut u8, input_len: usize) -> u64 {
108 let input: &[u8] = if input_len == 0 {
109 &[0u8; 0]
110 } else {
111 unsafe {
112 $crate::tetcore_std::slice::from_raw_parts(input_data, input_len)
113 }
114 };
115
116 let output $( : $ret_ty )? = {
117 let ($( $arg_name ),*) : ($( $arg_ty ),*) = $crate::Decode::decode(
118 &mut &input[..],
119 ).expect("Input data is correctly encoded");
120
121 $( $fn_impl )*
122 };
123
124 $crate::to_tetcore_wasm_fn_return_value(&output)
125 }
126 };
127}
128
129#[cfg(feature = "std")]
134#[derive(Clone)]
135pub struct TaskExecutor(futures::executor::ThreadPool);
136
137#[cfg(feature = "std")]
138impl TaskExecutor {
139 pub fn new() -> Self {
141 let mut builder = futures::executor::ThreadPoolBuilder::new();
142 Self(builder.pool_size(8).create().expect("Failed to create thread pool"))
143 }
144}
145
146#[cfg(feature = "std")]
147impl crate::traits::SpawnNamed for TaskExecutor {
148 fn spawn_blocking(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
149 self.0.spawn_ok(future);
150 }
151 fn spawn(&self, _: &'static str, future: futures::future::BoxFuture<'static, ()>) {
152 self.0.spawn_ok(future);
153 }
154}