Expand description
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)
}Re-exports§
pub use io::_eprint;pub use io::_print;pub use io::nucleus_id;pub use codec;pub use lazy_static;pub use scale_info;
Modules§
- abi
- error
- http
- Module for making http requests within nucleus.
- io
- Stdio module for printing to stdout and stderr of the host environment, useful for debugging on local. It is only available in the host environment, i.e., the environment where the Wasm is running. The functions in this module can be called both in get and post functions.
- storage
- Storage module provides a set of functions to interact with the kv storage. Any data stored in the kv storage will be synchronized across all nodes in the subnet. The nucleus will automatically update the state root after each modification and then submit to Verisense chain.
- timer
- tss
- Storage module provides a set of functions to interact with the kv storage. Any data stored in the kv storage will be synchronized across all nodes in the subnet. The nucleus will automatically update the state root after each modification and then submit to Verisense chain.
Macros§
Structs§
- Account
Id - An opaque 32-byte cryptographic identifier.
Constants§
- BUFFER_
LEN - the buffer used for transfering data from host to wasm this should be equal to a page size
- NO_
MORE_ DATA - if host function returns this value, it means there is no more data to read
Type Aliases§
- Call
Result - result of host function, T should be
codec::Codec - Nucleus
Id - the id of the nucleus, same as AccountId32