keyfork/keyforkd/src/service.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

2023-08-25 06:32:21 +00:00
use std::{future::Future, pin::Pin, task::Poll, sync::Arc};
use keyfork_mnemonic_util::Mnemonic;
2023-08-25 09:27:16 +00:00
use keyfork_derive_util::DerivablePath;
2023-08-25 06:32:21 +00:00
use tower::Service;
use thiserror::Error;
#[derive(Clone, Debug)]
pub struct Keyforkd {
mnemonic: Arc<Mnemonic>,
}
// Currently, this can't be instantiated, therefore it is a never-type
#[derive(Debug, Error)]
pub enum DerivationError {
}
impl Keyforkd {
pub fn new(mnemonic: Mnemonic) -> Self {
Self { mnemonic: Arc::new(mnemonic) }
}
}
impl Service<DerivablePath> for Keyforkd {
type Response = Vec<u8>;
type Error = DerivationError;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(
&mut self,
_cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))]
fn call(&mut self, req: DerivablePath) -> Self::Future {
dbg!(&req, &self.mnemonic);
Box::pin(async { Ok(vec![]) })
}
}