multiversx_chain_vm/
types.rs

1pub use crate::chain_core::types::Address as VMAddress;
2pub use crate::chain_core::types::CodeMetadata as VMCodeMetadata;
3pub use crate::chain_core::types::EsdtLocalRole;
4pub use crate::chain_core::types::EsdtLocalRoleFlags;
5pub use crate::chain_core::types::TokenType as VMTokenType;
6pub use crate::chain_core::types::H256;
7
8pub type RawHandle = i32;
9
10use num_bigint::BigUint;
11use num_traits::Zero;
12
13/// Helper function to quickly encode a u64 value, according to the MultiversX codec format.
14pub fn top_encode_u64(value: u64) -> Vec<u8> {
15    top_encode_big_uint(&BigUint::from(value))
16}
17
18/// Helper function to quickly encode a BigUint value, according to the MultiversX codec format.
19pub fn top_encode_big_uint(value: &BigUint) -> Vec<u8> {
20    if value.is_zero() {
21        Vec::new()
22    } else {
23        value.to_bytes_be()
24    }
25}
26
27pub(crate) fn top_decode_u64(bytes: &[u8]) -> u64 {
28    BigUint::from_bytes_be(bytes).try_into().unwrap()
29}