Skip to content

Commit

Permalink
misc: Cleanup old code
Browse files Browse the repository at this point in the history
  • Loading branch information
cvauclair committed Dec 12, 2024
1 parent f51c740 commit 35ea24c
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 332 deletions.
20 changes: 8 additions & 12 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use futures::{stream, StreamExt, TryStreamExt};
use ipfs::IpfsClient;
use sdk::{ids, pb::grc20};
use sink::{kg::{
self,
entity::{Entity, EntityNode},
}, ops::conversions};
self, mapping::DefaultAttributes,}, ops::conversions};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

Expand Down Expand Up @@ -46,21 +44,19 @@ async fn main() -> anyhow::Result<()> {
unimplemented!()
}
Command::Describe { id } => {
let entity_node = kg_client
.find_node_by_id::<EntityNode>(&id)
let entity = kg_client
.find_node_by_id::<DefaultAttributes>(&id)
.await?
.expect("Entity not found");

let entity = Entity::from_entity(kg_client.clone(), entity_node.attributes().clone());
println!("Entity: {}", entity.name_or_id());

println!("Entity: {}", entity);

let attributes = entity.attributes().await?;
let attributes = kg_client.attribute_nodes::<DefaultAttributes>(entity.id()).await?;

for attribute in attributes {
println!("\tAttribute: {}", attribute);
if let Some(value_type) = attribute.value_type().await? {
println!("\t\tValue type: {}", value_type);
println!("\tAttribute: {}", attribute.name_or_id());
if let Some(value_type) = kg_client.value_type_node::<DefaultAttributes>(attribute.id()).await? {
println!("\t\tValue type: {}", value_type.name_or_id());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub async fn gen_type(kg: &sink::kg::Client, entity: &Node<Named>) -> anyhow::Re

let typed_attrs = stream::iter(attrs.unique().fix_name_collisions())
.then(|attr| async move {
let value_type = kg.value_type_nodes(attr.id()).await?;
let value_type = kg.value_type_node(attr.id()).await?;
Ok::<_, anyhow::Error>((attr, value_type))
})
.try_collect::<Vec<_>>()
Expand Down
13 changes: 6 additions & 7 deletions sink/src/events/vote_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sdk::{
};
use web3_utils::checksum_address;

use crate::{kg::mapping::Relation, neo4j_utils::Neo4jExt};
use crate::kg::mapping::Relation;

use super::{handler::HandlerError, EventHandler};

Expand All @@ -24,8 +24,8 @@ impl EventHandler {
) {
// Space found
(Ok(Some(space)), Ok(_)) | (Ok(None), Ok(Some(space))) => {
let proposal = self.kg.neo4j
.find_one::<models::Proposal>(neo4rs::query(&format!(
let proposal = self.kg
.find_node::<models::Proposal>(neo4rs::query(&format!(
"MATCH (p:`{PROPOSAL_TYPE}` {{onchain_proposal_id: $onchain_proposal_id}})<-[:`{PROPOSALS}`]-(:`{INDEXED_SPACE}` {{id: $space_id}}) RETURN p",
PROPOSAL_TYPE = system_ids::PROPOSAL_TYPE,
PROPOSALS = system_ids::PROPOSALS,
Expand All @@ -38,8 +38,7 @@ impl EventHandler {

let account = self
.kg
.neo4j
.find_one::<models::GeoAccount>(
.find_node::<models::GeoAccount>(
neo4rs::query(&format!(
"MATCH (a:`{ACCOUNT}` {{address: $address}}) RETURN a",
ACCOUNT = system_ids::GEO_ACCOUNT,
Expand All @@ -65,8 +64,8 @@ impl EventHandler {
Relation::new(
INDEXER_SPACE_ID,
&vote_cast.id.clone(),
&account.id,
&proposal.id,
&account.id(),

Check failure on line 67 in sink/src/events/vote_cast.rs

View workflow job for this annotation

GitHub Actions / stable / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> sink/src/events/vote_cast.rs:67:37 | 67 | ... &account.id(), | ^^^^^^^^^^^^^ help: change this to: `account.id()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`
&proposal.id(),

Check failure on line 68 in sink/src/events/vote_cast.rs

View workflow job for this annotation

GitHub Actions / stable / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> sink/src/events/vote_cast.rs:68:37 | 68 | ... &proposal.id(), | ^^^^^^^^^^^^^^ help: change this to: `proposal.id()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
system_ids::VOTE_CAST,
vote_cast,
),
Expand Down
27 changes: 1 addition & 26 deletions sink/src/kg/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ impl Client {
self.find_nodes::<T>(query).await
}

pub async fn value_type_nodes<T: for<'a> Deserialize<'a> + Send>(&self, id: &str) -> Result<Option<Node<T>>, DatabaseError> {
pub async fn value_type_node<T: for<'a> Deserialize<'a> + Send>(&self, id: &str) -> Result<Option<Node<T>>, DatabaseError> {
let query = neo4rs::query(&format!(
r#"
MATCH (a {{id: $id}}) -[:`{value_type_attr}`]-> (t:`{type_type}`)
Expand Down Expand Up @@ -701,28 +701,3 @@ impl Client {
Ok(())
}
}

#[derive(Debug, Deserialize)]
pub struct Entity {
pub id: String,
pub name: Option<String>,
pub description: Option<String>,
pub cover: Option<String>,
pub content: Option<String>,
}

impl Entity {
pub fn new(id: &str, name: &str) -> Self {
Self {
id: id.to_string(),
name: Some(name.to_string()),
description: None,
cover: None,
content: None,
}
}

pub fn find_by_id_query(id: &str) -> neo4rs::Query {
neo4rs::query("MATCH (n { id: $id }) RETURN n").param("id", id)
}
}
76 changes: 0 additions & 76 deletions sink/src/kg/entity.rs

This file was deleted.

4 changes: 4 additions & 0 deletions sink/src/kg/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ impl Node<DefaultAttributes> {
.and_then(|v| v.as_str())
.map(|s| s.to_string())
}

pub fn name_or_id(&self) -> String {
self.name().unwrap_or_else(|| self.id().to_string())
}
}

pub type DefaultAttributes = HashMap<String, serde_json::Value>;
Expand Down
1 change: 0 additions & 1 deletion sink/src/kg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod client;
pub mod entity;
pub mod mapping;

pub use client::Client;
Loading

0 comments on commit 35ea24c

Please sign in to comment.