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