use log::{info, error};
#[derive(Debug)]
pub enum InteractionError {
InvalidContractAddress,
InvalidFunctionName,
DataKeyNotFound,
}
pub fn call_contract_function(
contract_address: &str,
function_name: &str,
_params: Vec<String>,
gas_limit: u64,
) -> Result<String, InteractionError> {
if contract_address.is_empty() {
error!("Invalid contract address provided.");
return Err(InteractionError::InvalidContractAddress);
}
if function_name.is_empty() {
error!("Invalid function name provided.");
return Err(InteractionError::InvalidFunctionName);
}
info!(
"Calling function '{}' on contract '{}' with gas limit {}...",
function_name, contract_address, gas_limit
);
Ok("Function call executed successfully.".to_string())
}
pub fn fetch_contract_data(
contract_address: &str,
data_key: &str,
) -> Result<String, InteractionError> {
if contract_address.is_empty() {
error!("Invalid contract address provided.");
return Err(InteractionError::InvalidContractAddress);
}
if data_key.is_empty() {
error!("Data key not found.");
return Err(InteractionError::DataKeyNotFound);
}
info!("Fetching data '{}' from contract '{}'...", data_key, contract_address);
Ok("Data fetched successfully.".to_string())
}