//! Contract methods use crate::{util, Error, Result}; use inkpad_std::{String, ToString, Vec}; use inkpad_support::types::Metadata; /// Custom ink method pub enum InkMethod { Deploy, Call, } impl ToString for InkMethod { fn to_string(&self) -> String { match &self { InkMethod::Call => "call", InkMethod::Deploy => "deploy", } .to_string() } } impl InkMethod { /// Get the input data by method and args pub fn parse(&self, metadata: &Metadata, method: &str, args: Vec>) -> Result> { let methods = match self { InkMethod::Call => metadata.messages(), InkMethod::Deploy => metadata.constructors(), }; // get selector let (selector, tys) = methods.get(method).ok_or(Error::GetMethodFailed { name: method.to_string(), })?; // parse arguments util::parse_args(selector, args, tys.iter().map(|ty| ty.1).collect()) } }