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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! fvm-std is a crate that supply base tool for developer to write contract with RUST more convenient
//!
//! ### Types
//! Here some simple types that we provide for developers to write contract easier.
//! #### H256
//! `H256` is a 32-length bytes, in order to express block hash. There are methods implement
//!
//! ```ignore
//! fn as_ref(&self) -> &H256
//! pub const fn new(val: [u8; 32]) -> Self
//! pub fn to_hex_string(&self) -> String
//! ```
//!
//! #### H160
//! `H160` is a 20-length bytes, in order to express address, there are methods implement
//!
//! ```ignore
//! fn as_ref(&self) -> &H160
//! pub const fn new(val: [u8; 20]) -> Self
//! ```
//!
//! #### Address
//!
//! `Address` is a alias for `H160`, also a method implement
//!
//! ```ignore
//! pub fn to_hex_string(&self) -> String
//! ```
//!
//! ***Notice: `to_hex_string` is different to `to_string`, the latter will only print part of the content, if it is too long***
//!
//! #### Log level
//!
//! level for developer to use with event log. more details see in section [log](#Log)
//!
//! ```rust
//! // CRITICAL ERROR WARNING NOTICE INFO DEBUG
//! pub enum LogLevel {
//! CRITICAL,
//! ERROR,
//! WARNING,
//! NOTICE,
//! INFO,
//! DEBUG,
//! }
//! ```
//!
//! ### Log
//!
//! we have supplied several tool macros method for developer to print log in contract, include
//! `critical!()`, `error!()`, `warning!()`, `notice!()`, `info!()`, `debug!()`
//!
//! #### Demo
//!
//! ```ignore
//! pub fn add(&mut self) -> u64 {
//! info!("info {}", "hello");
//! warning!("warning {}", "hello");
//! notice!("notice {}", "hello");
//! 1
//! }
//! ```
//!
//! ### Event
//!
//! supply event for developer used in contract.
//!
//! ```ignore
//! #[derive(Debug, Serialize)]
//! pub struct Event<T> where T: Serialize {
//! address: Address,
//! data: T,
//! topics: Vec<H256>,
//! }
//! ```
//!
//! **demo**
//!
//! ```ignore
//! #[derive(Debug, Serialize)]
//! struct Temp {
//! amount: u64,
//! }
//!
//!
//! #[storage]
//! pub struct SetHash {
//! map: HyperMap<String, String>,
//! }
//!
//! #[contract]
//! impl SetHash {
//! fn new() -> Self {
//! Self { map: HyperMap::new() }
//! }
//!
//! pub fn set_hash(&mut self, key: String, value: String) {
//! let temp = Temp { amount: 1 };
//! let ev = Event::new(temp, "set_hash".to_string(), vec!["test".to_string()]);
//! ev.emit();
//! self.map.insert(key, value);
//! }
//!
//! pub fn get_hash(&mut self, key: String) -> &String {
//! self.map.get(&key).unwrap()
//! }
//! }
//!
//! ```
// #![feature(proc_macro_hygiene)]
// 在no-std中更为稳定的抛出panic信息
// #![feature(panic_info_message)]
extern crate alloc;
///The prelude module provides common data types in the contract, and introduces some functions in the rust core library.
///The database module provides the interface to save the data in the contract to the chain and query the data from the chain.
///The runtime module provides an interface to interact with the chain in the contract
///The types module provides common data types such as address, U128, hash, etc.
/// The event module provides method to throw event in the contract.
///The abi module provides serialization and deserialization methods for different data types in the contract