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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![feature(lang_items)]
#![feature(core_intrinsics)]
#![feature(allocator_api)]
#![feature(alloc_prelude)]
#![feature(slice_concat_ext)]
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(exclusive_range_pattern)]
#![feature(proc_macro_hygiene)]
#![feature(panic_info_message)]

//#![feature(trace_macros)]

cfg_if::cfg_if! {
    if #[cfg(all(not(feature = "std"), feature = "bump-alloc"))] {
        use ontio_bump_alloc::BumpAlloc;
        #[global_allocator]
        static ALLOC: BumpAlloc = BumpAlloc::new();
    } else if #[cfg(not(feature = "std"))] {
        extern crate wee_alloc;
        // Use `wee_alloc` as the global allocator.
        #[global_allocator]
        static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
    }
}

cfg_if::cfg_if! {
    if #[cfg(not(feature = "std"))] {
        use prelude::*;
        /// Overrides the default panic_fmt
        #[no_mangle]
        #[panic_handler]
        pub fn panic_fmt(info: &core::panic::PanicInfo) -> ! {
            let msg = info.message().map(|msg| format!("{}", msg)).unwrap_or_default();
            let (file, line) = if let Some(loc) = info.location() {
                (loc.file(), loc.line())
            } else {
                ("", 0)
            };


            let panic_msg = format!("{} at {}:{}", msg, file, line);
            runtime::panic(&panic_msg)
        }

        #[lang = "eh_personality"]
        extern "C" fn eh_personality() {}

        /// Overrides the default oom
        #[lang = "oom"]
        #[no_mangle]
        pub fn oom(_: core::alloc::Layout) -> ! {
            core::intrinsics::abort()
        }
    }

}

extern crate alloc;
///The prelude module provides common data types in the contract, and introduces some functions in the rust core library.
pub mod prelude {
    pub use crate::contract::TransferParam;
    pub use crate::types::{Address, H256, I128, U128};
    pub use alloc::boxed::Box;
    pub use alloc::prelude::*;
    pub use alloc::str;
    pub use alloc::string::{self, String, ToString};
    pub use alloc::vec::Vec;
    pub use alloc::{format, vec};
    pub use core::cmp;
    pub use core::prelude::v1::*;
}

///The abi module provides serialization and deserialization methods for different data types in the contract
pub mod abi;
///The console module provides the debug function, which is used to print the log information in the contract and facilitate the debugging of the contract.
pub mod console;
///The contract module provides the method to call the asset ont, ong on the ontology chain.
pub mod contract;
///The database module provides the interface to save the data in the contract to the chain and query the data from the chain.
pub mod database;
///The runtime module provides an interface to interact with the chain in the contract
pub mod runtime;
///The types module provides common data types such as address, U128, hash, etc.
pub mod types;

///Macro module provides common macro functions, such as base58! To convert base58 encoded address to address type
pub mod macros;
pub mod utils;

#[cfg(feature = "mock")]
pub mod mock;