hopr_transport_probe/
db_proxy.rs

1use async_trait::async_trait;
2use hopr_api::{
3    chain::ChainKeyOperations,
4    db::{FoundSurb, HoprDbProtocolOperations},
5};
6
7use crate::traits::DbOperations;
8
9#[derive(Debug, Clone)]
10pub struct DbProxy<T, R> {
11    db: T,
12    resolver: R,
13}
14
15impl<T, R> DbProxy<T, R> {
16    pub fn new(db: T, resolver: R) -> Self {
17        Self { db, resolver }
18    }
19}
20
21#[async_trait]
22impl<T, R> DbOperations for DbProxy<T, R>
23where
24    T: HoprDbProtocolOperations + Clone + Send + Sync + 'static,
25    R: ChainKeyOperations + Clone + Send + Sync + 'static,
26{
27    type ChainError = R::Error;
28    type DbError = T::Error;
29
30    async fn find_surb(&self, matcher: hopr_network_types::types::SurbMatcher) -> Result<FoundSurb, T::Error> {
31        tracing::trace!(target: "db_proxy", ?matcher, "finding SURB with matcher");
32        self.db.find_surb(matcher).await
33    }
34
35    async fn resolve_chain_key(
36        &self,
37        offchain_key: &hopr_crypto_types::types::OffchainPublicKey,
38    ) -> Result<Option<hopr_primitive_types::prelude::Address>, R::Error> {
39        self.resolver.packet_key_to_chain_key(offchain_key).await
40    }
41}