rust_chain/vmapi/off_chain/
print.rs1use std::ffi::CStr;
2use chaintester::interfaces::TApplySyncClient;
3
4use chaintester::{
5 get_vm_api_client,
6};
7
8use crate::structs::*;
9use core::slice;
10
11pub 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 client.prints(s.to_owned()).unwrap();
17}
18
19pub fn prints_l(_cstr: *const u8, _len: u32) {
21 let s = unsafe {
22 slice::from_raw_parts(_cstr, _len as usize)
23 };
24 get_vm_api_client().prints_l(s.to_vec()).unwrap();
26}
27
28pub fn printi(value: i64) {
30 get_vm_api_client().printi(value).unwrap()
31}
32
33pub fn printui(value: u64) {
35 get_vm_api_client().printui(value.into()).unwrap()
36}
37
38pub fn printi128(value: i128) {
40 get_vm_api_client().printi128(value.to_le_bytes().to_vec()).unwrap()
41}
42
43pub fn printui128(value: u128) {
45 get_vm_api_client().printui128(value.to_le_bytes().to_vec()).unwrap()
46}
47
48pub fn printsf(value: f32) {
50 get_vm_api_client().printsf(value.to_le_bytes().to_vec()).unwrap()
51}
52
53pub fn printdf(value: f64) {
55 get_vm_api_client().printdf(value.to_le_bytes().to_vec()).unwrap()
56}
57
58pub fn printqf(value: *const Float128) {
60 unsafe {
61 get_vm_api_client().printqf((*value).data.to_vec()).unwrap()
62 }
63}
64
65pub fn printn(name: u64) {
67 get_vm_api_client().printn(name.into()).unwrap()
68}
69
70pub 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