1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use ibc_proto::google::protobuf::Any;

use crate::prelude::*;

/// Trait to be implemented by all IBC messages
pub trait Msg: Clone {
    type Raw: From<Self> + prost::Message;

    /// Unique type identifier for this message, to support encoding to/from `prost_types::Any`.
    fn type_url(&self) -> String;

    fn get_sign_bytes(self) -> Vec<u8> {
        let raw_msg: Self::Raw = self.into();
        prost::Message::encode_to_vec(&raw_msg)
    }

    fn to_any(self) -> Any {
        Any {
            type_url: self.type_url(),
            value: self.get_sign_bytes(),
        }
    }
}