-
Notifications
You must be signed in to change notification settings - Fork 326
/
tx_msg.rs
33 lines (26 loc) · 915 Bytes
/
tx_msg.rs
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
30
31
32
33
use prost_types::Any;
use crate::ics24_host::error::ValidationError;
pub trait Msg: Clone {
type ValidationError: std::error::Error;
type Raw: From<Self> + prost::Message;
// TODO: Clarify what is this function supposed to do & its connection to ICS26 routing mod.
fn route(&self) -> String;
/// Unique type identifier for this message, to support encoding to/from `prost_types::Any`.
fn type_url(&self) -> String;
#[allow(clippy::wrong_self_convention)]
fn to_any(self) -> Any {
Any {
type_url: self.type_url(),
value: self.get_sign_bytes(),
}
}
fn get_sign_bytes(self) -> Vec<u8> {
let mut buf = Vec::new();
let raw_msg: Self::Raw = self.into();
prost::Message::encode(&raw_msg, &mut buf).unwrap();
buf
}
fn validate_basic(&self) -> Result<(), ValidationError> {
Ok(())
}
}