mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Modify decoding
This commit is contained in:
@@ -13,6 +13,7 @@ pub enum Error {
|
||||
BadResponse(String),
|
||||
RequestFailed(String),
|
||||
JsonRpc(RpcError),
|
||||
Json(serde_json::Error),
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for Error {
|
||||
@@ -21,6 +22,12 @@ impl From<reqwest::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
fn from(e: serde_json::Error) -> Self {
|
||||
Error::Json(e)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait EngineApi {
|
||||
async fn upcheck(&self) -> Result<(), Error>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use async_trait::async_trait;
|
||||
use eth1::http::{hex_to_u64_be, response_result_or_error, send_rpc_request};
|
||||
use eth1::http::{response_result_or_error, send_rpc_request};
|
||||
pub use reqwest::Client;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -54,11 +54,9 @@ impl EngineApi for HttpJsonRpc {
|
||||
.map_err(Error::RequestFailed)?;
|
||||
|
||||
let result = response_result_or_error(&response_body).map_err(Error::JsonRpc)?;
|
||||
let string = result
|
||||
.as_str()
|
||||
.ok_or(Error::BadResponse("data was not string".to_string()))?;
|
||||
let response: PreparePayloadResponse = serde_json::from_value(result)?;
|
||||
|
||||
hex_to_u64_be(string).map_err(Error::BadResponse)
|
||||
Ok(response.payload_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,3 +69,10 @@ struct PreparePayloadRequest {
|
||||
random: Hash256,
|
||||
fee_recipient: Address,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(transparent, rename = "camelCase")]
|
||||
struct PreparePayloadResponse {
|
||||
#[serde(with = "eth2_serde_utils::u64_hex_be")]
|
||||
payload_id: u64,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user