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