1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
extern crate core;

mod address;
mod call_args;
mod mock_vm_type;
mod ty;
#[allow(clippy::assign_op_pattern, clippy::reversed_empty_ranges)]
mod uints;

pub use address::Address;
pub use address::CONTRACT_ADDRESS_PREFIX;
pub use borsh::{BorshDeserialize, BorshSerialize};
pub use call_args::CallArgs;
pub use mock_vm_type::{MockVMSerializationError, MockVMType};
pub use ty::Typed;
pub use uints::{U128, U256, U512};
/// A type representing the amount of native tokens.
pub type Balance = U256;
/// A type representing the block time.
pub type BlockTime = u64;

/// A type that can be written to the storage and read from the storage.
pub trait OdraType: MockVMType {
    /// Serializes the value.
    fn serialize(&self) -> Option<Vec<u8>> {
        self.ser().ok()
    }

    /// Deserializes the value.
    fn deserialize(bytes: &[u8]) -> Option<Self> {
        Self::deser(bytes.to_vec()).ok()
    }
}

impl<T: MockVMType> OdraType for T {}

/// Represents a serialized event.
pub type EventData = Vec<u8>;

#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Default)]
pub struct Bytes(Vec<u8>);

impl Bytes {
    /// Constructs a new, empty vector of bytes.
    pub fn new() -> Bytes {
        Bytes::default()
    }

    /// Returns reference to inner container.
    #[inline]
    pub fn inner_bytes(&self) -> &Vec<u8> {
        &self.0
    }

    /// Extracts a slice containing the entire vector.
    pub fn as_slice(&self) -> &[u8] {
        self.inner_bytes().as_slice()
    }
}

impl From<Vec<u8>> for Bytes {
    fn from(vec: Vec<u8>) -> Self {
        Self(vec)
    }
}