2022-08-16 22:59:07 +00:00
|
|
|
use eyre::Result;
|
|
|
|
use serde::de::Error;
|
2022-08-20 20:33:32 +00:00
|
|
|
use ssz_rs::prelude::*;
|
|
|
|
|
2022-08-29 17:31:17 +00:00
|
|
|
use common::types::Bytes32;
|
|
|
|
use common::utils::hex_str_to_bytes;
|
2022-08-16 22:59:07 +00:00
|
|
|
|
|
|
|
pub type BLSPubKey = Vector<u8, 48>;
|
2022-08-17 21:25:08 +00:00
|
|
|
pub type SignatureBytes = Vector<u8, 96>;
|
|
|
|
pub type Address = Vector<u8, 20>;
|
|
|
|
pub type LogsBloom = Vector<u8, 256>;
|
|
|
|
pub type Transaction = List<u8, 1073741824>;
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
pub struct BeaconBlock {
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub slot: u64,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub proposer_index: u64,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub parent_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub state_root: Bytes32,
|
|
|
|
pub body: BeaconBlockBody,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
pub struct BeaconBlockBody {
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
randao_reveal: SignatureBytes,
|
|
|
|
eth1_data: Eth1Data,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
graffiti: Bytes32,
|
2022-09-14 21:21:09 +00:00
|
|
|
proposer_slashings: List<ProposerSlashing, 16>,
|
|
|
|
attester_slashings: List<AttesterSlashing, 2>,
|
2022-08-17 21:25:08 +00:00
|
|
|
attestations: List<Attestation, 128>,
|
2022-08-31 21:40:44 +00:00
|
|
|
deposits: List<Deposit, 16>,
|
2022-09-14 21:21:09 +00:00
|
|
|
voluntary_exits: List<SignedVoluntaryExit, 16>,
|
2022-08-17 21:25:08 +00:00
|
|
|
sync_aggregate: SyncAggregate,
|
|
|
|
pub execution_payload: ExecutionPayload,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
pub struct ExecutionPayload {
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub parent_hash: Bytes32,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "address_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub fee_recipient: Address,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub state_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub receipts_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "logs_bloom_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub logs_bloom: Vector<u8, 256>,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub prev_randao: Bytes32,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub block_number: u64,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub gas_limit: u64,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub gas_used: u64,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub timestamp: u64,
|
2022-08-20 20:33:32 +00:00
|
|
|
#[serde(deserialize_with = "extra_data_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub extra_data: List<u8, 32>,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "u256_deserialize")]
|
2022-08-29 15:59:02 +00:00
|
|
|
pub base_fee_per_gas: U256,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub block_hash: Bytes32,
|
|
|
|
#[serde(deserialize_with = "transactions_deserialize")]
|
2022-08-31 21:40:44 +00:00
|
|
|
pub transactions: List<Transaction, 1048576>,
|
2022-08-17 21:25:08 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 21:21:09 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct ProposerSlashing {
|
|
|
|
signed_header_1: SignedBeaconBlockHeader,
|
|
|
|
signed_header_2: SignedBeaconBlockHeader,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct SignedBeaconBlockHeader {
|
|
|
|
message: BeaconBlockHeader,
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
signature: SignatureBytes,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct BeaconBlockHeader {
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
slot: u64,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
proposer_index: u64,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
parent_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
state_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
body_root: Bytes32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct AttesterSlashing {
|
|
|
|
attestation_1: IndexedAttestation,
|
|
|
|
attestation_2: IndexedAttestation,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct IndexedAttestation {
|
|
|
|
#[serde(deserialize_with = "attesting_indices_deserialize")]
|
|
|
|
attesting_indices: List<u64, 2048>,
|
|
|
|
data: AttestationData,
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
signature: SignatureBytes,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
struct Attestation {
|
|
|
|
aggregation_bits: Bitlist<2048>,
|
|
|
|
data: AttestationData,
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
signature: SignatureBytes,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
struct AttestationData {
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
slot: u64,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
index: u64,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
beacon_block_root: Bytes32,
|
|
|
|
source: Checkpoint,
|
|
|
|
target: Checkpoint,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
struct Checkpoint {
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
epoch: u64,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
root: Bytes32,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-09-14 21:21:09 +00:00
|
|
|
struct SignedVoluntaryExit {
|
|
|
|
message: VoluntaryExit,
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
signature: SignatureBytes,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct VoluntaryExit {
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
epoch: u64,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
validator_index: u64,
|
2022-08-17 21:25:08 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 21:40:44 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
|
|
|
struct Deposit {
|
|
|
|
#[serde(deserialize_with = "bytes_vector_deserialize")]
|
|
|
|
proof: Vector<Bytes32, 33>,
|
|
|
|
data: DepositData,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Default, Debug, SimpleSerialize, Clone)]
|
|
|
|
struct DepositData {
|
|
|
|
#[serde(deserialize_with = "pubkey_deserialize")]
|
|
|
|
pubkey: BLSPubKey,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
withdrawal_credentials: Bytes32,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
amount: u64,
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
signature: SignatureBytes,
|
|
|
|
}
|
|
|
|
|
2022-08-26 01:18:47 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Default, SimpleSerialize, Clone)]
|
2022-08-17 21:25:08 +00:00
|
|
|
pub struct Eth1Data {
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
deposit_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
2022-08-20 20:33:32 +00:00
|
|
|
deposit_count: u64,
|
2022-08-17 21:25:08 +00:00
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
block_hash: Bytes32,
|
|
|
|
}
|
2022-08-16 22:59:07 +00:00
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug)]
|
|
|
|
pub struct Bootstrap {
|
|
|
|
pub header: Header,
|
|
|
|
pub current_sync_committee: SyncCommittee,
|
|
|
|
#[serde(deserialize_with = "branch_deserialize")]
|
|
|
|
pub current_sync_committee_branch: Vec<Bytes32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug, Clone)]
|
|
|
|
pub struct Update {
|
|
|
|
pub attested_header: Header,
|
2022-08-31 00:31:58 +00:00
|
|
|
pub next_sync_committee: SyncCommittee,
|
2022-08-16 22:59:07 +00:00
|
|
|
#[serde(deserialize_with = "branch_deserialize")]
|
|
|
|
pub next_sync_committee_branch: Vec<Bytes32>,
|
|
|
|
pub finalized_header: Header,
|
|
|
|
#[serde(deserialize_with = "branch_deserialize")]
|
|
|
|
pub finality_branch: Vec<Bytes32>,
|
|
|
|
pub sync_aggregate: SyncAggregate,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub signature_slot: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, Debug)]
|
|
|
|
pub struct FinalityUpdate {
|
|
|
|
pub attested_header: Header,
|
|
|
|
pub finalized_header: Header,
|
|
|
|
#[serde(deserialize_with = "branch_deserialize")]
|
|
|
|
pub finality_branch: Vec<Bytes32>,
|
|
|
|
pub sync_aggregate: SyncAggregate,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub signature_slot: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-31 00:31:58 +00:00
|
|
|
#[derive(serde::Deserialize, Debug)]
|
|
|
|
pub struct OptimisticUpdate {
|
|
|
|
pub attested_header: Header,
|
|
|
|
pub sync_aggregate: SyncAggregate,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub signature_slot: u64,
|
|
|
|
}
|
|
|
|
|
2022-08-16 22:59:07 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Clone, Default, SimpleSerialize)]
|
|
|
|
pub struct Header {
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub slot: u64,
|
|
|
|
#[serde(deserialize_with = "u64_deserialize")]
|
|
|
|
pub proposer_index: u64,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub parent_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub state_root: Bytes32,
|
|
|
|
#[serde(deserialize_with = "bytes32_deserialize")]
|
|
|
|
pub body_root: Bytes32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Default, SimpleSerialize, serde::Deserialize)]
|
|
|
|
pub struct SyncCommittee {
|
|
|
|
#[serde(deserialize_with = "pubkeys_deserialize")]
|
|
|
|
pub pubkeys: Vector<BLSPubKey, 512>,
|
|
|
|
#[serde(deserialize_with = "pubkey_deserialize")]
|
|
|
|
pub aggregate_pubkey: BLSPubKey,
|
|
|
|
}
|
|
|
|
|
2022-08-17 21:25:08 +00:00
|
|
|
#[derive(serde::Deserialize, Debug, Clone, Default, SimpleSerialize)]
|
2022-08-16 22:59:07 +00:00
|
|
|
pub struct SyncAggregate {
|
2022-08-17 21:25:08 +00:00
|
|
|
pub sync_committee_bits: Bitvector<512>,
|
|
|
|
#[serde(deserialize_with = "signature_deserialize")]
|
|
|
|
pub sync_committee_signature: SignatureBytes,
|
|
|
|
}
|
|
|
|
|
2022-09-28 20:48:24 +00:00
|
|
|
pub struct GenericUpdate {
|
|
|
|
pub attested_header: Header,
|
|
|
|
pub sync_aggregate: SyncAggregate,
|
|
|
|
pub signature_slot: u64,
|
|
|
|
pub next_sync_committee: Option<SyncCommittee>,
|
|
|
|
pub next_sync_committee_branch: Option<Vec<Bytes32>>,
|
|
|
|
pub finalized_header: Option<Header>,
|
|
|
|
pub finality_branch: Option<Vec<Bytes32>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&Update> for GenericUpdate {
|
|
|
|
fn from(update: &Update) -> Self {
|
|
|
|
Self {
|
|
|
|
attested_header: update.attested_header.clone(),
|
|
|
|
sync_aggregate: update.sync_aggregate.clone(),
|
|
|
|
signature_slot: update.signature_slot.clone(),
|
|
|
|
next_sync_committee: Some(update.next_sync_committee.clone()),
|
|
|
|
next_sync_committee_branch: Some(update.next_sync_committee_branch.clone()),
|
|
|
|
finalized_header: Some(update.finalized_header.clone()),
|
|
|
|
finality_branch: Some(update.finality_branch.clone()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&FinalityUpdate> for GenericUpdate {
|
|
|
|
fn from(update: &FinalityUpdate) -> Self {
|
|
|
|
Self {
|
|
|
|
attested_header: update.attested_header.clone(),
|
|
|
|
sync_aggregate: update.sync_aggregate.clone(),
|
|
|
|
signature_slot: update.signature_slot.clone(),
|
|
|
|
next_sync_committee: None,
|
|
|
|
next_sync_committee_branch: None,
|
|
|
|
finalized_header: Some(update.finalized_header.clone()),
|
|
|
|
finality_branch: Some(update.finality_branch.clone()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&OptimisticUpdate> for GenericUpdate {
|
|
|
|
fn from(update: &OptimisticUpdate) -> Self {
|
|
|
|
Self {
|
|
|
|
attested_header: update.attested_header.clone(),
|
|
|
|
sync_aggregate: update.sync_aggregate.clone(),
|
|
|
|
signature_slot: update.signature_slot.clone(),
|
|
|
|
next_sync_committee: None,
|
|
|
|
next_sync_committee_branch: None,
|
|
|
|
finalized_header: None,
|
|
|
|
finality_branch: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn pubkey_deserialize<'de, D>(deserializer: D) -> Result<BLSPubKey, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-16 22:59:07 +00:00
|
|
|
let key: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let key_bytes = hex_str_to_bytes(&key).map_err(D::Error::custom)?;
|
|
|
|
Ok(Vector::from_iter(key_bytes))
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn pubkeys_deserialize<'de, D>(deserializer: D) -> Result<Vector<BLSPubKey, 512>, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-16 22:59:07 +00:00
|
|
|
let keys: Vec<String> = serde::Deserialize::deserialize(deserializer)?;
|
2022-08-20 20:33:32 +00:00
|
|
|
Ok(keys
|
|
|
|
.iter()
|
|
|
|
.map(|key| {
|
|
|
|
let key_bytes = hex_str_to_bytes(key)?;
|
|
|
|
Ok(Vector::from_iter(key_bytes))
|
|
|
|
})
|
|
|
|
.collect::<Result<Vector<BLSPubKey, 512>>>()
|
|
|
|
.map_err(D::Error::custom)?)
|
|
|
|
}
|
|
|
|
|
2022-08-31 21:40:44 +00:00
|
|
|
fn bytes_vector_deserialize<'de, D>(deserializer: D) -> Result<Vector<Bytes32, 33>, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
|
|
|
let elems: Vec<String> = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
Ok(elems
|
|
|
|
.iter()
|
|
|
|
.map(|elem| {
|
|
|
|
let elem_bytes = hex_str_to_bytes(elem)?;
|
|
|
|
Ok(Vector::from_iter(elem_bytes))
|
|
|
|
})
|
|
|
|
.collect::<Result<Vector<Bytes32, 33>>>()
|
|
|
|
.map_err(D::Error::custom)?)
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn signature_deserialize<'de, D>(deserializer: D) -> Result<SignatureBytes, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-17 21:25:08 +00:00
|
|
|
let sig: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let sig_bytes = hex_str_to_bytes(&sig).map_err(D::Error::custom)?;
|
|
|
|
Ok(Vector::from_iter(sig_bytes))
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn branch_deserialize<'de, D>(deserializer: D) -> Result<Vec<Bytes32>, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-16 22:59:07 +00:00
|
|
|
let branch: Vec<String> = serde::Deserialize::deserialize(deserializer)?;
|
2022-08-20 20:33:32 +00:00
|
|
|
Ok(branch
|
|
|
|
.iter()
|
|
|
|
.map(|elem| {
|
|
|
|
let elem_bytes = hex_str_to_bytes(elem)?;
|
|
|
|
Ok(Vector::from_iter(elem_bytes))
|
|
|
|
})
|
|
|
|
.collect::<Result<_>>()
|
|
|
|
.map_err(D::Error::custom)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn u64_deserialize<'de, D>(deserializer: D) -> Result<u64, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-16 22:59:07 +00:00
|
|
|
let val: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
Ok(val.parse().unwrap())
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn u256_deserialize<'de, D>(deserializer: D) -> Result<U256, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-17 21:25:08 +00:00
|
|
|
let val: String = serde::Deserialize::deserialize(deserializer)?;
|
2022-09-14 21:21:09 +00:00
|
|
|
let x = ethers::types::U256::from_dec_str(&val).map_err(D::Error::custom)?;
|
|
|
|
let mut x_bytes = [0; 32];
|
|
|
|
x.to_little_endian(&mut x_bytes);
|
|
|
|
Ok(U256::from_bytes_le(x_bytes))
|
2022-08-17 21:25:08 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn bytes32_deserialize<'de, D>(deserializer: D) -> Result<Bytes32, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-16 22:59:07 +00:00
|
|
|
let bytes: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let bytes = hex::decode(bytes.strip_prefix("0x").unwrap()).unwrap();
|
|
|
|
Ok(bytes.to_vec().try_into().unwrap())
|
|
|
|
}
|
2022-08-17 21:25:08 +00:00
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn logs_bloom_deserialize<'de, D>(deserializer: D) -> Result<LogsBloom, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-17 21:25:08 +00:00
|
|
|
let bytes: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let bytes = hex::decode(bytes.strip_prefix("0x").unwrap()).unwrap();
|
|
|
|
Ok(bytes.to_vec().try_into().unwrap())
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn address_deserialize<'de, D>(deserializer: D) -> Result<Address, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-17 21:25:08 +00:00
|
|
|
let bytes: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let bytes = hex::decode(bytes.strip_prefix("0x").unwrap()).unwrap();
|
|
|
|
Ok(bytes.to_vec().try_into().unwrap())
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn extra_data_deserialize<'de, D>(deserializer: D) -> Result<List<u8, 32>, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-17 21:25:08 +00:00
|
|
|
let bytes: String = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let bytes = hex::decode(bytes.strip_prefix("0x").unwrap()).unwrap();
|
|
|
|
Ok(bytes.to_vec().try_into().unwrap())
|
|
|
|
}
|
|
|
|
|
2022-08-20 20:33:32 +00:00
|
|
|
fn transactions_deserialize<'de, D>(deserializer: D) -> Result<List<Transaction, 1048576>, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
2022-08-17 21:25:08 +00:00
|
|
|
let transactions: Vec<String> = serde::Deserialize::deserialize(deserializer)?;
|
2022-08-20 20:33:32 +00:00
|
|
|
let transactions = transactions
|
|
|
|
.iter()
|
|
|
|
.map(|tx| {
|
|
|
|
let tx = hex_str_to_bytes(tx).unwrap();
|
|
|
|
let tx: Transaction = List::from_iter(tx);
|
|
|
|
tx
|
|
|
|
})
|
|
|
|
.collect::<List<Transaction, 1048576>>();
|
2022-08-17 21:25:08 +00:00
|
|
|
Ok(transactions)
|
|
|
|
}
|
2022-09-14 21:21:09 +00:00
|
|
|
|
|
|
|
fn attesting_indices_deserialize<'de, D>(deserializer: D) -> Result<List<u64, 2048>, D::Error>
|
|
|
|
where
|
|
|
|
D: serde::Deserializer<'de>,
|
|
|
|
{
|
|
|
|
let attesting_indices: Vec<String> = serde::Deserialize::deserialize(deserializer)?;
|
|
|
|
let attesting_indices = attesting_indices
|
|
|
|
.iter()
|
|
|
|
.map(|i| i.parse().unwrap())
|
|
|
|
.collect::<List<u64, 2048>>();
|
|
|
|
|
|
|
|
Ok(attesting_indices)
|
|
|
|
}
|