keyfork/keyforkd/src/service.rs

40 lines
1.0 KiB
Rust
Raw Normal View History

2023-08-25 09:28:47 +00:00
use std::{future::Future, pin::Pin, sync::Arc, task::Poll};
2023-08-25 06:32:21 +00:00
use keyfork_derive_util::request::{DerivationError, DerivationRequest, DerivationResponse};
2023-08-25 09:28:47 +00:00
use keyfork_mnemonic_util::Mnemonic;
use tower::Service;
2023-08-25 06:32:21 +00:00
#[derive(Clone, Debug)]
pub struct Keyforkd {
mnemonic: Arc<Mnemonic>,
}
impl Keyforkd {
pub fn new(mnemonic: Mnemonic) -> Self {
2023-08-25 09:28:47 +00:00
Self {
mnemonic: Arc::new(mnemonic),
}
2023-08-25 06:32:21 +00:00
}
}
impl Service<DerivationRequest> for Keyforkd {
type Response = DerivationResponse;
2023-08-25 06:32:21 +00:00
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: DerivationRequest) -> Self::Future {
let app = self.clone();
Box::pin(async { req.derive_with_mnemonic(&app.mnemonic) })
2023-08-25 06:32:21 +00:00
}
}