neo_solidity/neo/
method_token.rs1#[derive(Debug, Clone)]
6pub struct MethodToken {
7 pub hash: [u8; 20],
9 pub method: String,
11 pub parameters_count: u16,
13 pub has_return_value: bool,
15 pub call_flags: u8,
17}
18
19impl MethodToken {
20 pub fn new(hash: [u8; 20], method: &str, params: u16, has_return: bool, flags: u8) -> Self {
22 Self {
23 hash,
24 method: method.to_string(),
25 parameters_count: params,
26 has_return_value: has_return,
27 call_flags: flags,
28 }
29 }
30
31 pub fn hash_hex(&self) -> String {
33 hex::encode(self.hash)
34 }
35
36 pub fn allows_state_changes(&self) -> bool {
38 self.call_flags & 0x01 != 0
39 }
40
41 fn serialize(&self, buffer: &mut Vec<u8>) {
43 buffer.extend_from_slice(&self.hash);
45
46 let bytes = self.method.as_bytes();
48 assert!(
49 bytes.len() <= MAX_TOKEN_METHOD_LENGTH,
50 "method token '{}' exceeds {MAX_TOKEN_METHOD_LENGTH} bytes",
51 self.method
52 );
53 write_varbytes(buffer, bytes);
54
55 buffer.extend_from_slice(&self.parameters_count.to_le_bytes());
57
58 buffer.push(if self.has_return_value { 1 } else { 0 });
60
61 buffer.push(self.call_flags);
63 }
64}