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