Skip to content

Commit d482033

Browse files
📝 Add docstrings to pb/tuple-abi-encoding
Docstrings generation was requested by @d4mr. * #24 (comment) The following files were modified: * `server/src/http/dyn_contract.rs`
1 parent e3e0047 commit d482033

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

server/src/http/dyn_contract.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ impl ContractCall {
195195
Ok(abi)
196196
}
197197

198-
/// Extracts function name from method string
198+
/// Extracts the function name from a method string, handling optional "function" prefix and parameter lists.
199+
///
200+
/// Returns the function name as a string, or an error if the format is invalid.
199201
fn extract_function_name(&self, method: &str) -> Result<String, EngineError> {
200202
let trimmed = method.trim();
201203

@@ -214,6 +216,30 @@ impl ContractCall {
214216
})
215217
}
216218

219+
/// Converts a slice of JSON values into dynamic Solidity values according to ABI parameter definitions.
220+
///
221+
/// Validates parameter count, recursively parses complex types (such as tuples), and coerces each JSON value into a `DynSolValue` matching the expected Solidity type. Returns an error if parameter counts do not match, if a value cannot be coerced, or if a type mismatch is detected.
222+
///
223+
/// # Arguments
224+
///
225+
/// * `json_values` - The JSON values representing function arguments.
226+
/// * `json_abi_params` - The ABI parameter definitions describing expected Solidity types.
227+
///
228+
/// # Returns
229+
///
230+
/// A vector of `DynSolValue` instances corresponding to the parsed and validated parameters, or an error message if parsing fails.
231+
///
232+
/// # Examples
233+
///
234+
/// ```
235+
/// use serde_json::json;
236+
/// use alloy_sol_types::{DynSolValue, Param};
237+
///
238+
/// let json_values = vec![json!("0x1234..."), json!(42)];
239+
/// let abi_params = vec![Param { name: "to".into(), ty: "address".into(), components: vec![] }, Param { name: "amount".into(), ty: "uint256".into(), components: vec![] }];
240+
/// let result = ContractCall::json_to_sol(&json_values, &abi_params);
241+
/// assert!(result.is_ok());
242+
/// ```
217243
fn json_to_sol(
218244
json_values: &[JsonValue],
219245
json_abi_params: &[Param],
@@ -262,7 +288,12 @@ impl ContractCall {
262288
Ok(parsed_params)
263289
}
264290

265-
/// Encodes parameters using serde to directly deserialize into DynSolValue
291+
/// Encodes the contract call parameters for a given function using the contract's JSON parameters and ABI.
292+
///
293+
/// Validates parameter count, converts JSON values to Solidity types, and ABI-encodes the input data for transaction submission.
294+
///
295+
/// # Returns
296+
/// Encoded function call data as a byte vector on success, or an `EngineError` if parameter validation or encoding fails.
266297
pub fn encode_parameters(
267298
&self,
268299
function: &Function,

0 commit comments

Comments
 (0)