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 {base64, serde};
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#[cfg(feature = "bytes")]
47mod segment_bytes;
48
49#[cfg(feature = "bytes")]
50pub use segment_bytes::SegmentBytes;
51
52pub use fixed_vec::{BoundedMap, FixedVec};
53#[cfg(feature = "bytes")]
54pub use simple::AnyBytes;
55pub use simple::{
56 auth_queue_len, availability_timeout, basic_piece_len, basic_piece_points, block_gas_limit,
57 core_count, deposit_per_account, deposit_per_byte, deposit_per_item, epoch_period,
58 epoch_tail_start, max_accumulate_gas, max_authorizer_code_size, max_dependencies,
59 max_export_segments, max_exports, max_extrinsics, max_import_segments, max_imports, max_input,
60 max_is_authorized_gas, max_lookup_anchor_age, max_refine_gas, max_report_elective_data,
61 max_service_code_size, max_tickets_per_block, max_work_items, min_turnaround_period,
62 pieces_per_segment, recent_block_count, rotation_period, segment_len, segment_slice_len,
63 slot_period_sec, tickets_attempts_number, val_count, AuthConfig, AuthQueue, AuthQueueLen,
64 AuthTrace, AuthWindow, Authorization, AuthorizerHash, Balance, CodeHash, CoreCount, CoreIndex,
65 EpochPeriod, ExtrinsicHash, Hash, HeaderHash, MaxDependencies, MaxExportSegments,
66 MaxExtrinsics, MaxImportSegments, MaxImports, MaxTicketsPerBlock, MaxWorkItems, Memo,
67 OpaqueBandersnatchPublic, OpaqueBlsPublic, OpaqueEd25519Public, OpaqueValidatorMetadata,
68 PayloadHash, ProtocolParameters, RecentBlockCount, Segment, SegmentHash, SegmentLen,
69 SegmentSliceLen, SegmentTreeRoot, ServiceId, SignedGas, Slot, TicketAttempt,
70 TicketsAttemptsNumber, ToAny, ValCount, ValIndex, WorkOutput, WorkPackageHash, WorkPayload,
71 GP_VERSION, JAM_COMMON_ERA, MEMO_LEN, PAGE_SIZE, POINT_LEN, PROVEN_PER_SEGMENT, SEGMENT_LEN,
72 VALS_PER_CORE,
73};
74pub use vec_map::{MapLike, VecMap};
75pub use vec_set::{SetLike, VecSet};
76
77pub use types::{
78 AccumulateItem, Authorizer, ExtrinsicSpec, FetchKind, ImportSpec, NoWrap, OpaqueValKeyset,
79 OpaqueValKeysets, PageMode, PageOperation, RefineContext, RootIdentifier, ServiceInfo,
80 TransferRecord, WorkItem, WorkItemImportsVec, WorkItemRecord, WorkItemSummary, WorkPackage,
81 Wrap, WrappedWorkPackage,
82};
83
84#[doc(hidden)]
85pub use simple::{
86 AccumulateRootHash, AnyHash, AnyVec, Code, DoubleBalance, DoubleGas, MerkleNodeHash,
87 MmrPeakHash, StateRootHash, UnsignedGas, ValSuperMajority, WorkReportHash,
88 MAX_PREIMAGE_BLOB_LEN, MAX_PREIMAGE_LEN,
89};
90
91#[doc(hidden)]
93pub mod hex;
94
95#[doc(hidden)]
97pub use simple_result_code::{InvokeOutcomeCode, SimpleResult, SimpleResultCode, LOWEST_ERROR};
98
99#[doc(hidden)]
102pub use types::{
103 AccumulateParams, IsAuthorizedParams, RefineLoad, RefineParams, RefineParamsRef, WorkDigest,
104 WorkError, WorkItems,
105};
106
107mod pvm;
108pub use pvm::*;
109
110pub use bounded_collections::Get;
111
112pub trait ToAtomic {
113 type Atomic: atomic_traits::Atomic;
114}
115macro_rules! impl_to_atomic {
116 ($t:ty, $atomic:ty) => {
117 impl ToAtomic for $t {
118 type Atomic = $atomic;
119 }
120 };
121}
122impl_to_atomic!(u8, core::sync::atomic::AtomicU8);
123impl_to_atomic!(u16, core::sync::atomic::AtomicU16);
124impl_to_atomic!(u32, core::sync::atomic::AtomicU32);
125impl_to_atomic!(u64, core::sync::atomic::AtomicU64);
126impl_to_atomic!(usize, core::sync::atomic::AtomicUsize);
127
128#[macro_export]
129macro_rules! chain_params {
130 (atomic $atom:ident ; $init:expr ; $t:ty) => {
131 static $atom: <$t as $crate::ToAtomic>::Atomic =
132 <$t as $crate::ToAtomic>::Atomic::new($init);
133 };
134 (basic $atom:ident ; $init:expr ; $fn_vis:vis , $f:ident ; $t:tt ; $st:tt ; $(#[$($meta:meta)*])*) => {
135 chain_params! { atomic $atom; $init; $st }
136 $(#[$($meta)*])* $fn_vis fn $f() -> $t {
137 $atom.load(core::sync::atomic::Ordering::Relaxed) as $t
138 }
139 };
140 (get $struct_vis:vis , $struct_name:ident ; $f:ident ; $(#[$($meta:meta)*])*) => {
141 $(#[$($meta)*])*
142 #[derive(Copy, Clone, Eq, PartialEq, Default, Debug)]
143 $struct_vis struct $struct_name;
144 impl $crate::Get<u16> for $struct_name { fn get() -> u16 { $f() as u16 } }
145 impl $crate::Get<u32> for $struct_name { fn get() -> u32 { $f() as u32 } }
146 impl $crate::Get<u64> for $struct_name { fn get() -> u64 { $f() as u64 } }
147 impl $crate::Get<u128> for $struct_name { fn get() -> u128 { $f() as u128 } }
148 impl $crate::Get<usize> for $struct_name { fn get() -> usize { $f() as usize } }
149 };
150 (
151 $(#[$($meta:meta)*])* static $atom:ident : _ = _($init:expr);
152 $fn_vis:vis fn $f:ident() -> $t:tt;
153 $struct_vis:vis struct $struct_name:ident;
154 impl Get<_> for _ {}
155 $($rest:tt)*
156 ) => {
157 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $t ; $(#[$($meta)*])* }
158 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
159 chain_params! { $($rest)* }
160 };
161 (
162 $(#[$($meta:meta)*])* static $atom:ident : $st:tt = _($init:expr);
163 $fn_vis:vis fn $f:ident() -> $t:tt;
164 $struct_vis:vis struct $struct_name:ident;
165 impl Get<_> for _ {}
166 $($rest:tt)*
167 ) => {
168 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $st ; $(#[$($meta)*])* }
169 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
170 chain_params! { $($rest)* }
171 };
172 (
173 $(#[$($meta:meta)*])* static $atom:ident : _ = _($init:expr);
174 $fn_vis:vis fn $f:ident() -> $t:tt;
175 $($rest:tt)*
176 ) => {
177 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $t ; $(#[$($meta)*])* }
178 chain_params! { $($rest)* }
179 };
180 (
181 $(#[$($meta:meta)*])* static $atom:ident : $st:tt = _($init:expr);
182 $fn_vis:vis fn $f:ident() -> $t:tt;
183 $($rest:tt)*
184 ) => {
185 chain_params! { basic $atom ; $init ; $fn_vis , $f ; $t ; $st ; $(#[$($meta)*])* }
186 chain_params! { $($rest)* }
187 };
188 (
189 $(#[$($meta:meta)*])* $fn_vis:vis fn $f:ident() -> $t:tt { $fx:expr }
190 $struct_vis:vis struct $struct_name:ident;
191 impl Get<_> for _ {}
192 $($rest:tt)*
193 ) => {
194 $(#[$($meta)*])* $fn_vis fn $f() -> $t { $fx }
195 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
196 chain_params! { $($rest)* }
197 };
198 (
199 $(#[$($meta:meta)*])* $const_vis:vis const $const_name:ident: _ = $cx:expr;
200 $fn_vis:vis fn $f:ident() -> $t:tt;
201 $struct_vis:vis struct $struct_name:ident;
202 impl Get<_> for _ {}
203 $($rest:tt)*
204 ) => {
205 $(#[$($meta)*])* $const_vis const $const_name: $t = $cx;
206 $(#[$($meta)*])* $fn_vis fn $f() -> $t { $const_name }
207 chain_params! { get $struct_vis , $struct_name ; $f ; $(#[$($meta)*])* }
208 chain_params! { $($rest)* }
209 };
210 () => {}
211}