MCPcopy Create free account
hub / github.com/ProvableHQ/sdk / get_function_inputs

Method get_function_inputs

wasm/src/programs/program.rs:131–205  ·  view source on GitHub ↗
(&self, function_name: String)

Source from the content-addressed store, hash-verified

129 /// console.log(transfer_function_inputs === expected_inputs); // Output should be "true"
130 #[wasm_bindgen(js_name = "getFunctionInputs")]
131 pub fn get_function_inputs(&self, function_name: String) -> Result<Array, String> {
132 let function_id = IdentifierNative::from_str(&function_name).map_err(|e| e.to_string())?;
133 let function = self
134 .0
135 .functions()
136 .get(&function_id)
137 .ok_or_else(|| format!("function {} not found in {}", function_name, self.0.id()))?;
138 let function_inputs = Array::new_with_length(function.inputs().len() as u32);
139 for (index, input) in function.inputs().iter().enumerate() {
140 let register = JsValue::from_str(&input.register().to_string());
141 match input.value_type() {
142 ValueType::Constant(plaintext) => {
143 function_inputs.set(index as u32, {
144 let input = self.get_plaintext_input(plaintext, Some("constant".to_string()), None)?;
145 Reflect::set(&input, &"register".into(), &register).map_err(|_| "Failed to set property")?;
146 input.into()
147 });
148 }
149 ValueType::Public(plaintext) => {
150 function_inputs.set(index as u32, {
151 let input = self.get_plaintext_input(plaintext, Some("public".to_string()), None)?;
152 Reflect::set(&input, &"register".into(), &register).map_err(|_| "Failed to set property")?;
153 input.into()
154 });
155 }
156 ValueType::Private(plaintext) => {
157 function_inputs.set(index as u32, {
158 let input = self.get_plaintext_input(plaintext, Some("private".to_string()), None)?;
159 Reflect::set(&input, &"register".into(), &register).map_err(|_| "Failed to set property")?;
160 input.into()
161 });
162 }
163 ValueType::Record(identifier) => {
164 function_inputs.set(index as u32, {
165 let input = self.get_record_members(identifier.to_string())?;
166 Reflect::set(&input, &"register".into(), &register).map_err(|_| "Failed to set property")?;
167 input.into()
168 });
169 }
170 ValueType::ExternalRecord(locator) => {
171 let input = Object::new();
172 let value_type = JsValue::from_str("external_record");
173 Reflect::set(&input, &"type".into(), &value_type).map_err(|_| "Failed to set property")?;
174 Reflect::set(&input, &"locator".into(), &locator.to_string().into())
175 .map_err(|_| "Failed to set property")?;
176 Reflect::set(&input, &"register".into(), &register).map_err(|_| "Failed to set property")?;
177 function_inputs.set(index as u32, input.into());
178 }
179 ValueType::Future(locator) => {
180 let input = Object::new();
181 let value_type = JsValue::from_str("future");
182 Reflect::set(&input, &"type".into(), &value_type).map_err(|_| "Failed to set property")?;
183 Reflect::set(&input, &"locator".into(), &locator.to_string().into())
184 .map_err(|_| "Failed to set property")?;
185 Reflect::set(&input, &"register".into(), &register).map_err(|_| "Failed to set property")?;
186 function_inputs.set(index as u32, input.into());
187 }
188 ValueType::DynamicRecord => {

Callers 1

test_get_inputsFunction · 0.80

Calls 8

setFunction · 0.85
lenMethod · 0.80
registerMethod · 0.80
value_typeMethod · 0.80
get_plaintext_inputMethod · 0.80
get_record_membersMethod · 0.80
to_stringMethod · 0.45
inputsMethod · 0.45

Tested by 1

test_get_inputsFunction · 0.64