-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
272 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub const BLS_DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; | ||
pub const BLS_PUBLIC_KEY_BYTES_LEN: usize = 48; | ||
pub const BLS_SECRET_KEY_BYTES_LEN: usize = 32; | ||
pub const BLS_SIGNATURE_BYTES_LEN: usize = 96; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
/// A helper type that generates helper types for the beacon API. | ||
macro_rules! beacon_serde_glue { | ||
// Named-Struct | ||
( | ||
$( #[$meta:meta] )* | ||
$vis:vis struct $name:ident { | ||
$( | ||
$( #[$field_meta:meta] )* | ||
$field_vis:vis $field_name:ident : $field_ty:ty | ||
),* | ||
$(,)? } | ||
) => { | ||
$( #[$meta] )* | ||
$vis struct Beacon$name { | ||
$( | ||
$( #[$field_meta] )* | ||
$field_vis $field_name : $field_ty | ||
),* | ||
} | ||
} | ||
} | ||
|
||
pub(crate) use beacon_serde_glue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(missing_docs)] | ||
//! Types for the Ethereum 2.0 RPC protocol (beacon chain) | ||
use alloy_primitives::FixedBytes; | ||
use constants::{BLS_PUBLIC_KEY_BYTES_LEN, BLS_SIGNATURE_BYTES_LEN}; | ||
|
||
pub mod constants; | ||
pub mod macros; | ||
pub mod payload; | ||
|
||
/// BLS signature type | ||
pub type BlsSignature = FixedBytes<BLS_SIGNATURE_BYTES_LEN>; | ||
|
||
/// BLS public key type | ||
pub type BlsPublicKey = FixedBytes<BLS_PUBLIC_KEY_BYTES_LEN>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#![allow(missing_docs)] | ||
//! Payload support for the beacon API. | ||
//! | ||
//! Internal helper module to deserialize/serialize the payload attributes for the beacon API, which | ||
//! uses snake case and quoted decimals. | ||
//! | ||
//! This is necessary because we don't want to allow a mixture of both formats, hence `serde` | ||
//! aliases are not an option. | ||
pub use crate::Withdrawal; | ||
use crate::{ | ||
eth::{transaction::BlobTransactionSidecar, withdrawal::BeaconAPIWithdrawal}, | ||
ExecutionPayloadV1, | ||
}; | ||
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256, U64}; | ||
use c_kzg::{Blob, Bytes48}; | ||
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; | ||
use serde_with::{serde_as, DisplayFromStr}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub(crate) struct BeaconExecutionPayloadV1 { | ||
pub(crate) parent_hash: B256, | ||
pub(crate) fee_recipient: Address, | ||
pub(crate) state_root: B256, | ||
pub(crate) receipts_root: B256, | ||
pub(crate) logs_bloom: Bloom, | ||
pub(crate) prev_randao: B256, | ||
pub(crate) block_number: U64, | ||
pub(crate) gas_limit: U64, | ||
pub(crate) gas_used: U64, | ||
pub(crate) timestamp: U64, | ||
pub(crate) extra_data: Bytes, | ||
pub(crate) base_fee_per_gas: U256, | ||
pub(crate) block_hash: B256, | ||
pub(crate) transactions: Vec<Bytes>, | ||
} | ||
|
||
impl From<BeaconExecutionPayloadV1> for ExecutionPayloadV1 { | ||
fn from(payload: BeaconExecutionPayloadV1) -> Self { | ||
let BeaconExecutionPayloadV1 { | ||
parent_hash, | ||
fee_recipient, | ||
state_root, | ||
receipts_root, | ||
logs_bloom, | ||
prev_randao, | ||
block_number, | ||
gas_limit, | ||
gas_used, | ||
timestamp, | ||
extra_data, | ||
base_fee_per_gas, | ||
block_hash, | ||
transactions, | ||
} = payload; | ||
ExecutionPayloadV1 { | ||
parent_hash, | ||
fee_recipient, | ||
state_root, | ||
receipts_root, | ||
logs_bloom, | ||
prev_randao, | ||
block_number, | ||
gas_limit, | ||
gas_used, | ||
timestamp, | ||
extra_data, | ||
base_fee_per_gas, | ||
block_hash, | ||
transactions, | ||
} | ||
} | ||
} | ||
|
||
/// A helper serde module to convert from/to the Beacon API which uses quoted decimals rather than | ||
/// big-endian hex. | ||
pub mod beacon_payload_v1 { | ||
use super::*; | ||
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
|
||
/// Serialize the payload attributes for the beacon API. | ||
pub fn serialize<S>(payload_attributes: &Withdrawal, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
todo!() | ||
} | ||
|
||
/// Deserialize the payload attributes for the beacon API. | ||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Withdrawal, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.