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
//! std runtime interfaces
use crate::Sandbox;
use ceres_executor::{derive::Value, Result};
use ceres_std::{vec, Vec};

type ParcelResult = Result<Option<Value>>;

/// std runtime interfaces
pub trait RuntimeInterfaces: Sized {
    /// Println
    fn seal_println(sandbox: &mut Sandbox, args: &[Value]) -> ParcelResult;

    /// Generate random value
    fn seal_random(sandbox: &mut Sandbox, args: &[Value]) -> ParcelResult;

    /// sha2 256
    fn seal_hash_sha2_256(sandbox: &mut Sandbox, args: &[Value]) -> ParcelResult;

    /// keccak 256
    fn seal_hash_keccak_256(sandbox: &mut Sandbox, args: &[Value]) -> ParcelResult;

    /// blake2 256
    fn seal_hash_blake2_256(sandbox: &mut Sandbox, args: &[Value]) -> ParcelResult;

    /// blake2 128
    fn seal_hash_blake2_128(sandbox: &mut Sandbox, args: &[Value]) -> ParcelResult;

    /// pack functions
    fn pack(&self) -> Vec<ceres_executor::derive::HostCall<&'static str, &'static str, Sandbox>> {
        vec![
            ("seal0", "seal_println", Self::seal_println),
            ("seal0", "seal_random", Self::seal_random),
            ("seal0", "seal_hash_blake2_128", Self::seal_hash_blake2_128),
            ("seal0", "seal_hash_blake2_256", Self::seal_hash_blake2_256),
            ("seal0", "seal_hash_keccak_256", Self::seal_hash_keccak_256),
            ("seal0", "seal_hash_sha2_256", Self::seal_hash_sha2_256),
        ]
    }
}