| 7 | use wit_component::ComponentEncoder; |
| 8 | |
| 9 | pub fn call_function(bytes: &[u8], function: &str, params: &[&str]) -> Result<()> { |
| 10 | let (mut store, instance) = load_contract(bytes)?; |
| 11 | let parsed: Result<Vec<Val>> = params.chunks_exact(2).map(parse_params).collect(); |
| 12 | |
| 13 | tracing::info!("{} params {:?}", function, parsed); |
| 14 | |
| 15 | let function = instance |
| 16 | .get_func(&mut store, function) |
| 17 | .ok_or_else(|| RuntimeError::ExportFunctionError(function.into()))?; |
| 18 | |
| 19 | function |
| 20 | .call(&mut store, &parsed?, &mut []) |
| 21 | .map_err(|e| RuntimeError::CallFunctionError(e.to_string())) |
| 22 | } |
| 23 | |
| 24 | fn load_contract(bytes: &[u8]) -> Result<(Store<i32>, Instance)> { |
| 25 | let mut config = Config::new(); |