fatline-rs 0.2.1

Farcaster grpc client and utility library
Documentation
use async_trait::async_trait;
use tonic::Response;
use crate::error::DataType::Fids;
use crate::error::FatlineError;
use crate::HubService;
use crate::proto::{FidsRequest, FidsResponse};

#[async_trait]
pub trait HubInfoService {
    async fn get_current_fid_count(&mut self) -> Result<u64, FatlineError>;
}

#[async_trait]
impl HubInfoService for HubService {
    async fn get_current_fid_count(&mut self) -> Result<u64, FatlineError> {
        self.get_fids(FidsRequest {
            reverse: Some(true),
            page_token: None,
            page_size: Some(1)
        }).await
            .map_err(FatlineError::ClientError)
            .and_then(get_last_fid)
    }
}

fn get_last_fid(res: Response<FidsResponse>) -> Result<u64, FatlineError> {
    match res.into_inner().fids.last() {
        Some(value) => Ok(value.to_owned()),
        _ => Err(FatlineError::NoDataAvailable(Fids))
    }
}