MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / call_function

Function call_function

runtime/src/contract.rs:9–22  ·  view source on GitHub ↗
(bytes: &[u8], function: &str, params: &[&str])

Source from the content-addressed store, hash-verified

7use wit_component::ComponentEncoder;
8
9pub 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
24fn load_contract(bytes: &[u8]) -> Result<(Store<i32>, Instance)> {
25 let mut config = Config::new();

Callers 2

process_transactionMethod · 0.85

Calls 1

load_contractFunction · 0.85

Tested by 1