use ed25519_dalek::{PublicKey, SecretKey};
use crate::bitfield::Bitfield;
use crate::crypto::Merkle;
use crate::storage::Storage;
use failure::Error;
use random_access_storage::RandomAccess;
use std::fmt::Debug;
use tree_index::TreeIndex;
use crate::Feed;
use crate::Result;
#[derive(Debug)]
pub struct FeedBuilder<T>
where
T: RandomAccess + Debug,
{
storage: Storage<T>,
public_key: PublicKey,
secret_key: Option<SecretKey>,
}
impl<T> FeedBuilder<T>
where
T: RandomAccess<Error = Error> + Debug,
{
#[inline]
pub fn new(public_key: PublicKey, storage: Storage<T>) -> Self {
Self {
storage,
public_key,
secret_key: None,
}
}
pub fn secret_key(mut self, secret_key: SecretKey) -> Self {
self.secret_key = Some(secret_key);
self
}
#[inline]
pub fn build(self) -> Result<Feed<T>> {
Ok(Feed {
merkle: Merkle::new(),
byte_length: 0,
length: 0,
bitfield: Bitfield::default(),
tree: TreeIndex::default(),
public_key: self.public_key,
secret_key: self.secret_key,
storage: self.storage,
peers: vec![],
})
}
}