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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use bytes::BufMut;
use prost::{DecodeError, EncodeError};
use signatory::ed25519;
use amino_types::validate::ValidationError;
use chain;
pub trait SignableMsg {
fn sign_bytes<B: BufMut>(
&self,
chain_id: chain::Id,
sign_bytes: &mut B,
) -> Result<bool, EncodeError>;
fn set_signature(&mut self, sig: &ed25519::Signature);
fn validate(&self) -> Result<(), ValidationError>;
}
#[derive(Copy, Clone, Debug)]
pub enum SignedMsgType {
PreVote,
PreCommit,
Proposal,
}
impl SignedMsgType {
pub fn to_u32(self) -> u32 {
match self {
SignedMsgType::PreVote => 0x01,
SignedMsgType::PreCommit => 0x02,
SignedMsgType::Proposal => 0x20,
}
}
#[allow(dead_code)]
fn from(data: u32) -> Result<SignedMsgType, DecodeError> {
match data {
0x01 => Ok(SignedMsgType::PreVote),
0x02 => Ok(SignedMsgType::PreCommit),
0x20 => Ok(SignedMsgType::Proposal),
_ => Err(DecodeError::new("Invalid vote type")),
}
}
}