keyforkd: clone internal Arc instead of external struct holding Arc

This commit is contained in:
Ryan Heywood 2023-09-07 12:40:17 -05:00
parent 88dd6476df
commit c39d8343c7
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 5 additions and 2 deletions

View File

@ -4,6 +4,9 @@ use keyfork_derive_util::request::{DerivationError, DerivationRequest, Derivatio
use keyfork_mnemonic_util::Mnemonic; use keyfork_mnemonic_util::Mnemonic;
use tower::Service; use tower::Service;
// NOTE: All values implemented in Keyforkd must implement Clone with low overhead, either by
// using an Arc or by having a small signature. This is because Service<T> takes &mut self.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Keyforkd { pub struct Keyforkd {
mnemonic: Arc<Mnemonic>, mnemonic: Arc<Mnemonic>,
@ -33,7 +36,7 @@ impl Service<DerivationRequest> for Keyforkd {
#[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))]
fn call(&mut self, req: DerivationRequest) -> Self::Future { fn call(&mut self, req: DerivationRequest) -> Self::Future {
let app = self.clone(); let mnemonic = self.mnemonic.clone();
Box::pin(async { req.derive_with_mnemonic(&app.mnemonic) }) Box::pin(async { req.derive_with_mnemonic(&mnemonic) })
} }
} }