Skip to content

Commit

Permalink
[#] NextDotID#159 basenames
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongFuze committed Sep 2, 2024
1 parent 182432f commit 4ba03cd
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 31 deletions.
47 changes: 23 additions & 24 deletions src/config/tdb/migrations/LoadingJob_SocialGraph.gsql
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,11 @@ CREATE OR REPLACE QUERY delete_graph_inner_connection(VERTEX<Identities> p, INT
// DELETE e FROM vertex2delete:s-((Hold_Contract>):e)-Contracts:c;
// DELETE e FROM vertex2delete:s-((Reverse_Resolve_Contract>):e)-Contracts:c;
// DELETE e FROM vertex2delete:s-((<Resolve_Contract):e)-Contracts:c;
DELETE e FROM vertex2delete:s-((<Hold_Identity):e)-Identities:t WHERE s.platform != "ens" AND s.platform != "unstoppabledomains";
DELETE e FROM vertex2delete:s-((<Resolve):e)-Identities:t WHERE t.platform != "ens" AND t.platform != "unstoppabledomains";
DELETE e FROM vertex2delete:s-((<Reverse_Resolve):e)-Identities:t WHERE s.platform != "ens" AND s.platform != "unstoppabledomains";
DELETE e FROM vertex2delete:s-((<Proof_Forward):e)-Identities:t;
DELETE e FROM vertex2delete:s-((<Proof_Backward):e)-Identities:t;
// DELETE e FROM vertex2delete:s-((<Hold_Identity):e)-Identities:t WHERE s.platform != "ens" AND s.platform != "unstoppabledomains";
// DELETE e FROM vertex2delete:s-((<Resolve):e)-Identities:t WHERE t.platform != "ens" AND t.platform != "unstoppabledomains";
// DELETE e FROM vertex2delete:s-((<Reverse_Resolve):e)-Identities:t WHERE s.platform != "ens" AND s.platform != "unstoppabledomains";
// DELETE e FROM vertex2delete:s-((<Proof_Forward):e)-Identities:t;
// DELETE e FROM vertex2delete:s-((<Proof_Backward):e)-Identities:t;
}


Expand All @@ -514,8 +514,7 @@ CREATE OR REPLACE QUERY delete_graph_inner_connection_test(VERTEX<Identities> p,

CREATE OR REPLACE QUERY delete_domain_collection(VERTEX<DomainCollection> p) FOR GRAPH SocialGraph {
vertex2delete (DomainCollection) = {p};
DELETE e FROM vertex2delete:s-((PartOfCollection>):e)-Identities:tgt;
DELETE s FROM vertex2delete:s;
DELETE e FROM vertex2delete:s-((PartOfCollection>):e)-Identities:tgt WHERE tgt.platform != "basenames";
}

CREATE OR REPLACE QUERY clear_domain_search_cache() FOR GRAPH SocialGraph {
Expand All @@ -541,7 +540,7 @@ CREATE OR REPLACE QUERY domain_available_search(STRING id) FOR GRAPH SocialGraph

CREATE OR REPLACE QUERY domain_available_search_draft(SET<STRING> names, SET<STRING> ens_names) FOR GRAPH SocialGraph {
TYPEDEF TUPLE< STRING system, STRING name, DATETIME expired_at > DomainResult;
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ens", "sns", "genome", "clusters"];
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ens", "sns", "genome", "clusters", "basenames"];

SetAccum<DomainResult> @@domain_result;
owner = SELECT s FROM Identities:s-((Hold_Identity>):e)-Identities:v
Expand Down Expand Up @@ -579,7 +578,7 @@ CREATE OR REPLACE QUERY find_identity_graph_resolve(STRING platform, STRING iden
PRINT seed;
graph_id = @@minUpdateTime.id;

ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters"];
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters", "basenames"];
ListAccum<STRING> @@edge_type = ["Proof_Forward", "Proof_Backward", "Hold_Identity", "Resolve", "Reverse_Resolve"];

vset = SELECT v FROM Identities:v-((PartOfIdentitiesGraph>):e)-identities_graph LIMIT 500;
Expand Down Expand Up @@ -625,7 +624,7 @@ CREATE OR REPLACE QUERY find_expand_identity(STRING platform, STRING identity) F
SetAccum<Address> @owner_address;
SetAccum<Address> @resolve_address;

ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters"];
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters", "basenames"];
IF @@domainSystems.contains(platform) == TRUE THEN
tmp = SELECT domain FROM seed:domain-((<Hold_Identity):e)-Identities:owner
ACCUM domain.@owner_address += Address(owner.platform, owner.identity);
Expand Down Expand Up @@ -663,7 +662,7 @@ CREATE OR REPLACE QUERY find_identity_graph(STRING p, INT reverse_flag=0) FOR GR
POST-ACCUM s.@degree += 1;
graph_id = @@minUpdateTime.id;

ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters"];
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters", "basenames"];
ListAccum<STRING> @@edge_type = ["Proof_Forward", "Proof_Backward", "Hold_Identity", "Resolve", "Reverse_Resolve"];

IF reverse_flag == 1 THEN
Expand All @@ -675,21 +674,21 @@ CREATE OR REPLACE QUERY find_identity_graph(STRING p, INT reverse_flag=0) FOR GR
tmp2 = SELECT v1 FROM vset:v1-((<Proof_Forward|<Proof_Backward):e2)-vset:v2
ACCUM @@edges += IdentityConnection(v2, v1, e2.source, "Proof"), v1.@degree += 1, v2.@degree += 1;
tmp4 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:i-((Resolve>):e2)-vset:v2
WHERE i.platform != "genome" AND i.platform != "ens" AND i.platform != "sns"
WHERE i.platform != "genome" AND i.platform != "ens" AND i.platform != "sns" AND i.platform != "basenames"
ACCUM @@edges += IdentityConnection(v1, i, e1.source, "Hold"),
i.@owner_address += Address(v1.platform, v1.identity),
i.@resolve_address += Address(v2.platform, v2.identity), v1.@degree += 1, v2.@degree += 1;
tmp5 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:v2
WHERE v2.platform != "genome" AND v2.platform != "ens" AND v2.platform != "sns"
WHERE v2.platform != "genome" AND v2.platform != "ens" AND v2.platform != "sns" AND v2.platform != "basenames"
ACCUM @@edges += IdentityConnection(v1, v2, e1.source, "Hold"),
v2.@owner_address += Address(v1.platform, v1.identity), v1.@degree += 1, v2.@degree += 1;
tmp3 = SELECT v1 FROM vset:v1-((Resolve>):r)-vset:v2
WHERE v1.platform == "genome" OR v1.platform == "ens" OR v1.platform == "sns"
WHERE v1.platform == "genome" OR v1.platform == "ens" OR v1.platform == "sns" OR v1.platform == "basenames"
ACCUM
@@edges += IdentityConnection(v1, v2, r.source, "Resolve"),
v1.@resolve_address += Address(v2.platform, v2.identity), v1.@degree += 1, v2.@degree += 1;
tmp3_1 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:v2
WHERE v2.platform == "genome" OR v2.platform == "ens" OR v2.platform == "sns"
WHERE v2.platform == "genome" OR v2.platform == "ens" OR v2.platform == "sns" OR v2.platform == "basenames"
ACCUM v2.@owner_address += Address(v1.platform, v1.identity);

tmp6 = SELECT v1 FROM vset:v1-((Reverse_Resolve>):e1)-vset:v2
Expand All @@ -706,21 +705,21 @@ CREATE OR REPLACE QUERY find_identity_graph(STRING p, INT reverse_flag=0) FOR GR
tmp2 = SELECT v1 FROM vset:v1-((<Proof_Forward|<Proof_Backward):e2)-vset:v2
ACCUM @@edges += IdentityConnection(v2, v1, e2.source, "Proof"), v1.@degree += 1, v2.@degree += 1;
tmp4 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:i-((Resolve>):e2)-vset:v2
WHERE i.platform != "genome" AND i.platform != "ens" AND i.platform != "sns"
WHERE i.platform != "genome" AND i.platform != "ens" AND i.platform != "sns" AND i.platform != "basenames"
ACCUM @@edges += IdentityConnection(v1, i, e1.source, "Hold"),
i.@owner_address += Address(v1.platform, v1.identity),
i.@resolve_address += Address(v2.platform, v2.identity), v1.@degree += 1, v2.@degree += 1;
tmp5 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:v2
WHERE v2.platform != "genome" AND v2.platform != "ens" AND v2.platform != "sns"
WHERE v2.platform != "genome" AND v2.platform != "ens" AND v2.platform != "sns" AND v2.platform != "basenames"
ACCUM @@edges += IdentityConnection(v1, v2, e1.source, "Hold"),
v2.@owner_address += Address(v1.platform, v1.identity), v1.@degree += 1, v2.@degree += 1;
tmp3 = SELECT v1 FROM vset:v1-((Resolve>):r)-vset:v2
WHERE v1.platform == "genome" OR v1.platform == "ens" OR v1.platform == "sns"
WHERE v1.platform == "genome" OR v1.platform == "ens" OR v1.platform == "sns" OR v1.platform == "basenames"
ACCUM
@@edges += IdentityConnection(v1, v2, r.source, "Resolve"),
v1.@resolve_address += Address(v2.platform, v2.identity), v1.@degree += 1, v2.@degree += 1;
tmp3_1 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:v2
WHERE v2.platform == "genome" OR v2.platform == "ens" OR v2.platform == "sns"
WHERE v2.platform == "genome" OR v2.platform == "ens" OR v2.platform == "sns" OR v2.platform == "basenames"
ACCUM v2.@owner_address += Address(v1.platform, v1.identity);
tmp6 = SELECT v1 FROM vset:v1-((Reverse_Resolve>):e1)-vset:v2
ACCUM @@edges += IdentityConnection(v1, v2, e1.source, "Reverse_Resolve"), v1.@degree += 1, v2.@degree += 1;
Expand All @@ -735,21 +734,21 @@ CREATE OR REPLACE QUERY find_identity_graph(STRING p, INT reverse_flag=0) FOR GR
tmp2 = SELECT v1 FROM vset:v1-((<Proof_Forward|<Proof_Backward):e2)-vset:v2
ACCUM @@edges += IdentityConnection(v2, v1, e2.source, "Proof"), v1.@degree += 1, v2.@degree += 1;
tmp4 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:i-((Resolve>):e2)-vset:v2
WHERE i.platform != "genome" AND i.platform != "ens" AND i.platform != "sns"
WHERE i.platform != "genome" AND i.platform != "ens" AND i.platform != "sns" AND i.platform != "basenames"
ACCUM @@edges += IdentityConnection(v1, i, e1.source, "Hold"),
i.@owner_address += Address(v1.platform, v1.identity),
i.@resolve_address += Address(v2.platform, v2.identity), v1.@degree += 1, v2.@degree += 1;
tmp5 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:v2
WHERE v2.platform != "genome" AND v2.platform != "ens" AND v2.platform != "sns"
WHERE v2.platform != "genome" AND v2.platform != "ens" AND v2.platform != "sns" AND v2.platform != "basenames"
ACCUM @@edges += IdentityConnection(v1, v2, e1.source, "Hold"),
v2.@owner_address += Address(v1.platform, v1.identity), v1.@degree += 1, v2.@degree += 1;
tmp3 = SELECT v1 FROM vset:v1-((Resolve>):r)-vset:v2
WHERE v1.platform == "genome" OR v1.platform == "ens" OR v1.platform == "sns"
WHERE v1.platform == "genome" OR v1.platform == "ens" OR v1.platform == "sns" OR v1.platform == "basenames"
ACCUM
@@edges += IdentityConnection(v1, v2, r.source, "Resolve"),
v1.@resolve_address += Address(v2.platform, v2.identity), v1.@degree += 1, v2.@degree += 1;
tmp3_1 = SELECT v1 FROM vset:v1-((Hold_Identity>):e1)-vset:v2
WHERE v2.platform == "genome" OR v2.platform == "ens" OR v2.platform == "sns"
WHERE v2.platform == "genome" OR v2.platform == "ens" OR v2.platform == "sns" OR v2.platform == "basenames"
ACCUM v2.@owner_address += Address(v1.platform, v1.identity);

tmp6 = SELECT v1 FROM vset:v1-((Reverse_Resolve>):e1)-vset:v2
Expand Down Expand Up @@ -791,7 +790,7 @@ CREATE OR REPLACE QUERY neighbors_with_source_reverse(VERTEX<Identities> p, INT
SetAccum<STRING> @source_list;
SetAccum<EDGE> @@edge_set;
SetAccum<VERTEX<Identities>> @@vertices;
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters"];
ListAccum<STRING> @@domainSystems = ["dotbit", "lens", "unstoppabledomains", "space_id", "crossbell", "ENS", "ens", "sns", "genome", "clusters", "basenames"];

##### Initialization #####
seed (Identities) = {p};
Expand Down
11 changes: 10 additions & 1 deletion src/controller/tigergraphql/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ impl IdentityRecord {

/// The expiry date for the domain, from either the registration, or the wrapped domain if PCC is burned
async fn expired_at(&self) -> Option<i64> {
if !vec![Platform::Dotbit, Platform::ENS, Platform::Genome].contains(&self.platform) {
if !vec![
Platform::Dotbit,
Platform::ENS,
Platform::Genome,
Platform::Basenames,
]
.contains(&self.platform)
{
return None;
}
self.expired_at.map(|dt| dt.and_utc().timestamp())
Expand All @@ -255,6 +262,7 @@ impl IdentityRecord {
Platform::Solana,
Platform::SNS,
Platform::Genome,
Platform::Basenames,
]
.contains(&self.platform)
{
Expand All @@ -275,6 +283,7 @@ impl IdentityRecord {
Platform::ENS,
Platform::SNS,
Platform::Genome,
Platform::Basenames,
]
.contains(&self.platform)
{
Expand Down
11 changes: 10 additions & 1 deletion src/controller/tigergraphql/identity_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ impl ExpandIdentityRecord {

/// The expiry date for the domain, from either the registration, or the wrapped domain if PCC is burned
async fn expired_at(&self) -> Option<i64> {
if !vec![Platform::Dotbit, Platform::ENS, Platform::Genome].contains(&self.platform) {
if !vec![
Platform::Dotbit,
Platform::ENS,
Platform::Genome,
Platform::Basenames,
]
.contains(&self.platform)
{
return None;
}
self.expired_at.map(|dt| dt.and_utc().timestamp())
Expand All @@ -162,6 +169,7 @@ impl ExpandIdentityRecord {
Platform::Solana,
Platform::SNS,
Platform::Genome,
Platform::Basenames,
]
.contains(&self.platform)
{
Expand All @@ -182,6 +190,7 @@ impl ExpandIdentityRecord {
Platform::ENS,
Platform::SNS,
Platform::Genome,
Platform::Basenames,
]
.contains(&self.platform)
{
Expand Down
3 changes: 2 additions & 1 deletion src/tigergraph/vertex/domain_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ impl DomainCollection {
Platform::ENS,
Platform::Farcaster,
Platform::Lens,
Platform::SNS,
Platform::Clusters,
Platform::Basenames,
Platform::UnstoppableDomains,
Platform::SNS,
Platform::SpaceId,
Platform::Dotbit,
Platform::Crossbell,
Expand Down
29 changes: 25 additions & 4 deletions src/tigergraph/vertex/identity_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use crate::{
Attribute, BaseResponse, Graph, OpCode, Transfer,
},
upstream::{Chain, DataSource, Platform},
util::parse_body,
util::{naive_now, parse_body},
};
use async_trait::async_trait;
use chrono::Duration;
use http::uri::InvalidUri;
use hyper::{client::HttpConnector, Body, Client, Method};
use serde::de::{self, MapAccess, Visitor};
Expand Down Expand Up @@ -322,15 +323,35 @@ impl IdentityGraph {
return Ok(None); // If vertices=1, it's isolated vertex
}
} else {
// filter out dataSource == "keybase" edges
// filter out dataSource == "basenames" edges
let filter_edges: Vec<IdentityConnection> = result
.edges
.clone()
.into_iter()
.filter(|e| e.source != DataSource::Keybase.to_string())
.filter(|e| e.data_source != DataSource::Basenames)
.collect();

if filter_edges.len() == 0 {
return Ok(None);
// only have basenames edges
let basenames_vertex: Vec<ExpandIdentityRecord> = result
.vertices
.clone()
.into_iter()
.filter(|v| v.record.platform == Platform::Ethereum)
.collect();

if basenames_vertex.len() > 0 {
let updated_at =
basenames_vertex.first().cloned().unwrap().updated_at;
let current_time = naive_now();
let duration_since_update =
current_time.signed_duration_since(updated_at);
// Check if the difference is greater than 2 hours
if duration_since_update > Duration::hours(2) {
tracing::info!("Basenames refetching...");
return Ok(None);
}
}
}
}
return Ok(Some(result));
Expand Down
5 changes: 5 additions & 0 deletions src/upstream/types/contract_category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub enum ContractCategory {
#[graphql(name = "gns")]
GNS,

#[strum(serialize = "basenames")]
#[serde(rename = "basenames")]
#[graphql(name = "basenames")]
Basenames,

#[default]
#[serde(rename = "unknown")]
#[graphql(name = "unknown")]
Expand Down
8 changes: 8 additions & 0 deletions src/upstream/types/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ pub enum DataSource {
#[graphql(name = "sns")]
SNS,

/// Basenames
/// Basenames are a core onchain building block that enable builders to establish their identity on Base by registering human-readable names for their wallet address(es).
/// https://www.base.org/names
#[strum(serialize = "basenames")]
#[serde(rename = "basenames")]
#[graphql(name = "basenames")]
Basenames,

/// opensea
/// https://opensea.io
/// Twitter <-> Ethereum
Expand Down
Loading

0 comments on commit 4ba03cd

Please sign in to comment.