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