1#![cfg_attr(not(feature = "std"), no_std)]
4
5extern crate alloc;
6
7#[doc(hidden)]
8#[cfg(not(feature = "std"))]
9pub use core::{
10 clone::Clone,
11 cmp::{Eq, PartialEq},
12 fmt,
13 fmt::Debug,
14 option::Option,
15 prelude::rust_2021::derive,
16 result::Result,
17};
18
19#[doc(hidden)]
20pub use scale::{Decode, Encode, MaxEncodedLen};
21
22#[doc(hidden)]
23#[cfg(not(feature = "std"))]
24pub use alloc::vec::Vec;
25#[doc(hidden)]
26pub use bounded_collections::BoundedVec;
27#[doc(hidden)]
28#[cfg(feature = "std")]
29pub use std::vec::Vec;
30
31mod fixed_vec;
32mod simple;
33mod simple_result_code;
34mod types;
35mod vec_map;
36mod vec_set;
37
38mod opaque;
39
40pub use fixed_vec::{BoundedMap, FixedVec};
41pub use simple::{
42 auth_queue_len, basic_piece_len, basic_piece_points, max_dependencies, max_exports,
43 max_extrinsics, max_imports, max_input, max_work_items, min_turnaround_period,
44 pieces_per_segment, segment_len, segment_slice_len, val_count, AuthOutput, AuthParam,
45 AuthQueue, AuthQueueLen, Authorization, AuthorizerHash, Balance, CodeHash, CoreIndex,
46 ExtrinsicHash, Hash, HeaderHash, MaxImports, MaxWorkItems, Memo, OpaqueBandersnatchPublic,
47 OpaqueEd25519Public, OpaqueValidatorMetadata, Parameters, PayloadHash, Segment, SegmentHash,
48 SegmentLen, SegmentSliceLen, SegmentTreeRoot, ServiceId, SignedGas, Slot, ValCount, ValIndex,
49 WorkOutput, WorkPackageHash, WorkPayload, JAM_COMMON_ERA, MEMO_LEN, POINT_LEN, SEGMENT_LEN,
50};
51pub use vec_map::{MapLike, VecMap};
52pub use vec_set::{SetLike, VecSet};
53
54pub use types::{
55 AccumulateItem, Authorizer, ExtrinsicSpec, ImportSpec, OpaqueValKeyset, OpaqueValKeysets,
56 RefineContext, RootIdentifier, ServiceInfo, TransferRecord, WorkItem, WorkItemImportsVec,
57 WorkPackage,
58};
59
60#[doc(hidden)]
61pub use simple::{
62 AccumulateRootHash, AnyHash, AnyVec, Bundle, Code, DoubleBalance, DoubleGas, MerkleNodeHash,
63 MmrPeakHash, StateRootHash, UnsignedGas, ValSuperMajority, WorkReportHash,
64};
65
66#[doc(hidden)]
68pub mod hex;
69
70#[doc(hidden)]
72pub use simple_result_code::{InvokeOutcomeCode, SimpleResult, SimpleResultCode, LOWEST_ERROR};
73
74#[doc(hidden)]
77pub use types::{
78 AccumulateParams, OnTransferParams, OnTransferParamsRef, RefineLoad, RefineParams,
79 RefineParamsRef, WorkError, WorkItems, WorkResult,
80};
81
82mod pvm;
83pub use pvm::*;
84
85pub use bounded_collections::Get;
86
87pub trait ToAtomic {
88 type Atomic: atomic_traits::Atomic;
89}
90macro_rules! impl_to_atomic {
91 ($t:ty, $atomic:ty) => {
92 impl ToAtomic for $t {
93 type Atomic = $atomic;
94 }
95 };
96}
97impl_to_atomic!(u8, core::sync::atomic::AtomicU8);
98impl_to_atomic!(u16, core::sync::atomic::AtomicU16);
99impl_to_atomic!(u32, core::sync::atomic::AtomicU32);
100impl_to_atomic!(u64, core::sync::atomic::AtomicU64);
101impl_to_atomic!(usize, core::sync::atomic::AtomicUsize);
102
103#[macro_export]
104macro_rules! chain_params {
105 (atomic $atom:ident ; $init:expr ; $t:ty) => {
106 static $atom: <$t as $crate::ToAtomic>::Atomic =
107 <$t as $crate::ToAtomic>::Atomic::new($init);
108 };
109 (basic $atom:ident ; $init:expr ; $fn_vis:vis , $f:ident ; $t:tt ; $st:tt ; $(#[$($meta:meta)*])*) => {
110 chain_params! { atomic $atom; $init; $st }
111 $(#[$($meta)*])* $fn_vis fn $f() -> $t {
112 $atom.load(core::sync::atomic::Ordering::Relaxed) as $t
113 }
114 };
115 (get $struct_vis:vis , $struct_name:ident ; $f:ident ; $(#[$($meta:meta)*])*) => {
116 $(#[$($meta)*])*
117 #[derive(Copy, Clone, Eq, PartialEq, Default, Debug)]
118 $struct_vis struct $struct_name;
119 impl $crate::Get<u16> for $struct_name { fn get() -> u16 { $f() as u16 } }
120 impl $crate::Get<u32> for $struct_name { fn get() -> u32 { $f() as u32 } }
121 impl $crate::Get<u64> for $struct_name { fn get() -> u64 { $f() as u64 } }
122 impl $crate::Get<u128> for $struct_name { fn get() -> u128 { $f() as u128 } }
123 impl $crate::Get<usize> for $struct_name { fn get() -> usize { $f() as usize } }
124 };
125 (
126 $(#[$($meta:meta)*])* static $atom:ident : _ = _($init:expr);
127 $fn_vis:vis fn $f:ident() -> $t:tt;
128 $struct_vis:vis struct $struct_name:ident;
129 impl Get<_> for _ {}
130 $($rest:tt)*
131 ) => {
132 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $t ; $(#[$($meta)*])* }
133 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
134 chain_params! { $($rest)* }
135 };
136 (
137 $(#[$($meta:meta)*])* static $atom:ident : $st:tt = _($init:expr);
138 $fn_vis:vis fn $f:ident() -> $t:tt;
139 $struct_vis:vis struct $struct_name:ident;
140 impl Get<_> for _ {}
141 $($rest:tt)*
142 ) => {
143 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $st ; $(#[$($meta)*])* }
144 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
145 chain_params! { $($rest)* }
146 };
147 (
148 $(#[$($meta:meta)*])* static $atom:ident : _ = _($init:expr);
149 $fn_vis:vis fn $f:ident() -> $t:tt;
150 $($rest:tt)*
151 ) => {
152 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $t ; $(#[$($meta)*])* }
153 chain_params! { $($rest)* }
154 };
155 (
156 $(#[$($meta:meta)*])* static $atom:ident : $st:tt = _($init:expr);
157 $fn_vis:vis fn $f:ident() -> $t:tt;
158 $($rest:tt)*
159 ) => {
160 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $st ; $(#[$($meta)*])* }
161 chain_params! { $($rest)* }
162 };
163 (
164 $(#[$($meta:meta)*])* $fn_vis:vis fn $f:ident() -> $t:tt { $fx:expr }
165 $struct_vis:vis struct $struct_name:ident;
166 impl Get<_> for _ {}
167 $($rest:tt)*
168 ) => {
169 $(#[$($meta)*])* $fn_vis fn $f() -> $t { $fx }
170 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
171 chain_params! { $($rest)* }
172 };
173 (
174 $(#[$($meta:meta)*])* $const_vis:vis const $const_name:ident: _ = $cx:expr;
175 $fn_vis:vis fn $f:ident() -> $t:tt;
176 $struct_vis:vis struct $struct_name:ident;
177 impl Get<_> for _ {}
178 $($rest:tt)*
179 ) => {
180 $(#[$($meta)*])* $const_vis const $const_name: $t = $cx;
181 $(#[$($meta)*])* $fn_vis fn $f() -> $t { $const_name }
182 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
183 chain_params! { $($rest)* }
184 };
185 () => {}
186}