breez_sdk_spark/session_store/
adapter.rs1use std::sync::Arc;
2
3use bitcoin::secp256k1::PublicKey;
4
5use super::SessionStore;
6
7pub struct SessionStoreAdapter(pub Arc<dyn SessionStore>);
13
14impl SessionStoreAdapter {
15 #[must_use]
18 pub fn new(inner: Arc<dyn SessionStore>) -> Self {
19 Self(inner)
20 }
21}
22
23#[macros::async_trait]
24impl spark_wallet::SessionStore for SessionStoreAdapter {
25 async fn get_session(
26 &self,
27 service_identity_key: &PublicKey,
28 ) -> Result<spark_wallet::Session, spark_wallet::SessionStoreError> {
29 self.0
30 .get_session(*service_identity_key)
31 .await
32 .map(Into::into)
33 .map_err(Into::into)
34 }
35
36 async fn set_session(
37 &self,
38 service_identity_key: &PublicKey,
39 session: spark_wallet::Session,
40 ) -> Result<(), spark_wallet::SessionStoreError> {
41 self.0
42 .set_session(*service_identity_key, session.into())
43 .await
44 .map_err(Into::into)
45 }
46}
47
48pub(crate) struct SparkSessionStoreAdapter(pub(crate) Arc<dyn spark_wallet::SessionStore>);
53
54#[macros::async_trait]
55impl SessionStore for SparkSessionStoreAdapter {
56 async fn get_session(
57 &self,
58 service_identity_key: PublicKey,
59 ) -> Result<super::Session, super::SessionStoreError> {
60 self.0
61 .get_session(&service_identity_key)
62 .await
63 .map(Into::into)
64 .map_err(Into::into)
65 }
66
67 async fn set_session(
68 &self,
69 service_identity_key: PublicKey,
70 session: super::Session,
71 ) -> Result<(), super::SessionStoreError> {
72 self.0
73 .set_session(&service_identity_key, session.into())
74 .await
75 .map_err(Into::into)
76 }
77}