lighthouse/beacon_node/libp2p/src/rpc/methods.rs

52 lines
1.0 KiB
Rust
Raw Normal View History

2019-03-14 14:50:59 +00:00
/// Available RPC methods types and ids.
use ssz_derive::{Decode, Encode};
use types::{Epoch, Hash256, Slot};
#[derive(Debug)]
pub enum RPCMethod {
Hello,
2019-03-19 23:05:17 +00:00
Goodbye,
2019-03-14 14:50:59 +00:00
Unknown,
}
impl From<u16> for RPCMethod {
fn from(method_id: u16) -> Self {
match method_id {
0 => RPCMethod::Hello,
2019-03-19 23:05:17 +00:00
1 => RPCMethod::Goodbye,
2019-03-14 14:50:59 +00:00
_ => RPCMethod::Unknown,
}
}
}
2019-03-19 01:19:07 +00:00
impl Into<u16> for RPCMethod {
fn into(self) -> u16 {
match self {
RPCMethod::Hello => 0,
2019-03-19 23:05:17 +00:00
RPCMethod::Goodbye => 1,
2019-03-19 01:19:07 +00:00
_ => 0,
}
}
}
2019-03-14 14:50:59 +00:00
#[derive(Debug, Clone)]
pub enum RPCRequest {
Hello(HelloMessage),
2019-03-19 23:05:17 +00:00
Goodbye(u64),
2019-03-14 14:50:59 +00:00
}
#[derive(Debug, Clone)]
pub enum RPCResponse {
Hello(HelloMessage),
2019-03-14 14:50:59 +00:00
}
// request/response structs for RPC methods
#[derive(Encode, Decode, Clone, Debug)]
pub struct HelloMessage {
2019-03-14 14:50:59 +00:00
pub network_id: u8,
pub latest_finalized_root: Hash256,
pub latest_finalized_epoch: Epoch,
pub best_root: Hash256,
pub best_slot: Slot,
}