diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index 84b5b6c8b3..e678c70e8c 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -13,6 +13,7 @@ pub enum Error { BadResponse(String), RequestFailed(String), JsonRpc(RpcError), + Json(serde_json::Error), } impl From for Error { @@ -21,6 +22,12 @@ impl From for Error { } } +impl From for Error { + fn from(e: serde_json::Error) -> Self { + Error::Json(e) + } +} + #[async_trait] pub trait EngineApi { async fn upcheck(&self) -> Result<(), Error>; diff --git a/beacon_node/execution_layer/src/engine_api/http.rs b/beacon_node/execution_layer/src/engine_api/http.rs index 6ba1bd1dbb..78323c8731 100644 --- a/beacon_node/execution_layer/src/engine_api/http.rs +++ b/beacon_node/execution_layer/src/engine_api/http.rs @@ -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, +}