Rename RPC reqeusts, correct RPC internals
This commit is contained in:
parent
2871ad5055
commit
7370306366
@ -19,17 +19,17 @@ impl From<u16> for RPCMethod {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum RPCRequest {
|
pub enum RPCRequest {
|
||||||
HelloRequest,
|
Hello(HelloBody),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum RPCResponse {
|
pub enum RPCResponse {
|
||||||
HelloResponse(HelloResponse),
|
Hello(HelloBody),
|
||||||
}
|
}
|
||||||
|
|
||||||
// request/response structs for RPC methods
|
// request/response structs for RPC methods
|
||||||
#[derive(Encode, Decode, Clone, Debug)]
|
#[derive(Encode, Decode, Clone, Debug)]
|
||||||
pub struct HelloResponse {
|
pub struct HelloBody {
|
||||||
pub network_id: u8,
|
pub network_id: u8,
|
||||||
pub latest_finalized_root: Hash256,
|
pub latest_finalized_root: Hash256,
|
||||||
pub latest_finalized_epoch: Epoch,
|
pub latest_finalized_epoch: Epoch,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
///
|
///
|
||||||
/// This is purpose built for Ethereum 2.0 serenity and the protocol listens on
|
/// This is purpose built for Ethereum 2.0 serenity and the protocol listens on
|
||||||
/// `/eth/serenity/rpc/1.0.0`
|
/// `/eth/serenity/rpc/1.0.0`
|
||||||
mod handler;
|
|
||||||
mod methods;
|
mod methods;
|
||||||
mod protocol;
|
mod protocol;
|
||||||
|
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
use super::methods::HelloResponse;
|
use super::methods::{HelloBody, RPCMethod, RPCRequest, RPCResponse};
|
||||||
use super::methods::{RPCMethod, RPCRequest, RPCResponse};
|
use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||||
//use crate::rpc_proto;
|
|
||||||
//use byteorder::{BigEndian, ByteOrder};
|
|
||||||
//use bytes::BytesMut;
|
|
||||||
use futures::{future, stream, Future, Stream};
|
|
||||||
use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, PeerId, UpgradeInfo};
|
|
||||||
//use std::{io, iter};
|
|
||||||
use ssz::{ssz_encode, Decodable, Encodable, SszStream};
|
use ssz::{ssz_encode, Decodable, Encodable, SszStream};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
@ -83,7 +77,10 @@ fn decode(packet: Vec<u8>) -> Result<RpcEvent, DecodeError> {
|
|||||||
|
|
||||||
if request {
|
if request {
|
||||||
let body = match RPCMethod::from(method_id) {
|
let body = match RPCMethod::from(method_id) {
|
||||||
RPCMethod::Hello => RPCRequest::HelloRequest,
|
RPCMethod::Hello => {
|
||||||
|
let (hello_body, _index) = HelloBody::ssz_decode(&packet, index)?;
|
||||||
|
RPCRequest::Hello(hello_body)
|
||||||
|
}
|
||||||
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,8 +94,8 @@ fn decode(packet: Vec<u8>) -> Result<RpcEvent, DecodeError> {
|
|||||||
else {
|
else {
|
||||||
let result = match RPCMethod::from(method_id) {
|
let result = match RPCMethod::from(method_id) {
|
||||||
RPCMethod::Hello => {
|
RPCMethod::Hello => {
|
||||||
let (hello_response, _index) = HelloResponse::ssz_decode(&packet, index)?;
|
let (body, _index) = HelloBody::ssz_decode(&packet, index)?;
|
||||||
RPCResponse::HelloResponse(hello_response)
|
RPCResponse::Hello(body)
|
||||||
}
|
}
|
||||||
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
RPCMethod::Unknown => return Err(DecodeError::UnknownRPCMethod),
|
||||||
};
|
};
|
||||||
@ -137,8 +134,8 @@ impl Encodable for RpcEvent {
|
|||||||
s.append(id);
|
s.append(id);
|
||||||
s.append(method_id);
|
s.append(method_id);
|
||||||
match body {
|
match body {
|
||||||
RPCRequest::HelloRequest => {}
|
RPCRequest::Hello(body) => s.append(body),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
RpcEvent::Response {
|
RpcEvent::Response {
|
||||||
id,
|
id,
|
||||||
@ -149,7 +146,7 @@ impl Encodable for RpcEvent {
|
|||||||
s.append(id);
|
s.append(id);
|
||||||
s.append(method_id);
|
s.append(method_id);
|
||||||
match result {
|
match result {
|
||||||
RPCResponse::HelloResponse(response) => {
|
RPCResponse::Hello(response) => {
|
||||||
s.append(response);
|
s.append(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user