use std::{future::Future, pin::Pin, sync::Arc, task::Poll}; use keyfork_derive_util::request::{DerivationError, DerivationRequest, DerivationResponse}; use keyfork_mnemonic_util::Mnemonic; use tower::Service; #[derive(Clone, Debug)] pub struct Keyforkd { mnemonic: Arc, } impl Keyforkd { pub fn new(mnemonic: Mnemonic) -> Self { Self { mnemonic: Arc::new(mnemonic), } } } impl Service for Keyforkd { type Response = DerivationResponse; type Error = DerivationError; type Future = Pin> + Send>>; fn poll_ready( &mut self, _cx: &mut std::task::Context<'_>, ) -> std::task::Poll> { 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) }) } }