diff --git a/src/block_metadata.rs b/src/block_metadata.rs index b081cb3..d6d6dae 100644 --- a/src/block_metadata.rs +++ b/src/block_metadata.rs @@ -5,11 +5,15 @@ use hotshot_types::traits::{node_implementation::NodeType, BlockPayload}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -pub struct HashableBlock(::BlockPayload, <::BlockPayload as BlockPayload>::Metadata); +pub struct HashableBlock( + ::BlockPayload, + <::BlockPayload as BlockPayload>::Metadata, +); pub type BlockHash = Commitment>; impl Default for HashableBlock { fn default() -> Self { - let (bp, bm) = ::BlockPayload::from_transactions(Vec::new()).unwrap_or_else(|_|::BlockPayload::genesis()); + let (bp, bm) = ::BlockPayload::from_transactions(Vec::new()) + .unwrap_or_else(|_| ::BlockPayload::genesis()); Self(bp, bm) } } @@ -37,4 +41,3 @@ pub struct BlockMetadata { offered_fee: u64, _phantom: PhantomData, } - diff --git a/src/builder.rs b/src/builder.rs index bfc6ec9..020d922 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -3,13 +3,20 @@ use std::{fmt::Display, path::PathBuf}; use clap::Args; use derive_more::From; use futures::FutureExt; -use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey}}; +use hotshot_types::{ + data::VidCommitment, + traits::{node_implementation::NodeType, signature_key::SignatureKey}, +}; use serde::{Deserialize, Serialize}; use snafu::{OptionExt, ResultExt, Snafu}; use tagged_base64::TaggedBase64; use tide_disco::{api::ApiError, method::ReadState, Api, RequestError, StatusCode}; -use crate::{api::load_api, block_metadata::BlockHash, data_source::{self, BuilderDataSource}}; +use crate::{ + api::load_api, + block_metadata::BlockHash, + data_source::{self, BuilderDataSource}, +}; #[derive(Args, Default)] pub struct Options { @@ -40,7 +47,6 @@ pub enum BuildError { Error { message: String }, } - #[derive(Clone, Debug, From, Snafu, Deserialize, Serialize)] #[snafu(visibility(pub))] pub enum Error { @@ -65,14 +71,16 @@ pub enum Error { }, } - pub fn define_api(options: &Options) -> Result, ApiError> where State: 'static + Send + Sync + ReadState, ::State: Send + Sync + BuilderDataSource, Types: NodeType, - <::SignatureKey as SignatureKey>::PureAssembledSignatureType: for<'a> TryFrom<&'a TaggedBase64> + Into + Display, - for<'a> <<::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom<&'a TaggedBase64>>::Error: Display, + <::SignatureKey as SignatureKey>::PureAssembledSignatureType: + for<'a> TryFrom<&'a TaggedBase64> + Into + Display, + for<'a> <<::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom< + &'a TaggedBase64, + >>::Error: Display, { let mut api = load_api::( options.api_path.as_ref(), @@ -83,9 +91,12 @@ where .get("available_blocks", |req, state| { async move { let hash = req.blob_param("parent_hash")?; - state.get_available_blocks(&hash).await.context(BlockAvailableSnafu { - resource: hash.to_string(), - }) + state + .get_available_blocks(&hash) + .await + .context(BlockAvailableSnafu { + resource: hash.to_string(), + }) } .boxed() })? @@ -93,11 +104,14 @@ where async move { let hash = req.blob_param("block_hash")?; let signature = req.blob_param("signature")?; - state.claim_block(&hash, &signature).await.context(BlockClaimSnafu { - resource: hash.to_string(), - }) + state + .claim_block(&hash, &signature) + .await + .context(BlockClaimSnafu { + resource: hash.to_string(), + }) } .boxed() })?; Ok(api) -} \ No newline at end of file +} diff --git a/src/data_source.rs b/src/data_source.rs index 49d394e..664f285 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -2,18 +2,32 @@ use std::sync::Arc; use async_trait::async_trait; use commit::Committable; -use hotshot_types::{data::VidCommitment, traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload}}; +use hotshot_types::{ + data::VidCommitment, + traits::{node_implementation::NodeType, signature_key::SignatureKey, BlockPayload}, +}; use tagged_base64::TaggedBase64; -use crate::{block_metadata::{BlockHash, BlockMetadata}, builder::BuildError}; +use crate::{ + block_metadata::{BlockHash, BlockMetadata}, + builder::BuildError, +}; #[async_trait] pub trait BuilderDataSource -where I: NodeType, - <::SignatureKey as SignatureKey>::PureAssembledSignatureType: for<'a> TryFrom<&'a TaggedBase64> + Into - { - async fn get_available_blocks(&self, for_parent: &VidCommitment) -> Result>, BuildError>; - async fn claim_block(&self, block_hash: &BlockHash, signature: &<::SignatureKey as SignatureKey>::PureAssembledSignatureType) -> Result; +where + I: NodeType, + <::SignatureKey as SignatureKey>::PureAssembledSignatureType: + for<'a> TryFrom<&'a TaggedBase64> + Into, +{ + async fn get_available_blocks( + &self, + for_parent: &VidCommitment, + ) -> Result>, BuildError>; + async fn claim_block( + &self, + block_hash: &BlockHash, + signature: &<::SignatureKey as SignatureKey>::PureAssembledSignatureType, + ) -> Result; async fn submit_txn(&self, txn: ::Transaction) -> Result<(), BuildError>; } - diff --git a/src/lib.rs b/src/lib.rs index 2493f5a..8a52c67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ +mod api; pub mod block_metadata; pub mod builder; pub mod data_source; pub mod query_data; -mod api; diff --git a/src/query_data.rs b/src/query_data.rs index b2bb9e9..602a329 100644 --- a/src/query_data.rs +++ b/src/query_data.rs @@ -3,7 +3,6 @@ // // TODO: License - use hotshot_types::traits::node_implementation::NodeType; use serde::{Deserialize, Serialize};