use crate::{
hostio::{self, wrap_hostio},
types::AddressVM,
};
use alloc::vec::Vec;
use alloy_primitives::{Address, U256};
pub fn args(len: usize) -> Vec<u8> {
let mut input = Vec::with_capacity(len);
unsafe {
hostio::read_args(input.as_mut_ptr());
input.set_len(len);
}
input
}
pub fn output(data: &[u8]) {
unsafe {
hostio::write_result(data.as_ptr(), data.len());
}
}
pub fn read_return_data(offset: usize, size: Option<usize>) -> Vec<u8> {
let size = size.unwrap_or_else(|| return_data_len().saturating_sub(offset));
let mut data = Vec::with_capacity(size);
if size > 0 {
unsafe {
let bytes_written = hostio::read_return_data(data.as_mut_ptr(), offset, size);
debug_assert!(bytes_written <= size);
data.set_len(bytes_written);
}
};
data
}
wrap_hostio!(
return_data_len RETURN_DATA_LEN return_data_size usize
);
wrap_hostio!(
address ADDRESS contract_address Address
);
pub fn balance() -> U256 {
address().balance()
}