rust_chain/vmapi/off_chain/
print.rs

1use std::ffi::CStr;
2use chaintester::interfaces::TApplySyncClient;
3
4use chaintester::{
5    get_vm_api_client,
6};
7
8use crate::structs::*;
9use core::slice;
10
11///
12pub fn prints(cstr: *const u8) {
13    let s = unsafe { CStr::from_ptr(cstr as *const i8).to_str().unwrap() };
14    let mut client = get_vm_api_client();
15    // print!("\x1b[92m{}\x1b[0m", s);
16    client.prints(s.to_owned()).unwrap();
17}
18
19///
20pub fn prints_l(_cstr: *const u8, _len: u32) {
21    let s = unsafe {
22        slice::from_raw_parts(_cstr, _len as usize)
23    };
24    // print!("\x1b[92m{}\x1b[0m", std::str::from_utf8(s).unwrap());
25    get_vm_api_client().prints_l(s.to_vec()).unwrap();
26}
27
28///
29pub fn printi(value: i64) {
30    get_vm_api_client().printi(value).unwrap()
31}
32
33///
34pub fn printui(value: u64) {
35    get_vm_api_client().printui(value.into()).unwrap()
36}
37
38///
39pub fn printi128(value: i128) {
40    get_vm_api_client().printi128(value.to_le_bytes().to_vec()).unwrap()
41}
42
43///
44pub fn printui128(value: u128) {
45    get_vm_api_client().printui128(value.to_le_bytes().to_vec()).unwrap()
46}
47
48///
49pub fn printsf(value: f32) {
50    get_vm_api_client().printsf(value.to_le_bytes().to_vec()).unwrap()
51}
52
53///
54pub fn printdf(value: f64) {
55    get_vm_api_client().printdf(value.to_le_bytes().to_vec()).unwrap()
56}
57
58///
59pub fn printqf(value: *const Float128) {
60    unsafe {
61        get_vm_api_client().printqf((*value).data.to_vec()).unwrap()
62    }
63}
64
65///
66pub fn printn(name: u64) {
67    get_vm_api_client().printn(name.into()).unwrap()
68}
69
70///
71pub fn printhex(data: *const u8, datalen: u32) {
72    let s = unsafe {
73        slice::from_raw_parts(data, datalen as usize)
74    };
75
76    get_vm_api_client().printhex(s.to_vec()).unwrap()
77}
78