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
//! The core sdk for developing nucleus on Verisense.
//! NOTE: This crate is currently under heavy development and is not stable yet. We release it just for testing and collecting feedback.
//!
//! # Examples
//!
//! ```
//! use parity_scale_codec::{Decode, Encode};
//! use vrs_core_sdk::{get, post, storage};
//!
//! #[derive(Debug, Decode, Encode)]
//! pub struct User {
//! pub id: u64,
//! pub name: String,
//! }
//!
//! #[post]
//! pub fn add_user(user: User) -> Result<u64, String> {
//! let max_id_key = [&b"user:"[..], &u64::MAX.to_be_bytes()[..]].concat();
//! let max_id = match storage::search(&max_id_key, storage::Direction::Reverse)
//! .map_err(|e| e.to_string())?
//! {
//! Some((id, _)) => u64::from_be_bytes(id[5..].try_into().unwrap()) + 1,
//! None => 1u64,
//! };
//! let key = [&b"user:"[..], &max_id.to_be_bytes()[..]].concat();
//! storage::put(&key, user.encode()).map_err(|e| e.to_string())?;
//! Ok(max_id)
//! }
//!
//! #[get]
//! pub fn get_user(id: u64) -> Result<Option<User>, String> {
//! let key = [&b"user:"[..], &id.to_be_bytes()[..]].concat();
//! let r = storage::get(&key).map_err(|e| e.to_string())?;
//! let user = r.map(|d| User::decode(&mut &d[..]).unwrap());
//! Ok(user)
//! }
//! ```
pub use codec;
pub use ;
pub use lazy_static;
pub use scale_info;
pub use AccountId32 as AccountId;
pub use *;
/// the buffer used for transfering data from host to wasm
/// this should be equal to a page size
pub const BUFFER_LEN: usize = 64 * 1024;
/// if host function returns this value, it means there is no more data to read
pub const NO_MORE_DATA: i32 = 0;
/// result of host function, T should be `codec::Codec`
pub type CallResult<T> = ;
/// the id of the nucleus, same as AccountId32
pub type NucleusId = AccountId;
pub