Implement BeaconBlockRoots RPC method

This commit is contained in:
Age Manning 2019-03-21 11:02:52 +11:00
parent a14426349a
commit 766a79adfa
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93

View File

@ -1,4 +1,4 @@
use super::methods::{HelloMessage, RPCMethod, RPCRequest, RPCResponse};
use super::methods::*;
use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use ssz::{ssz_encode, Decodable, Encodable, SszStream};
use std::io;
@ -85,6 +85,11 @@ fn decode(packet: Vec<u8>) -> Result<RPCEvent, DecodeError> {
let (goodbye_code, _index) = u64::ssz_decode(&packet, index)?;
RPCRequest::Goodbye(goodbye_code)
}
RPCMethod::BeaconBlockRoots => {
let (block_roots_request, _index) =
BeaconBlockRootsRequest::ssz_decode(&packet, index)?;
RPCRequest::BeaconBlockRoots(block_roots_request)
}
RPCMethod::Unknown | _ => return Err(DecodeError::UnknownRPCMethod),
};
@ -101,6 +106,11 @@ fn decode(packet: Vec<u8>) -> Result<RPCEvent, DecodeError> {
let (body, _index) = HelloMessage::ssz_decode(&packet, index)?;
RPCResponse::Hello(body)
}
RPCMethod::Goodbye => unreachable!("Should never receive a goodbye response"),
RPCMethod::BeaconBlockRoots => {
let (body, _index) = BeaconBlockRootsResponse::ssz_decode(&packet, index)?;
RPCResponse::BeaconBlockRoots(body)
}
RPCMethod::Unknown | _ => return Err(DecodeError::UnknownRPCMethod),
};
Ok(RPCEvent::Response {