Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Support conversion from grpc response to beacon block #20

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target

Cargo.lock

.DS_Store
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ pub mod firehose {
pub mod beacon {
pub mod r#type {
pub mod v1 {
use crate::{firehose::v2::SingleBlockResponse, ProtosError};
use crate::{
firehose::v2::{Response, SingleBlockResponse},
ProtosError,
};
use primitive_types::{H256, U256};
use prost::Message;
use ssz_types::{length::Fixed, Bitfield, FixedVector};
Expand Down Expand Up @@ -545,6 +548,16 @@ pub mod beacon {
}
}

impl TryFrom<Response> for Block {
type Error = ProtosError;

fn try_from(response: Response) -> Result<Self, Self::Error> {
let any = response.block.ok_or(ProtosError::NullBlock)?;
let block = Block::decode(any.value.as_ref())?;
Ok(block)
}
}

impl<E: EthSpec> TryFrom<SyncAggregate> for types::SyncAggregate<E> {
type Error = ProtosError;

Expand Down
Loading