casper_types/
lib.rs

1//! Types used to allow creation of Wasm contracts and tests for use on the Casper Platform.
2
3#![cfg_attr(
4    not(any(
5        feature = "json-schema",
6        feature = "datasize",
7        feature = "std",
8        feature = "testing",
9        test,
10    )),
11    no_std
12)]
13#![doc(html_root_url = "https://docs.rs/casper-types/6.0.1")]
14#![doc(
15    html_favicon_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon_48.png",
16    html_logo_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon.png"
17)]
18#![cfg_attr(docsrs, feature(doc_auto_cfg))]
19
20#[cfg_attr(not(test), macro_use)]
21extern crate alloc;
22
23extern crate core;
24
25mod access_rights;
26pub mod account;
27pub mod addressable_entity;
28pub mod api_error;
29mod auction_state;
30mod block;
31mod block_time;
32mod byte_code;
33pub mod bytesrepr;
34#[cfg(any(feature = "std", test))]
35mod chainspec;
36pub mod checksummed_hex;
37mod cl_type;
38mod cl_value;
39pub mod contract_messages;
40mod contract_wasm;
41pub mod contracts;
42pub mod crypto;
43mod deploy_info;
44mod digest;
45mod display_iter;
46mod era_id;
47pub mod execution;
48#[cfg(any(feature = "std-fs-io", test))]
49pub mod file_utils;
50mod gas;
51#[cfg(any(feature = "testing", feature = "gens", test))]
52pub mod gens;
53pub mod global_state;
54#[cfg(feature = "json-schema")]
55mod json_pretty_printer;
56mod key;
57mod motes;
58mod package;
59mod peers_map;
60mod phase;
61mod protocol_version;
62pub mod runtime_footprint;
63mod semver;
64pub(crate) mod serde_helpers;
65mod stored_value;
66pub mod system;
67mod tagged;
68#[cfg(any(feature = "testing", test))]
69pub mod testing;
70mod timestamp;
71mod transaction;
72mod transfer;
73mod transfer_result;
74mod uint;
75mod uref;
76mod validator_change;
77
78#[cfg(all(feature = "std", any(feature = "std-fs-io", test)))]
79use libc::{c_long, sysconf, _SC_PAGESIZE};
80#[cfg(feature = "std")]
81use once_cell::sync::Lazy;
82
83pub use crate::uint::{UIntParseError, U128, U256, U512};
84
85pub use access_rights::{
86    AccessRights, ContextAccessRights, GrantedAccess, ACCESS_RIGHTS_SERIALIZED_LENGTH,
87};
88pub use account::Account;
89#[doc(inline)]
90pub use addressable_entity::{
91    AddressableEntity, AddressableEntityHash, ContractRuntimeTag, EntityAddr, EntityEntryPoint,
92    EntityKind, EntryPointAccess, EntryPointAddr, EntryPointPayment, EntryPointType,
93    EntryPointValue, EntryPoints, Parameter, Parameters, DEFAULT_ENTRY_POINT_NAME,
94};
95#[doc(inline)]
96pub use api_error::ApiError;
97#[allow(deprecated)]
98pub use auction_state::{AuctionState, JsonEraValidators, JsonValidatorWeights};
99#[cfg(all(feature = "std", feature = "json-schema"))]
100pub use block::JsonBlockWithSignatures;
101pub use block::{
102    AvailableBlockRange, Block, BlockBody, BlockBodyV1, BlockBodyV2, BlockGlobalAddr,
103    BlockGlobalAddrTag, BlockHash, BlockHashAndHeight, BlockHeader, BlockHeaderV1, BlockHeaderV2,
104    BlockHeaderWithSignatures, BlockHeaderWithSignaturesValidationError, BlockIdentifier,
105    BlockSignatures, BlockSignaturesMergeError, BlockSignaturesV1, BlockSignaturesV2,
106    BlockSyncStatus, BlockSynchronizerStatus, BlockV1, BlockV2, BlockValidationError,
107    BlockWithSignatures, ChainNameDigest, EraEnd, EraEndV1, EraEndV2, EraReport, FinalitySignature,
108    FinalitySignatureId, FinalitySignatureV1, FinalitySignatureV2, RewardedSignatures, Rewards,
109    SingleBlockRewardedSignatures,
110};
111#[cfg(any(all(feature = "std", feature = "testing"), test))]
112pub use block::{TestBlockBuilder, TestBlockV1Builder};
113pub use block_time::{BlockTime, HoldsEpoch, BLOCKTIME_SERIALIZED_LENGTH};
114pub use byte_code::{ByteCode, ByteCodeAddr, ByteCodeHash, ByteCodeKind};
115pub use cl_type::{named_key_type, CLType, CLTyped};
116#[cfg(feature = "json-schema")]
117pub use cl_value::cl_value_to_json;
118pub use cl_value::{
119    handle_stored_dictionary_value, CLTypeMismatch, CLValue, CLValueError, ChecksumRegistry,
120    DictionaryValue as CLValueDictionary, SystemHashRegistry,
121};
122pub use global_state::Pointer;
123
124#[cfg(any(feature = "std", test))]
125pub use chainspec::{
126    AccountConfig, AccountsConfig, ActivationPoint, AdministratorAccount, AuctionCosts,
127    BrTableCost, Chainspec, ChainspecRawBytes, ChainspecRegistry, ConsensusProtocolName,
128    ControlFlowCosts, CoreConfig, DelegatorConfig, DeployConfig, FeeHandling, GenesisAccount,
129    GenesisConfig, GenesisValidator, GlobalStateUpdate, GlobalStateUpdateConfig,
130    GlobalStateUpdateError, HandlePaymentCosts, HighwayConfig, HoldBalanceHandling, HostFunction,
131    HostFunctionCost, HostFunctionCostsV1, HostFunctionCostsV2, HostFunctionV2,
132    LegacyRequiredFinality, MessageLimits, MintCosts, NetworkConfig, NextUpgrade, OpcodeCosts,
133    PricingHandling, ProtocolConfig, ProtocolUpgradeConfig, RefundHandling, StandardPaymentCosts,
134    StorageCosts, SystemConfig, TransactionConfig, TransactionLaneDefinition, TransactionV1Config,
135    VacancyConfig, ValidatorConfig, WasmConfig, WasmV1Config, WasmV2Config,
136    DEFAULT_BASELINE_MOTES_AMOUNT, DEFAULT_GAS_HOLD_INTERVAL, DEFAULT_HOST_FUNCTION_NEW_DICTIONARY,
137    DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_REFUND_HANDLING,
138};
139#[cfg(any(all(feature = "std", feature = "testing"), test))]
140pub use chainspec::{
141    DEFAULT_ADD_BID_COST, DEFAULT_ADD_COST, DEFAULT_BIT_COST, DEFAULT_CONST_COST,
142    DEFAULT_CONTROL_FLOW_BLOCK_OPCODE, DEFAULT_CONTROL_FLOW_BR_IF_OPCODE,
143    DEFAULT_CONTROL_FLOW_BR_OPCODE, DEFAULT_CONTROL_FLOW_BR_TABLE_MULTIPLIER,
144    DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE, DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE,
145    DEFAULT_CONTROL_FLOW_CALL_OPCODE, DEFAULT_CONTROL_FLOW_DROP_OPCODE,
146    DEFAULT_CONTROL_FLOW_ELSE_OPCODE, DEFAULT_CONTROL_FLOW_END_OPCODE,
147    DEFAULT_CONTROL_FLOW_IF_OPCODE, DEFAULT_CONTROL_FLOW_LOOP_OPCODE,
148    DEFAULT_CONTROL_FLOW_RETURN_OPCODE, DEFAULT_CONTROL_FLOW_SELECT_OPCODE,
149    DEFAULT_CONVERSION_COST, DEFAULT_CURRENT_MEMORY_COST, DEFAULT_DELEGATE_COST, DEFAULT_DIV_COST,
150    DEFAULT_FEE_HANDLING, DEFAULT_GLOBAL_COST, DEFAULT_GROW_MEMORY_COST,
151    DEFAULT_INTEGER_COMPARISON_COST, DEFAULT_LARGE_TRANSACTION_GAS_LIMIT, DEFAULT_LOAD_COST,
152    DEFAULT_LOCAL_COST, DEFAULT_MAX_PAYMENT_MOTES, DEFAULT_MAX_STACK_HEIGHT,
153    DEFAULT_MIN_TRANSFER_MOTES, DEFAULT_MUL_COST, DEFAULT_NEW_DICTIONARY_COST, DEFAULT_NOP_COST,
154    DEFAULT_STORE_COST, DEFAULT_TRANSFER_COST, DEFAULT_UNREACHABLE_COST, DEFAULT_WASM_MAX_MEMORY,
155};
156pub use contract_wasm::{ContractWasm, ContractWasmHash};
157#[doc(inline)]
158pub use contracts::{Contract, NamedKeys};
159pub use crypto::*;
160pub use deploy_info::DeployInfo;
161pub use digest::{
162    ChunkWithProof, ChunkWithProofVerificationError, Digest, DigestError, IndexedMerkleProof,
163    MerkleConstructionError, MerkleVerificationError,
164};
165pub use display_iter::DisplayIter;
166pub use era_id::EraId;
167pub use gas::Gas;
168#[cfg(feature = "json-schema")]
169pub use json_pretty_printer::json_pretty_print;
170#[doc(inline)]
171pub use key::{
172    DictionaryAddr, FromStrError as KeyFromStrError, HashAddr, Key, KeyTag, PackageAddr,
173    BLAKE2B_DIGEST_LENGTH, DICTIONARY_ITEM_KEY_MAX_LENGTH, KEY_DICTIONARY_LENGTH, KEY_HASH_LENGTH,
174};
175pub use motes::Motes;
176#[doc(inline)]
177pub use package::{
178    EntityVersion, EntityVersionKey, EntityVersions, Group, Groups, Package, PackageHash,
179    PackageStatus, ENTITY_INITIAL_VERSION,
180};
181pub use peers_map::{PeerEntry, Peers};
182pub use phase::{Phase, PHASE_SERIALIZED_LENGTH};
183pub use protocol_version::{ProtocolVersion, VersionCheckResult};
184pub use runtime_footprint::RuntimeFootprint;
185pub use semver::{ParseSemVerError, SemVer, SEM_VER_SERIALIZED_LENGTH};
186pub use stored_value::{
187    GlobalStateIdentifier, StoredValue, StoredValueTag, TypeMismatch as StoredValueTypeMismatch,
188};
189pub use system::mint::METHOD_TRANSFER;
190pub use tagged::Tagged;
191#[cfg(any(feature = "std", test))]
192pub use timestamp::serde_option_time_diff;
193pub use timestamp::{TimeDiff, Timestamp};
194#[cfg(any(feature = "std", test))]
195pub use transaction::{calculate_lane_id_for_deploy, calculate_transaction_lane, GasLimited};
196pub use transaction::{
197    AddressableEntityIdentifier, Approval, ApprovalsHash, Deploy, DeployDecodeFromJsonError,
198    DeployError, DeployExcessiveSizeError, DeployHash, DeployHeader, DeployId,
199    ExecutableDeployItem, ExecutableDeployItemIdentifier, ExecutionInfo, InitiatorAddr,
200    InvalidDeploy, InvalidTransaction, InvalidTransactionV1, NamedArg, PackageIdentifier,
201    PricingMode, PricingModeError, RuntimeArgs, Transaction, TransactionArgs,
202    TransactionEntryPoint, TransactionHash, TransactionId, TransactionInvocationTarget,
203    TransactionRuntimeParams, TransactionScheduling, TransactionTarget, TransactionV1,
204    TransactionV1DecodeFromJsonError, TransactionV1Error, TransactionV1ExcessiveSizeError,
205    TransactionV1Hash, TransactionV1Payload, TransferTarget,
206};
207pub use transfer::{
208    Transfer, TransferAddr, TransferFromStrError, TransferV1, TransferV2, TRANSFER_ADDR_LENGTH,
209};
210pub use transfer_result::{TransferResult, TransferredTo};
211pub use uref::{
212    FromStrError as URefFromStrError, URef, URefAddr, UREF_ADDR_LENGTH, UREF_SERIALIZED_LENGTH,
213};
214pub use validator_change::ValidatorChange;
215/// The lane identifier for the native mint interaction.
216pub const MINT_LANE_ID: u8 = 0;
217/// The lane identifier for the native auction interaction.
218pub const AUCTION_LANE_ID: u8 = 1;
219/// The lane identifier for the install/upgrade auction interaction.
220pub const INSTALL_UPGRADE_LANE_ID: u8 = 2;
221/// The lane identifier for large wasms.
222pub(crate) const LARGE_WASM_LANE_ID: u8 = 3;
223/// The lane identifier for medium wasms.
224pub(crate) const MEDIUM_WASM_LANE_ID: u8 = 4;
225/// The lane identifier for small wasms.
226pub(crate) const SMALL_WASM_LANE_ID: u8 = 5;
227
228/// OS page size.
229#[cfg(feature = "std")]
230pub static OS_PAGE_SIZE: Lazy<usize> = Lazy::new(|| {
231    /// Sensible default for many if not all systems.
232    const DEFAULT_PAGE_SIZE: usize = 4096;
233
234    #[cfg(any(feature = "std-fs-io", test))]
235    // https://www.gnu.org/software/libc/manual/html_node/Sysconf.html
236    let value: c_long = unsafe { sysconf(_SC_PAGESIZE) };
237
238    #[cfg(not(any(feature = "std-fs-io", test)))]
239    let value = 0;
240
241    if value <= 0 {
242        DEFAULT_PAGE_SIZE
243    } else {
244        value as usize
245    }
246});