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
use std::io::Result;
use crate::{choices::status::Status, ids::Id};
#[tonic::async_trait]
pub trait Block: Decidable + Initializer + StatusWriter + Sync + Send {
async fn bytes(&self) -> &[u8];
async fn to_bytes(&self) -> Result<Vec<u8>>;
async fn height(&self) -> u64;
async fn timestamp(&self) -> u64;
async fn parent(&self) -> Id;
async fn verify(&mut self) -> Result<()>;
}
#[tonic::async_trait]
pub trait Decidable {
async fn id(&self) -> Id;
async fn status(&self) -> Status;
async fn accept(&mut self) -> Result<()>;
async fn reject(&mut self) -> Result<()>;
}
#[tonic::async_trait]
pub trait Initializer {
async fn init(&mut self, bytes: &[u8], status: Status) -> Result<()>;
}
#[tonic::async_trait]
pub trait StatusWriter {
async fn set_status(&mut self, status: Status);
}