1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use {Param, Result, ErrorKind, Token, ParamType, encode, Bytes};
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Constructor {
pub inputs: Vec<Param>,
}
impl Constructor {
fn param_types(&self) -> Vec<ParamType> {
self.inputs.iter()
.map(|p| p.kind.clone())
.collect()
}
pub fn encode_input(&self, code: Bytes, tokens: &[Token]) -> Result<Bytes> {
let params = self.param_types();
if Token::types_check(tokens, ¶ms) {
Ok(code.into_iter().chain(encode(tokens)).collect())
} else {
Err(ErrorKind::InvalidData.into())
}
}
}