fvm-std 1.0.0

tool for user to write contract which will be run in hyperchain with rust
Documentation
use alloc::vec::Vec;
use crate::prelude::{Address, H256};
use crate::runtime;
use crate::types::LogLevel;

/// With this method, another contract can be called, Please refer to the corresponding simple_call.
///
/// addr: Called contract address
///
/// input: Parameters required to call the target contract method
///
/// # Example
/// ```no_run
/// # use fvm_std::advance::call_contract;
/// # use fvm_std::types::Address;
/// let addr = Address::repeat_byte(1u8);
/// let res = call_contract(&addr, addr.as_bytes());
/// ```
pub fn call_contract(addr: &Address, input: &[u8]) -> Vec<u8> {
    runtime::call_contract(addr, input)
}

/// With this method, another contract can be called.
///
/// cns: Called contract cns name
///
/// input: Parameters required to call the target contract method
///
/// # Example
/// ```no_run
/// # use fvm_std::advance::cns_call_contract;
/// # use fvm_std::types::Address;
/// let cns_name = "hello".as_bytes();
/// let input = "world".as_bytes();
/// let res = cns_call_contract(cns_name, input);
/// ```
pub fn cns_call_contract(cns_name: &[u8], input: &[u8]) -> Vec<u8> {
    runtime::cns_call_contract(cns_name, input)
}

///Save key-value as a key-value pair
///
/// 对于一般的的属性存储:
/// `fieldName + key => Gson(value)`
/// ---prefix--|--key---|----value--
/// 对于Map, List等的存储:
/// `fieldName + @ + Gson(key) => value`
/// ---prefix------|---key----|----value--
///
/// # Example
///
///```no_run
/// use fvm_std::advance::storage_write;
/// let key = "key";
/// let prefix = "map";
/// let value = "value";
/// storage_write(key.as_bytes(), value.as_bytes());
/// ```
///
pub fn storage_write(key: &[u8], val: &[u8]) {
    runtime::storage_write(key, &[], val)
}

///Read key-value pairs according to key.
///
/// # Example
///
///```no_run
/// # use fvm_std::advance::storage_read;
/// let key = "key";
/// let res: Option<Vec<u8>> = storage_read(key.as_bytes());
/// ```
///
pub fn storage_read(key: &[u8]) -> Option<Vec<u8>> {
    runtime::storage_read(key, &[])
}


///Delte key-value from ledger
///
/// 对于一般的的属性存储:
/// `fieldName + key => Gson(value)`
/// ---prefix--|--key---|----value--
/// 对于Map, List等的存储:
/// `fieldName + @ + Gson(key) => value`
/// ---prefix------|---key----|----value--
///
/// # Example
///
///```no_run
/// # use fvm_std::advance::storage_delete;
/// let key = "key";
/// let prefix = "map";
/// let value = "value";
/// storage_delete(key.as_bytes());
/// ```
///
pub fn storage_delete(key: &[u8]) {
    runtime::storage_delete(key, &[])
}

/// Get timestamp in current block
/// # Example
///
/// ```no_run
/// # use fvm_std::advance::block_time;
/// let res = block_time();
/// ```
///
pub fn block_time() -> u64 {
    runtime::block_time()
}

/// Get current block height
/// # Example
///
/// ```no_run
/// use fvm_std::advance::block_height;
/// let res = block_height();
/// ```
///
pub fn block_height() -> u64 {
    runtime::block_height()
}

/// Get the address of current executing contract
/// # Example
///
/// ```no_run
/// use fvm_std::advance::self_address;
/// let res = self_address();
/// ```
///
pub fn self_address() -> Address {
    runtime::self_address()
}

///return Caller's contract address
/// # Example
///
///```no_run
/// use fvm_std::advance::caller_address;
/// let res = caller_address();
/// ```
///
pub fn caller_address() -> Address {
    runtime::caller_address()
}

///return the origin Caller's contract address, it is same with `caller_address`
/// in normal call, but in cross call, the `origin_address` return the origin
/// caller address.
/// # Example
///
///```no_run
/// use fvm_std::advance::origin_address;
/// let res = origin_address();
/// ```
///
pub fn origin_address() -> Address {
    runtime::origin_address()
}

///return current tx hash
/// # Example
///
///```no_run
/// use fvm_std::advance::tx_hash;
/// let res = tx_hash();
/// ```
///
pub fn tx_hash() -> H256 {
    runtime::tx_hash()
}

/// Calculate the hash value
/// # Example
///
/// ```no_run
/// use fvm_std::advance::sha256;
/// let res = sha256("test");
/// ```
///
pub fn sha256(data: impl AsRef<[u8]>) -> H256 {
    runtime::sha256(data)
}


/// Get input data from transaction or caller contract
/// # Example
///
/// ```no_run
/// use fvm_std::advance::input;
/// let input = input();
/// ```
///
pub fn input() -> Vec<u8> {
    runtime::input()
}

/// return the result of execution and exit contract execution
/// # Example
///
/// ```no_run
///   use fvm_std::advance::{input, ret};
///   let input = input();
///   ret(input.as_slice());
/// ```
///
pub fn ret(data: &[u8]) {
    runtime::ret(data)
}

// /// used for event, or use it with correct format
// pub fn event(data: &[u8]) {
//     runtime::event(data)
// }

// /// output debugging information
// pub fn log(class_name: &[u8], data: &[u8], level: LogLevel) {
//     runtime::log(class_name, data, level)
// }

/// When the function is executed, all writes to the chain will be cancelled, and the error message will be returned.
///
/// # Example
///
/// ```no_run
///   use fvm_std::advance::revert;
/// revert("panic");
/// ```
///
pub fn revert(msg: &str) -> ! {
    runtime::revert(msg)
}

pub fn log(class_name: &[u8], data: &[u8], level: LogLevel) {
    runtime::log(class_name, data, level)
}