use crate::{util, Error, Result};
use inkpad_std::{String, ToString, Vec};
use inkpad_support::types::Metadata;
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 {
pub fn parse(&self, metadata: &Metadata, method: &str, args: Vec<Vec<u8>>) -> Result<Vec<u8>> {
let methods = match self {
InkMethod::Call => metadata.messages(),
InkMethod::Deploy => metadata.constructors(),
};
let (selector, tys) = methods.get(method).ok_or(Error::GetMethodFailed {
name: method.to_string(),
})?;
util::parse_args(selector, args, tys.iter().map(|ty| ty.1).collect())
}
}