mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 21:27:12 +00:00
Resolve merge conflicts
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use super::*;
|
||||
use alloy_rlp::RlpEncodable;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Decode;
|
||||
use ssz::{Decode, TryFromIter};
|
||||
use ssz_types::{FixedVector, VariableList, typenum::Unsigned};
|
||||
use strum::EnumString;
|
||||
use superstruct::superstruct;
|
||||
use types::beacon_block_body::KzgCommitments;
|
||||
@@ -9,7 +10,7 @@ use types::blob_sidecar::BlobsList;
|
||||
use types::execution_requests::{
|
||||
ConsolidationRequests, DepositRequests, RequestType, WithdrawalRequests,
|
||||
};
|
||||
use types::{Blob, FixedVector, KzgProof, Unsigned};
|
||||
use types::{Blob, KzgProof};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -65,7 +66,7 @@ pub struct JsonPayloadIdResponse {
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(V1, V2, V3, V4, V5, V6),
|
||||
variants(Bellatrix, Capella, Deneb, Electra, Fulu, Eip7805, Gloas),
|
||||
variant_attributes(
|
||||
derive(Debug, PartialEq, Default, Serialize, Deserialize,),
|
||||
serde(bound = "E: EthSpec", rename_all = "camelCase"),
|
||||
@@ -100,19 +101,19 @@ pub struct JsonExecutionPayload<E: EthSpec> {
|
||||
pub block_hash: ExecutionBlockHash,
|
||||
#[serde(with = "ssz_types::serde_utils::list_of_hex_var_list")]
|
||||
pub transactions: Transactions<E>,
|
||||
#[superstruct(only(V2, V3, V4, V5, V6))]
|
||||
#[superstruct(only(Capella, Deneb, Electra, Fulu, Eip7805, Gloas))]
|
||||
pub withdrawals: VariableList<JsonWithdrawal, E::MaxWithdrawalsPerPayload>,
|
||||
#[superstruct(only(V3, V4, V5, V6))]
|
||||
#[superstruct(only(Deneb, Electra, Fulu, Eip7805, Gloas))]
|
||||
#[serde(with = "serde_utils::u64_hex_be")]
|
||||
pub blob_gas_used: u64,
|
||||
#[superstruct(only(V3, V4, V5, V6))]
|
||||
#[superstruct(only(Deneb, Electra, Fulu, Eip7805, Gloas))]
|
||||
#[serde(with = "serde_utils::u64_hex_be")]
|
||||
pub excess_blob_gas: u64,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayloadBellatrix<E>> for JsonExecutionPayloadV1<E> {
|
||||
impl<E: EthSpec> From<ExecutionPayloadBellatrix<E>> for JsonExecutionPayloadBellatrix<E> {
|
||||
fn from(payload: ExecutionPayloadBellatrix<E>) -> Self {
|
||||
JsonExecutionPayloadV1 {
|
||||
JsonExecutionPayloadBellatrix {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -130,9 +131,11 @@ impl<E: EthSpec> From<ExecutionPayloadBellatrix<E>> for JsonExecutionPayloadV1<E
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<E: EthSpec> From<ExecutionPayloadCapella<E>> for JsonExecutionPayloadV2<E> {
|
||||
fn from(payload: ExecutionPayloadCapella<E>) -> Self {
|
||||
JsonExecutionPayloadV2 {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadCapella<E>> for JsonExecutionPayloadCapella<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: ExecutionPayloadCapella<E>) -> Result<Self, Self::Error> {
|
||||
Ok(JsonExecutionPayloadCapella {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -147,18 +150,15 @@ impl<E: EthSpec> From<ExecutionPayloadCapella<E>> for JsonExecutionPayloadV2<E>
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
}
|
||||
withdrawals: withdrawals_to_json(payload.withdrawals)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl<E: EthSpec> From<ExecutionPayloadDeneb<E>> for JsonExecutionPayloadV3<E> {
|
||||
fn from(payload: ExecutionPayloadDeneb<E>) -> Self {
|
||||
JsonExecutionPayloadV3 {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadDeneb<E>> for JsonExecutionPayloadDeneb<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: ExecutionPayloadDeneb<E>) -> Result<Self, Self::Error> {
|
||||
Ok(JsonExecutionPayloadDeneb {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -173,21 +173,18 @@ impl<E: EthSpec> From<ExecutionPayloadDeneb<E>> for JsonExecutionPayloadV3<E> {
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_to_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E> {
|
||||
fn from(payload: ExecutionPayloadElectra<E>) -> Self {
|
||||
JsonExecutionPayloadV4 {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadElectra<E>> for JsonExecutionPayloadElectra<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: ExecutionPayloadElectra<E>) -> Result<Self, Self::Error> {
|
||||
Ok(JsonExecutionPayloadElectra {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -202,21 +199,18 @@ impl<E: EthSpec> From<ExecutionPayloadElectra<E>> for JsonExecutionPayloadV4<E>
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_to_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayloadEip7805<E>> for JsonExecutionPayloadV5<E> {
|
||||
fn from(payload: ExecutionPayloadEip7805<E>) -> Self {
|
||||
JsonExecutionPayloadV5 {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadFulu<E>> for JsonExecutionPayloadFulu<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: ExecutionPayloadFulu<E>) -> Result<Self, Self::Error> {
|
||||
Ok(JsonExecutionPayloadFulu {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -231,21 +225,18 @@ impl<E: EthSpec> From<ExecutionPayloadEip7805<E>> for JsonExecutionPayloadV5<E>
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_to_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayloadFulu<E>> for JsonExecutionPayloadV6<E> {
|
||||
fn from(payload: ExecutionPayloadFulu<E>) -> Self {
|
||||
JsonExecutionPayloadV6 {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadEip7805<E>> for JsonExecutionPayloadEip7805<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: ExecutionPayloadEip7805<E>) -> Result<Self, Self::Error> {
|
||||
Ok(JsonExecutionPayloadEip7805 {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -260,33 +251,69 @@ impl<E: EthSpec> From<ExecutionPayloadFulu<E>> for JsonExecutionPayloadV6<E> {
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_to_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayload<E>> for JsonExecutionPayload<E> {
|
||||
fn from(execution_payload: ExecutionPayload<E>) -> Self {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadGloas<E>> for JsonExecutionPayloadGloas<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: ExecutionPayloadGloas<E>) -> Result<Self, Self::Error> {
|
||||
Ok(JsonExecutionPayloadGloas {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
receipts_root: payload.receipts_root,
|
||||
logs_bloom: payload.logs_bloom,
|
||||
prev_randao: payload.prev_randao,
|
||||
block_number: payload.block_number,
|
||||
gas_limit: payload.gas_limit,
|
||||
gas_used: payload.gas_used,
|
||||
timestamp: payload.timestamp,
|
||||
extra_data: payload.extra_data,
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: withdrawals_to_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayload<E>> for JsonExecutionPayload<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(execution_payload: ExecutionPayload<E>) -> Result<Self, Self::Error> {
|
||||
match execution_payload {
|
||||
ExecutionPayload::Bellatrix(payload) => JsonExecutionPayload::V1(payload.into()),
|
||||
ExecutionPayload::Capella(payload) => JsonExecutionPayload::V2(payload.into()),
|
||||
ExecutionPayload::Deneb(payload) => JsonExecutionPayload::V3(payload.into()),
|
||||
ExecutionPayload::Electra(payload) => JsonExecutionPayload::V4(payload.into()),
|
||||
ExecutionPayload::Eip7805(payload) => JsonExecutionPayload::V5(payload.into()),
|
||||
ExecutionPayload::Fulu(payload) => JsonExecutionPayload::V6(payload.into()),
|
||||
ExecutionPayload::Bellatrix(payload) => {
|
||||
Ok(JsonExecutionPayload::Bellatrix(payload.into()))
|
||||
}
|
||||
ExecutionPayload::Capella(payload) => {
|
||||
Ok(JsonExecutionPayload::Capella(payload.try_into()?))
|
||||
}
|
||||
ExecutionPayload::Deneb(payload) => {
|
||||
Ok(JsonExecutionPayload::Deneb(payload.try_into()?))
|
||||
}
|
||||
ExecutionPayload::Electra(payload) => {
|
||||
Ok(JsonExecutionPayload::Electra(payload.try_into()?))
|
||||
}
|
||||
ExecutionPayload::Fulu(payload) => Ok(JsonExecutionPayload::Fulu(payload.try_into()?)),
|
||||
ExecutionPayload::Eip7805(payload) => {
|
||||
Ok(JsonExecutionPayload::Eip7805(payload.try_into()?))
|
||||
}
|
||||
ExecutionPayload::Gloas(payload) => {
|
||||
Ok(JsonExecutionPayload::Gloas(payload.try_into()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadV1<E>> for ExecutionPayloadBellatrix<E> {
|
||||
fn from(payload: JsonExecutionPayloadV1<E>) -> Self {
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadBellatrix<E>> for ExecutionPayloadBellatrix<E> {
|
||||
fn from(payload: JsonExecutionPayloadBellatrix<E>) -> Self {
|
||||
ExecutionPayloadBellatrix {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
@@ -305,9 +332,11 @@ impl<E: EthSpec> From<JsonExecutionPayloadV1<E>> for ExecutionPayloadBellatrix<E
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadV2<E>> for ExecutionPayloadCapella<E> {
|
||||
fn from(payload: JsonExecutionPayloadV2<E>) -> Self {
|
||||
ExecutionPayloadCapella {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadCapella<E>> for ExecutionPayloadCapella<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: JsonExecutionPayloadCapella<E>) -> Result<Self, Self::Error> {
|
||||
Ok(ExecutionPayloadCapella {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -322,19 +351,16 @@ impl<E: EthSpec> From<JsonExecutionPayloadV2<E>> for ExecutionPayloadCapella<E>
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
}
|
||||
withdrawals: withdrawals_from_json(payload.withdrawals)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadV3<E>> for ExecutionPayloadDeneb<E> {
|
||||
fn from(payload: JsonExecutionPayloadV3<E>) -> Self {
|
||||
ExecutionPayloadDeneb {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadDeneb<E>> for ExecutionPayloadDeneb<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: JsonExecutionPayloadDeneb<E>) -> Result<Self, Self::Error> {
|
||||
Ok(ExecutionPayloadDeneb {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -349,21 +375,18 @@ impl<E: EthSpec> From<JsonExecutionPayloadV3<E>> for ExecutionPayloadDeneb<E> {
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_from_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadV4<E>> for ExecutionPayloadElectra<E> {
|
||||
fn from(payload: JsonExecutionPayloadV4<E>) -> Self {
|
||||
ExecutionPayloadElectra {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadElectra<E>> for ExecutionPayloadElectra<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: JsonExecutionPayloadElectra<E>) -> Result<Self, Self::Error> {
|
||||
Ok(ExecutionPayloadElectra {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -378,21 +401,18 @@ impl<E: EthSpec> From<JsonExecutionPayloadV4<E>> for ExecutionPayloadElectra<E>
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_from_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadV5<E>> for ExecutionPayloadEip7805<E> {
|
||||
fn from(payload: JsonExecutionPayloadV5<E>) -> Self {
|
||||
ExecutionPayloadEip7805 {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadFulu<E>> for ExecutionPayloadFulu<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: JsonExecutionPayloadFulu<E>) -> Result<Self, Self::Error> {
|
||||
Ok(ExecutionPayloadFulu {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -407,21 +427,18 @@ impl<E: EthSpec> From<JsonExecutionPayloadV5<E>> for ExecutionPayloadEip7805<E>
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_from_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadV6<E>> for ExecutionPayloadFulu<E> {
|
||||
fn from(payload: JsonExecutionPayloadV6<E>) -> Self {
|
||||
ExecutionPayloadFulu {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadEip7805<E>> for ExecutionPayloadEip7805<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: JsonExecutionPayloadEip7805<E>) -> Result<Self, Self::Error> {
|
||||
Ok(ExecutionPayloadEip7805 {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
@@ -436,27 +453,63 @@ impl<E: EthSpec> From<JsonExecutionPayloadV6<E>> for ExecutionPayloadFulu<E> {
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: payload
|
||||
.withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
withdrawals: withdrawals_from_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayload<E>> for ExecutionPayload<E> {
|
||||
fn from(json_execution_payload: JsonExecutionPayload<E>) -> Self {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadGloas<E>> for ExecutionPayloadGloas<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(payload: JsonExecutionPayloadGloas<E>) -> Result<Self, Self::Error> {
|
||||
Ok(ExecutionPayloadGloas {
|
||||
parent_hash: payload.parent_hash,
|
||||
fee_recipient: payload.fee_recipient,
|
||||
state_root: payload.state_root,
|
||||
receipts_root: payload.receipts_root,
|
||||
logs_bloom: payload.logs_bloom,
|
||||
prev_randao: payload.prev_randao,
|
||||
block_number: payload.block_number,
|
||||
gas_limit: payload.gas_limit,
|
||||
gas_used: payload.gas_used,
|
||||
timestamp: payload.timestamp,
|
||||
extra_data: payload.extra_data,
|
||||
base_fee_per_gas: payload.base_fee_per_gas,
|
||||
block_hash: payload.block_hash,
|
||||
transactions: payload.transactions,
|
||||
withdrawals: withdrawals_from_json(payload.withdrawals)?,
|
||||
blob_gas_used: payload.blob_gas_used,
|
||||
excess_blob_gas: payload.excess_blob_gas,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayload<E>> for ExecutionPayload<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(json_execution_payload: JsonExecutionPayload<E>) -> Result<Self, Self::Error> {
|
||||
match json_execution_payload {
|
||||
JsonExecutionPayload::V1(payload) => ExecutionPayload::Bellatrix(payload.into()),
|
||||
JsonExecutionPayload::V2(payload) => ExecutionPayload::Capella(payload.into()),
|
||||
JsonExecutionPayload::V3(payload) => ExecutionPayload::Deneb(payload.into()),
|
||||
JsonExecutionPayload::V4(payload) => ExecutionPayload::Electra(payload.into()),
|
||||
JsonExecutionPayload::V5(payload) => ExecutionPayload::Eip7805(payload.into()),
|
||||
JsonExecutionPayload::V6(payload) => ExecutionPayload::Fulu(payload.into()),
|
||||
JsonExecutionPayload::Bellatrix(payload) => {
|
||||
Ok(ExecutionPayload::Bellatrix(payload.into()))
|
||||
}
|
||||
JsonExecutionPayload::Capella(payload) => {
|
||||
Ok(ExecutionPayload::Capella(payload.try_into()?))
|
||||
}
|
||||
JsonExecutionPayload::Deneb(payload) => {
|
||||
Ok(ExecutionPayload::Deneb(payload.try_into()?))
|
||||
}
|
||||
JsonExecutionPayload::Electra(payload) => {
|
||||
Ok(ExecutionPayload::Electra(payload.try_into()?))
|
||||
}
|
||||
JsonExecutionPayload::Fulu(payload) => Ok(ExecutionPayload::Fulu(payload.try_into()?)),
|
||||
JsonExecutionPayload::Eip7805(payload) => {
|
||||
Ok(ExecutionPayload::Eip7805(payload.try_into()?))
|
||||
}
|
||||
JsonExecutionPayload::Gloas(payload) => {
|
||||
Ok(ExecutionPayload::Gloas(payload.try_into()?))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -500,10 +553,10 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
|
||||
// Elements of the list **MUST** be ordered by `request_type` in ascending order
|
||||
let current_prefix = RequestType::from_u8(*prefix_byte)
|
||||
.ok_or(RequestsError::InvalidPrefix(*prefix_byte))?;
|
||||
if let Some(prev) = prev_prefix {
|
||||
if prev.to_u8() >= current_prefix.to_u8() {
|
||||
return Err(RequestsError::InvalidOrdering);
|
||||
}
|
||||
if let Some(prev) = prev_prefix
|
||||
&& prev.to_u8() >= current_prefix.to_u8()
|
||||
{
|
||||
return Err(RequestsError::InvalidOrdering);
|
||||
}
|
||||
prev_prefix = Some(current_prefix);
|
||||
|
||||
@@ -542,7 +595,7 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(V1, V2, V3, V4, V5, V6),
|
||||
variants(Bellatrix, Capella, Deneb, Electra, Fulu, Eip7805, Gloas),
|
||||
variant_attributes(
|
||||
derive(Debug, PartialEq, Serialize, Deserialize),
|
||||
serde(bound = "E: EthSpec", rename_all = "camelCase")
|
||||
@@ -553,25 +606,30 @@ impl<E: EthSpec> TryFrom<JsonExecutionRequests> for ExecutionRequests<E> {
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub struct JsonGetPayloadResponse<E: EthSpec> {
|
||||
#[superstruct(only(V1), partial_getter(rename = "execution_payload_v1"))]
|
||||
pub execution_payload: JsonExecutionPayloadV1<E>,
|
||||
#[superstruct(only(V2), partial_getter(rename = "execution_payload_v2"))]
|
||||
pub execution_payload: JsonExecutionPayloadV2<E>,
|
||||
#[superstruct(only(V3), partial_getter(rename = "execution_payload_v3"))]
|
||||
pub execution_payload: JsonExecutionPayloadV3<E>,
|
||||
#[superstruct(only(V4), partial_getter(rename = "execution_payload_v4"))]
|
||||
pub execution_payload: JsonExecutionPayloadV4<E>,
|
||||
#[superstruct(only(V5), partial_getter(rename = "execution_payload_v5"))]
|
||||
pub execution_payload: JsonExecutionPayloadV5<E>,
|
||||
#[superstruct(only(V6), partial_getter(rename = "execution_payload_v6"))]
|
||||
pub execution_payload: JsonExecutionPayloadV6<E>,
|
||||
#[superstruct(
|
||||
only(Bellatrix),
|
||||
partial_getter(rename = "execution_payload_bellatrix")
|
||||
)]
|
||||
pub execution_payload: JsonExecutionPayloadBellatrix<E>,
|
||||
#[superstruct(only(Capella), partial_getter(rename = "execution_payload_capella"))]
|
||||
pub execution_payload: JsonExecutionPayloadCapella<E>,
|
||||
#[superstruct(only(Deneb), partial_getter(rename = "execution_payload_deneb"))]
|
||||
pub execution_payload: JsonExecutionPayloadDeneb<E>,
|
||||
#[superstruct(only(Electra), partial_getter(rename = "execution_payload_electra"))]
|
||||
pub execution_payload: JsonExecutionPayloadElectra<E>,
|
||||
#[superstruct(only(Fulu), partial_getter(rename = "execution_payload_fulu"))]
|
||||
pub execution_payload: JsonExecutionPayloadFulu<E>,
|
||||
#[superstruct(only(Eip7805), partial_getter(rename = "execution_payload_eip7805"))]
|
||||
pub execution_payload: JsonExecutionPayloadEip7805<E>,
|
||||
#[superstruct(only(Gloas), partial_getter(rename = "execution_payload_gloas"))]
|
||||
pub execution_payload: JsonExecutionPayloadGloas<E>,
|
||||
#[serde(with = "serde_utils::u256_hex_be")]
|
||||
pub block_value: Uint256,
|
||||
#[superstruct(only(V3, V4, V5, V6))]
|
||||
#[superstruct(only(Deneb, Electra, Fulu, Eip7805, Gloas))]
|
||||
pub blobs_bundle: JsonBlobsBundleV1<E>,
|
||||
#[superstruct(only(V3, V4, V5, V6))]
|
||||
#[superstruct(only(Deneb, Electra, Fulu, Eip7805, Gloas))]
|
||||
pub should_override_builder: bool,
|
||||
#[superstruct(only(V4, V5, V6))]
|
||||
#[superstruct(only(Electra, Fulu, Eip7805, Gloas))]
|
||||
pub execution_requests: JsonExecutionRequests,
|
||||
}
|
||||
|
||||
@@ -579,56 +637,79 @@ impl<E: EthSpec> TryFrom<JsonGetPayloadResponse<E>> for GetPayloadResponse<E> {
|
||||
type Error = String;
|
||||
fn try_from(json_get_payload_response: JsonGetPayloadResponse<E>) -> Result<Self, Self::Error> {
|
||||
match json_get_payload_response {
|
||||
JsonGetPayloadResponse::V1(response) => {
|
||||
JsonGetPayloadResponse::Bellatrix(response) => {
|
||||
Ok(GetPayloadResponse::Bellatrix(GetPayloadResponseBellatrix {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
block_value: response.block_value,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V2(response) => {
|
||||
JsonGetPayloadResponse::Capella(response) => {
|
||||
Ok(GetPayloadResponse::Capella(GetPayloadResponseCapella {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
execution_payload: response.execution_payload.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution payload: {:?}", e)
|
||||
})?,
|
||||
block_value: response.block_value,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V3(response) => {
|
||||
JsonGetPayloadResponse::Deneb(response) => {
|
||||
Ok(GetPayloadResponse::Deneb(GetPayloadResponseDeneb {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
execution_payload: response.execution_payload.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution payload: {:?}", e)
|
||||
})?,
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V4(response) => {
|
||||
JsonGetPayloadResponse::Electra(response) => {
|
||||
Ok(GetPayloadResponse::Electra(GetPayloadResponseElectra {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
execution_payload: response.execution_payload.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution payload: {:?}", e)
|
||||
})?,
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
requests: response.execution_requests.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution requests : {:?}", e)
|
||||
format!("Failed to convert json to execution requests: {:?}", e)
|
||||
})?,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V5(response) => {
|
||||
Ok(GetPayloadResponse::Eip7805(GetPayloadResponseEip7805 {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
requests: response.execution_requests.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution requests {:?}", e)
|
||||
})?,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::V6(response) => {
|
||||
JsonGetPayloadResponse::Fulu(response) => {
|
||||
Ok(GetPayloadResponse::Fulu(GetPayloadResponseFulu {
|
||||
execution_payload: response.execution_payload.into(),
|
||||
execution_payload: response.execution_payload.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution payload: {:?}", e)
|
||||
})?,
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
requests: response.execution_requests.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution requests {:?}", e)
|
||||
format!("Failed to convert json to execution requests: {:?}", e)
|
||||
})?,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::Eip7805(response) => {
|
||||
Ok(GetPayloadResponse::Eip7805(GetPayloadResponseEip7805 {
|
||||
execution_payload: response.execution_payload.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution payload: {:?}", e)
|
||||
})?,
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
requests: response.execution_requests.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution requests: {:?}", e)
|
||||
})?,
|
||||
}))
|
||||
}
|
||||
JsonGetPayloadResponse::Gloas(response) => {
|
||||
Ok(GetPayloadResponse::Gloas(GetPayloadResponseGloas {
|
||||
execution_payload: response.execution_payload.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution payload: {:?}", e)
|
||||
})?,
|
||||
block_value: response.block_value,
|
||||
blobs_bundle: response.blobs_bundle.into(),
|
||||
should_override_builder: response.should_override_builder,
|
||||
requests: response.execution_requests.try_into().map_err(|e| {
|
||||
format!("Failed to convert json to execution requests: {:?}", e)
|
||||
})?,
|
||||
}))
|
||||
}
|
||||
@@ -670,6 +751,26 @@ impl From<JsonWithdrawal> for Withdrawal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper functions to convert between `VariableList<Withdrawal>` and `VariableList<JsonWithdrawal>`.
|
||||
fn withdrawals_to_json<N>(
|
||||
list: VariableList<Withdrawal, N>,
|
||||
) -> Result<VariableList<JsonWithdrawal, N>, ssz_types::Error>
|
||||
where
|
||||
N: Unsigned,
|
||||
{
|
||||
VariableList::try_from_iter(list.into_iter().map(Into::into))
|
||||
}
|
||||
|
||||
fn withdrawals_from_json<N>(
|
||||
list: VariableList<JsonWithdrawal, N>,
|
||||
) -> Result<VariableList<Withdrawal, N>, ssz_types::Error>
|
||||
where
|
||||
N: Unsigned,
|
||||
{
|
||||
VariableList::try_from_iter(list.into_iter().map(Into::into))
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, RlpEncodable)]
|
||||
pub struct EncodableJsonWithdrawal<'a> {
|
||||
pub index: u64,
|
||||
@@ -973,30 +1074,25 @@ pub struct JsonExecutionPayloadBodyV1<E: EthSpec> {
|
||||
pub withdrawals: Option<VariableList<JsonWithdrawal, E::MaxWithdrawalsPerPayload>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<JsonExecutionPayloadBodyV1<E>> for ExecutionPayloadBodyV1<E> {
|
||||
fn from(value: JsonExecutionPayloadBodyV1<E>) -> Self {
|
||||
Self {
|
||||
impl<E: EthSpec> TryFrom<JsonExecutionPayloadBodyV1<E>> for ExecutionPayloadBodyV1<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(value: JsonExecutionPayloadBodyV1<E>) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
transactions: value.transactions,
|
||||
withdrawals: value.withdrawals.map(|json_withdrawals| {
|
||||
Withdrawals::<E>::from(
|
||||
json_withdrawals
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
}),
|
||||
}
|
||||
withdrawals: value.withdrawals.map(withdrawals_from_json).transpose()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<ExecutionPayloadBodyV1<E>> for JsonExecutionPayloadBodyV1<E> {
|
||||
fn from(value: ExecutionPayloadBodyV1<E>) -> Self {
|
||||
Self {
|
||||
impl<E: EthSpec> TryFrom<ExecutionPayloadBodyV1<E>> for JsonExecutionPayloadBodyV1<E> {
|
||||
type Error = ssz_types::Error;
|
||||
|
||||
fn try_from(value: ExecutionPayloadBodyV1<E>) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
transactions: value.transactions,
|
||||
withdrawals: value.withdrawals.map(|withdrawals| {
|
||||
VariableList::from(withdrawals.into_iter().map(Into::into).collect::<Vec<_>>())
|
||||
}),
|
||||
}
|
||||
withdrawals: value.withdrawals.map(withdrawals_to_json).transpose()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1078,10 +1174,10 @@ impl TryFrom<JsonClientVersionV1> for ClientVersionV1 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bls::{PublicKeyBytes, SignatureBytes};
|
||||
use ssz::Encode;
|
||||
use types::{
|
||||
ConsolidationRequest, DepositRequest, MainnetEthSpec, PublicKeyBytes, RequestType,
|
||||
SignatureBytes, WithdrawalRequest,
|
||||
ConsolidationRequest, DepositRequest, MainnetEthSpec, RequestType, WithdrawalRequest,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user