Skip to content

Commit 1ea500d

Browse files
committed
graph, store: Move looking up ENS names into its own trait
1 parent f76912a commit 1ea500d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

graph/src/components/store.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,12 +912,18 @@ impl Display for DeploymentLocator {
912912
}
913913
}
914914

915+
/// A special trait to handle looking up ENS names from special rainbow
916+
/// tables that need to be manually loaded into the system
917+
pub trait EnsLookup: Send + Sync + 'static {
918+
/// Find the reverse of keccak256 for `hash` through looking it up in the
919+
/// rainbow table.
920+
fn find_name(&self, hash: &str) -> Result<Option<String>, StoreError>;
921+
}
922+
915923
/// Common trait for store implementations.
916924
#[async_trait]
917925
pub trait SubgraphStore: Send + Sync + 'static {
918-
/// Find the reverse of keccak256 for `hash` through looking it up in the
919-
/// rainbow table.
920-
fn find_ens_name(&self, _hash: &str) -> Result<Option<String>, StoreError>;
926+
fn ens_lookup(&self) -> Arc<dyn EnsLookup>;
921927

922928
/// Check if the store is accepting queries for the specified subgraph.
923929
/// May return true even if the specified subgraph is not currently assigned to an indexing
@@ -1121,7 +1127,7 @@ pub type PoolWaitStats = Arc<RwLock<MovingStats>>;
11211127
// The store trait must be implemented manually because mockall does not support async_trait, nor borrowing from arguments.
11221128
#[async_trait]
11231129
impl SubgraphStore for MockStore {
1124-
fn find_ens_name(&self, _hash: &str) -> Result<Option<String>, StoreError> {
1130+
fn ens_lookup(&self) -> Arc<dyn EnsLookup> {
11251131
unimplemented!()
11261132
}
11271133

store/postgres/src/subgraph_store.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use graph::{
1212
cheap_clone::CheapClone,
1313
components::{
1414
server::index_node::VersionInfo,
15-
store::{self, DeploymentLocator, EntityType, WritableStore as WritableStoreTrait},
15+
store::{
16+
self, DeploymentLocator, EnsLookup as EnsLookupTrait, EntityType,
17+
WritableStore as WritableStoreTrait,
18+
},
1619
},
1720
constraint_violation,
1821
data::query::QueryTarget,
@@ -944,10 +947,23 @@ impl SubgraphStoreInner {
944947
}
945948
}
946949

950+
struct EnsLookup {
951+
primary: ConnectionPool,
952+
}
953+
954+
impl EnsLookupTrait for EnsLookup {
955+
fn find_name(&self, hash: &str) -> Result<Option<String>, StoreError> {
956+
let conn = self.primary.get()?;
957+
primary::Connection::new(conn).find_ens_name(hash)
958+
}
959+
}
960+
947961
#[async_trait::async_trait]
948962
impl SubgraphStoreTrait for SubgraphStore {
949-
fn find_ens_name(&self, hash: &str) -> Result<Option<String>, StoreError> {
950-
self.primary_conn()?.find_ens_name(hash)
963+
fn ens_lookup(&self) -> Arc<dyn EnsLookupTrait> {
964+
Arc::new(EnsLookup {
965+
primary: self.mirror.primary().clone(),
966+
})
951967
}
952968

953969
// FIXME: This method should not get a node_id

0 commit comments

Comments
 (0)