diff --git a/cli/src/main.rs b/cli/src/main.rs index ff3e069..24f7047 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -2,7 +2,7 @@ use clap::{Args, Parser, Subcommand}; use futures::{stream, StreamExt, TryStreamExt}; use ipfs::IpfsClient; use sdk::mapping::{Entity, Named}; -use sdk::{ids, pb::grc20}; +use sdk::{ids, pb}; use sink::bootstrap::constants; use sink::kg; use tracing_subscriber::layer::SubscriberExt; @@ -37,8 +37,8 @@ async fn main() -> anyhow::Result<()> { // for (op_type, triple) in ops { // match op_type { - // grc20::OpType::SetTriple => println!("SetTriple: {:?}", triple), - // grc20::OpType::DeleteTriple => println!("DeleteTriple: {:?}", triple), + // ipfs::OpType::SetTriple => println!("SetTriple: {:?}", triple), + // ipfs::OpType::DeleteTriple => println!("DeleteTriple: {:?}", triple), // _ => (), // } // } @@ -178,32 +178,32 @@ fn set_log_level() { } pub fn find_triples( - ops: impl IntoIterator, + ops: impl IntoIterator, entity_id: &str, -) -> Vec<(grc20::OpType, grc20::Triple)> { +) -> Vec<(pb::ipfs::OpType, pb::ipfs::Triple)> { ops.into_iter() .filter_map(|op| match (op.r#type(), &op.triple) { ( - grc20::OpType::SetTriple, - Some(grc20::Triple { + pb::ipfs::OpType::SetTriple, + Some(pb::ipfs::Triple { entity, attribute, - value: Some(grc20::Value { value, .. }), + value: Some(pb::ipfs::Value { value, .. }), }), ) if *entity == entity_id || *attribute == entity_id || *value == entity_id => Some(( - grc20::OpType::SetTriple, + pb::ipfs::OpType::SetTriple, op.triple.expect("Triple should be some"), )), ( - grc20::OpType::DeleteTriple, - Some(grc20::Triple { + pb::ipfs::OpType::DeleteTriple, + Some(pb::ipfs::Triple { entity, attribute, - value: Some(grc20::Value { value, .. }), + value: Some(pb::ipfs::Value { value, .. }), }), ) if *entity == entity_id || *attribute == entity_id || *value == entity_id => Some(( - grc20::OpType::DeleteTriple, + pb::ipfs::OpType::DeleteTriple, op.triple.expect("Triple should be some"), )), _ => None, @@ -211,13 +211,16 @@ pub fn find_triples( .collect() } -async fn import_space(ipfs_client: &IpfsClient, ipfs_hash: &str) -> anyhow::Result> { - let import = ipfs_client.get::(ipfs_hash, true).await?; +async fn import_space( + ipfs_client: &IpfsClient, + ipfs_hash: &str, +) -> anyhow::Result> { + let import = ipfs_client.get::(ipfs_hash, true).await?; Ok(stream::iter(import.edits) .then(|edit_hash| async move { let edit = ipfs_client - .get::(&edit_hash, true) + .get::(&edit_hash, true) .await?; anyhow::Ok(edit.ops) }) diff --git a/sdk/proto/grc20.proto b/sdk/proto/grc20.proto deleted file mode 100644 index e14b7fd..0000000 --- a/sdk/proto/grc20.proto +++ /dev/null @@ -1,110 +0,0 @@ -syntax = "proto3"; - -package grc20; - -message IpfsMetadata { - // We version the data structured used to represent proposal metadata. Each - // proposal type has their own metadata and versioning that we can change - // independently of other proposal types. - string version = 1; - ActionType type = 2; - string id = 3; - string name = 4; -} - -message Edit { - string version = 1; - ActionType type = 2; - string id = 3; - string name = 4; - repeated Op ops = 5; - repeated string authors = 6; -} - -message ImportEdit { - string version = 1; - ActionType type = 2; - string id = 3; - string name = 4; - repeated Op ops = 5; - repeated string authors = 6; - string createdBy = 7; - string createdAt = 8; - string blockHash = 9; - string blockNumber = 10; - string transactionHash = 11; -} - -message Op { - OpType type = 1; - Triple triple = 2; -} - -message Triple { - string entity = 1; - string attribute = 2; - Value value = 3; -} - -message Value { - ValueType type = 1; - string value = 2; -} - -enum OpType { - NONE = 0; - SET_TRIPLE = 1; - DELETE_TRIPLE = 2; -} - -enum ValueType { - UNKNOWN = 0; - TEXT = 1; - NUMBER = 2; - CHECKBOX = 3; - URL = 4; - TIME = 5; - POINT = 6; -} - -message Membership { - ActionType type = 1; - string name = 2; - string version = 3; - string id = 4; - string user = 5; -} - -message Subspace { - ActionType type = 1; - string name = 2; - string version = 3; - string id = 4; - string subspace = 5; -} - -enum ActionType { - EMPTY = 0; - ADD_EDIT = 1; - ADD_SUBSPACE = 2; - REMOVE_SUBSPACE = 3; - IMPORT_SPACE = 4; - ARCHIVE_SPACE = 5; - ADD_EDITOR = 6; - REMOVE_EDITOR = 7; - ADD_MEMBER = 8; - REMOVE_MEMBER = 9; -} - -message Import { - string version = 1; - ActionType type = 2; - string previousNetwork = 3; - string previousContractAddress = 4; - repeated string edits = 5; -} - -message Options { - string format = 1; - string crop = 2; -} diff --git a/sdk/src/blocks.rs b/sdk/src/blocks.rs index 33c2cc8..25df9d9 100644 --- a/sdk/src/blocks.rs +++ b/sdk/src/blocks.rs @@ -1,4 +1,4 @@ -use crate::{ids::create_geo_id, pb::grc20, relation::create_relationship, system_ids}; +use crate::{ids::create_geo_id, pb::ipfs, relation::create_relationship, system_ids}; pub struct DataBlock; @@ -8,7 +8,7 @@ impl DataBlock { source_type: DataBlockType, position: Option<&str>, name: Option<&str>, - ) -> impl Iterator { + ) -> impl Iterator { let new_block_id = create_geo_id(); std::iter::empty() @@ -34,11 +34,11 @@ impl DataBlock { position, )) // Set attribute: NewBlock.Name - .chain(name.map(|name| grc20::Triple { + .chain(name.map(|name| ipfs::Triple { entity: new_block_id, attribute: system_ids::NAME.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Text.into(), + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Text.into(), value: name.to_string(), }), })) @@ -68,7 +68,7 @@ impl TextBlock { from_id: &str, text: &str, position: Option<&str>, - ) -> impl Iterator { + ) -> impl Iterator { let new_block_id = create_geo_id(); std::iter::empty() @@ -87,11 +87,11 @@ impl TextBlock { position, )) // Set attribute: NewBlock.MarkdownContent - .chain(std::iter::once(grc20::Triple { + .chain(std::iter::once(ipfs::Triple { entity: new_block_id, attribute: system_ids::MARKDOWN_CONTENT.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Text.into(), + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Text.into(), value: text.to_string(), }), })) @@ -101,7 +101,7 @@ impl TextBlock { // pub struct ImageBlock; // impl ImageBlock { -// pub fn new(from_id: &str, url: &str, position: Option<&str>) -> impl Iterator { +// pub fn new(from_id: &str, url: &str, position: Option<&str>) -> impl Iterator { // let new_block_id = create_geo_id(); // std::iter::empty() @@ -110,10 +110,10 @@ impl TextBlock { // // Create relation: Entity > BLOCKS > NewBlock // .chain(create_relationship(from_id, &new_block_id, system_ids::BLOCKS, position)) // // Set attribute: NewBlock.Url -// .chain(std::iter::once(grc20::Triple { +// .chain(std::iter::once(ipfs::Triple { // entity: new_block_id, // attribute: system_ids::URL.to_string(), -// value: Some(grc20::Value { r#type: grc20::ValueType::Text.into(), value: url.to_string() }), +// value: Some(ipfs::Value { r#type: ipfs::ValueType::Text.into(), value: url.to_string() }), // })) // } // } diff --git a/sdk/src/conversion.rs b/sdk/src/conversion.rs index fd0507a..001e597 100644 --- a/sdk/src/conversion.rs +++ b/sdk/src/conversion.rs @@ -1,8 +1,8 @@ -use crate::{ids::Grc20Id, pb::grc20}; +use crate::{ids::Grc20Id, pb::ipfs}; /// A trait for converting a type to a sequence of triples. pub trait ToTriples { - fn to_triples(&self) -> impl Iterator; + fn to_triples(&self) -> impl Iterator; } /// A trait for creating a type from a sequence of triples. @@ -11,17 +11,16 @@ pub trait FromTriples: Sized { fn from_triples( id: Grc20Id, - triples: impl IntoIterator, + triples: impl IntoIterator, ) -> Result; } pub trait ToOps { - fn to_ops(&self) -> impl Iterator; + fn to_ops(&self) -> impl Iterator; } pub trait FromOps: Sized { type Error; - fn from_ops(id: Grc20Id, ops: impl IntoIterator) - -> Result; + fn from_ops(id: Grc20Id, ops: impl IntoIterator) -> Result; } diff --git a/sdk/src/mapping/entity.rs b/sdk/src/mapping/entity.rs index fb4e11a..554be73 100644 --- a/sdk/src/mapping/entity.rs +++ b/sdk/src/mapping/entity.rs @@ -174,11 +174,11 @@ impl Entity { space_id: &str, entity_id: &str, attribute_id: &str, - value: &pb::grc20::Value, + value: &pb::ipfs::Value, ) -> Result<(), DatabaseError> { match (attribute_id, value.r#type(), value.value.as_str()) { // Set the type of the entity - (system_ids::TYPES, pb::grc20::ValueType::Url, value) => { + (system_ids::TYPES, pb::ipfs::ValueType::Url, value) => { const SET_TYPE_QUERY: &str = const_format::formatcp!( r#" MERGE (n {{ id: $id, space_id: $space_id }}) @@ -215,7 +215,7 @@ impl Entity { // Set the FROM_ENTITY or TO_ENTITY on a relation entity ( system_ids::RELATION_FROM_ATTRIBUTE | system_ids::RELATION_TO_ATTRIBUTE, - pb::grc20::ValueType::Url, + pb::ipfs::ValueType::Url, value, ) => { let query = format!( @@ -254,7 +254,7 @@ impl Entity { } // Set the RELATION_TYPE on a relation entity - (system_ids::RELATION_TYPE_ATTRIBUTE, pb::grc20::ValueType::Url, value) => { + (system_ids::RELATION_TYPE_ATTRIBUTE, pb::ipfs::ValueType::Url, value) => { const QUERY: &str = const_format::formatcp!( r#" MERGE (r {{ id: $id, space_id: $space_id }}) @@ -314,7 +314,7 @@ impl Entity { neo4j: &neo4rs::Graph, block: &BlockMetadata, space_id: &str, - triple: pb::grc20::Triple, + triple: pb::ipfs::Triple, ) -> Result<(), DatabaseError> { let delete_triple_query = format!( r#" diff --git a/sdk/src/mapping/triple.rs b/sdk/src/mapping/triple.rs index 17c6131..2f57364 100644 --- a/sdk/src/mapping/triple.rs +++ b/sdk/src/mapping/triple.rs @@ -226,18 +226,18 @@ impl Display for ValueType { } } -impl TryFrom for ValueType { +impl TryFrom for ValueType { type Error = String; - fn try_from(value: pb::grc20::ValueType) -> Result { + fn try_from(value: pb::ipfs::ValueType) -> Result { match value { - pb::grc20::ValueType::Text => Ok(ValueType::Text), - pb::grc20::ValueType::Number => Ok(ValueType::Number), - pb::grc20::ValueType::Checkbox => Ok(ValueType::Checkbox), - pb::grc20::ValueType::Url => Ok(ValueType::Url), - pb::grc20::ValueType::Time => Ok(ValueType::Time), - pb::grc20::ValueType::Point => Ok(ValueType::Point), - pb::grc20::ValueType::Unknown => Err("Unknown ValueType".to_string()), + pb::ipfs::ValueType::Text => Ok(ValueType::Text), + pb::ipfs::ValueType::Number => Ok(ValueType::Number), + pb::ipfs::ValueType::Checkbox => Ok(ValueType::Checkbox), + pb::ipfs::ValueType::Url => Ok(ValueType::Url), + pb::ipfs::ValueType::Time => Ok(ValueType::Time), + pb::ipfs::ValueType::Point => Ok(ValueType::Point), + pb::ipfs::ValueType::Unknown => Err("Unknown ValueType".to_string()), } } } diff --git a/sdk/src/models/proposal.rs b/sdk/src/models/proposal.rs index 786a54c..58a0279 100644 --- a/sdk/src/models/proposal.rs +++ b/sdk/src/models/proposal.rs @@ -1,12 +1,13 @@ use std::fmt::Display; use serde::{Deserialize, Serialize}; +use web3_utils::checksum_address; use crate::{ error::DatabaseError, ids, mapping::{Entity, Relation}, - pb::{self, grc20}, + pb::ipfs, system_ids, }; @@ -22,16 +23,16 @@ pub enum ProposalType { ArchiveSpace, } -impl TryFrom for ProposalType { +impl TryFrom for ProposalType { type Error = String; - fn try_from(action_type: pb::ipfs::ActionType) -> Result { + fn try_from(action_type: ipfs::ActionType) -> Result { match action_type { - pb::ipfs::ActionType::AddEdit => Ok(Self::AddEdit), - pb::ipfs::ActionType::AddSubspace => Ok(Self::AddSubspace), - pb::ipfs::ActionType::RemoveSubspace => Ok(Self::RemoveSubspace), - pb::ipfs::ActionType::ImportSpace => Ok(Self::ImportSpace), - pb::ipfs::ActionType::ArchiveSpace => Ok(Self::ArchiveSpace), + ipfs::ActionType::AddEdit => Ok(Self::AddEdit), + ipfs::ActionType::AddSubspace => Ok(Self::AddSubspace), + ipfs::ActionType::RemoveSubspace => Ok(Self::RemoveSubspace), + ipfs::ActionType::ImportSpace => Ok(Self::ImportSpace), + ipfs::ActionType::ArchiveSpace => Ok(Self::ArchiveSpace), _ => Err(format!("Invalid action type: {:?}", action_type)), } } @@ -90,7 +91,7 @@ impl Proposal { let query = neo4rs::query(QUERY) .param("proposal_id", proposal_id) - .param("plugin_address", plugin_address); + .param("plugin_address", checksum_address(plugin_address, None)); #[derive(Debug, Deserialize)] struct ResultRow { @@ -182,7 +183,7 @@ pub struct EditProposal { pub space: String, pub space_address: String, pub creator: String, - pub ops: Vec, + pub ops: Vec, } #[derive(Deserialize, Serialize)] diff --git a/sdk/src/models/space.rs b/sdk/src/models/space.rs index 68848f9..a4db17e 100644 --- a/sdk/src/models/space.rs +++ b/sdk/src/models/space.rs @@ -55,7 +55,10 @@ impl Space { INDEXED_SPACE = system_ids::INDEXED_SPACE, ); - let query = neo4rs::query(QUERY).param("dao_contract_address", dao_contract_address); + let query = neo4rs::query(QUERY).param( + "dao_contract_address", + checksum_address(dao_contract_address, None), + ); #[derive(Debug, Deserialize)] struct ResultRow { @@ -84,7 +87,10 @@ impl Space { INDEXED_SPACE = system_ids::INDEXED_SPACE, ); - let query = neo4rs::query(QUERY).param("space_plugin_address", space_plugin_address); + let query = neo4rs::query(QUERY).param( + "space_plugin_address", + checksum_address(space_plugin_address, None), + ); #[derive(Debug, Deserialize)] struct ResultRow { @@ -113,7 +119,10 @@ impl Space { INDEXED_SPACE = system_ids::INDEXED_SPACE, ); - let query = neo4rs::query(QUERY).param("voting_plugin_address", voting_plugin_address); + let query = neo4rs::query(QUERY).param( + "voting_plugin_address", + checksum_address(voting_plugin_address, None), + ); #[derive(Debug, Deserialize)] struct ResultRow { @@ -142,7 +151,10 @@ impl Space { INDEXED_SPACE = system_ids::INDEXED_SPACE, ); - let query = neo4rs::query(QUERY).param("member_access_plugin", member_access_plugin); + let query = neo4rs::query(QUERY).param( + "member_access_plugin", + checksum_address(member_access_plugin, None), + ); #[derive(Debug, Deserialize)] struct ResultRow { @@ -171,8 +183,10 @@ impl Space { INDEXED_SPACE = system_ids::INDEXED_SPACE, ); - let query = - neo4rs::query(QUERY).param("personal_space_admin_plugin", personal_space_admin_plugin); + let query = neo4rs::query(QUERY).param( + "personal_space_admin_plugin", + checksum_address(personal_space_admin_plugin, None), + ); #[derive(Debug, Deserialize)] struct ResultRow { diff --git a/sdk/src/pb/grc20.rs b/sdk/src/pb/grc20.rs deleted file mode 100644 index b826caa..0000000 --- a/sdk/src/pb/grc20.rs +++ /dev/null @@ -1,256 +0,0 @@ -// @generated -// This file is @generated by prost-build. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct IpfsMetadata { - /// We version the data structured used to represent proposal metadata. Each - /// proposal type has their own metadata and versioning that we can change - /// independently of other proposal types. - #[prost(string, tag="1")] - pub version: ::prost::alloc::string::String, - #[prost(enumeration="ActionType", tag="2")] - pub r#type: i32, - #[prost(string, tag="3")] - pub id: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub name: ::prost::alloc::string::String, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Edit { - #[prost(string, tag="1")] - pub version: ::prost::alloc::string::String, - #[prost(enumeration="ActionType", tag="2")] - pub r#type: i32, - #[prost(string, tag="3")] - pub id: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub name: ::prost::alloc::string::String, - #[prost(message, repeated, tag="5")] - pub ops: ::prost::alloc::vec::Vec, - #[prost(string, repeated, tag="6")] - pub authors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct ImportEdit { - #[prost(string, tag="1")] - pub version: ::prost::alloc::string::String, - #[prost(enumeration="ActionType", tag="2")] - pub r#type: i32, - #[prost(string, tag="3")] - pub id: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub name: ::prost::alloc::string::String, - #[prost(message, repeated, tag="5")] - pub ops: ::prost::alloc::vec::Vec, - #[prost(string, repeated, tag="6")] - pub authors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, - #[prost(string, tag="7")] - pub created_by: ::prost::alloc::string::String, - #[prost(string, tag="8")] - pub created_at: ::prost::alloc::string::String, - #[prost(string, tag="9")] - pub block_hash: ::prost::alloc::string::String, - #[prost(string, tag="10")] - pub block_number: ::prost::alloc::string::String, - #[prost(string, tag="11")] - pub transaction_hash: ::prost::alloc::string::String, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Op { - #[prost(enumeration="OpType", tag="1")] - pub r#type: i32, - #[prost(message, optional, tag="2")] - pub triple: ::core::option::Option, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Triple { - #[prost(string, tag="1")] - pub entity: ::prost::alloc::string::String, - #[prost(string, tag="2")] - pub attribute: ::prost::alloc::string::String, - #[prost(message, optional, tag="3")] - pub value: ::core::option::Option, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Value { - #[prost(enumeration="ValueType", tag="1")] - pub r#type: i32, - #[prost(string, tag="2")] - pub value: ::prost::alloc::string::String, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Membership { - #[prost(enumeration="ActionType", tag="1")] - pub r#type: i32, - #[prost(string, tag="2")] - pub name: ::prost::alloc::string::String, - #[prost(string, tag="3")] - pub version: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub id: ::prost::alloc::string::String, - #[prost(string, tag="5")] - pub user: ::prost::alloc::string::String, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Subspace { - #[prost(enumeration="ActionType", tag="1")] - pub r#type: i32, - #[prost(string, tag="2")] - pub name: ::prost::alloc::string::String, - #[prost(string, tag="3")] - pub version: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub id: ::prost::alloc::string::String, - #[prost(string, tag="5")] - pub subspace: ::prost::alloc::string::String, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Import { - #[prost(string, tag="1")] - pub version: ::prost::alloc::string::String, - #[prost(enumeration="ActionType", tag="2")] - pub r#type: i32, - #[prost(string, tag="3")] - pub previous_network: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub previous_contract_address: ::prost::alloc::string::String, - #[prost(string, repeated, tag="5")] - pub edits: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Options { - #[prost(string, tag="1")] - pub format: ::prost::alloc::string::String, - #[prost(string, tag="2")] - pub crop: ::prost::alloc::string::String, -} -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] -#[repr(i32)] -pub enum OpType { - None = 0, - SetTriple = 1, - DeleteTriple = 2, -} -impl OpType { - /// String value of the enum field names used in the ProtoBuf definition. - /// - /// The values are not transformed in any way and thus are considered stable - /// (if the ProtoBuf definition does not change) and safe for programmatic use. - pub fn as_str_name(&self) -> &'static str { - match self { - OpType::None => "NONE", - OpType::SetTriple => "SET_TRIPLE", - OpType::DeleteTriple => "DELETE_TRIPLE", - } - } - /// Creates an enum from field names used in the ProtoBuf definition. - pub fn from_str_name(value: &str) -> ::core::option::Option { - match value { - "NONE" => Some(Self::None), - "SET_TRIPLE" => Some(Self::SetTriple), - "DELETE_TRIPLE" => Some(Self::DeleteTriple), - _ => None, - } - } -} -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] -#[repr(i32)] -pub enum ValueType { - Unknown = 0, - Text = 1, - Number = 2, - Checkbox = 3, - Url = 4, - Time = 5, - Point = 6, -} -impl ValueType { - /// String value of the enum field names used in the ProtoBuf definition. - /// - /// The values are not transformed in any way and thus are considered stable - /// (if the ProtoBuf definition does not change) and safe for programmatic use. - pub fn as_str_name(&self) -> &'static str { - match self { - ValueType::Unknown => "UNKNOWN", - ValueType::Text => "TEXT", - ValueType::Number => "NUMBER", - ValueType::Checkbox => "CHECKBOX", - ValueType::Url => "URL", - ValueType::Time => "TIME", - ValueType::Point => "POINT", - } - } - /// Creates an enum from field names used in the ProtoBuf definition. - pub fn from_str_name(value: &str) -> ::core::option::Option { - match value { - "UNKNOWN" => Some(Self::Unknown), - "TEXT" => Some(Self::Text), - "NUMBER" => Some(Self::Number), - "CHECKBOX" => Some(Self::Checkbox), - "URL" => Some(Self::Url), - "TIME" => Some(Self::Time), - "POINT" => Some(Self::Point), - _ => None, - } - } -} -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] -#[repr(i32)] -pub enum ActionType { - Empty = 0, - AddEdit = 1, - AddSubspace = 2, - RemoveSubspace = 3, - ImportSpace = 4, - ArchiveSpace = 5, - AddEditor = 6, - RemoveEditor = 7, - AddMember = 8, - RemoveMember = 9, -} -impl ActionType { - /// String value of the enum field names used in the ProtoBuf definition. - /// - /// The values are not transformed in any way and thus are considered stable - /// (if the ProtoBuf definition does not change) and safe for programmatic use. - pub fn as_str_name(&self) -> &'static str { - match self { - ActionType::Empty => "EMPTY", - ActionType::AddEdit => "ADD_EDIT", - ActionType::AddSubspace => "ADD_SUBSPACE", - ActionType::RemoveSubspace => "REMOVE_SUBSPACE", - ActionType::ImportSpace => "IMPORT_SPACE", - ActionType::ArchiveSpace => "ARCHIVE_SPACE", - ActionType::AddEditor => "ADD_EDITOR", - ActionType::RemoveEditor => "REMOVE_EDITOR", - ActionType::AddMember => "ADD_MEMBER", - ActionType::RemoveMember => "REMOVE_MEMBER", - } - } - /// Creates an enum from field names used in the ProtoBuf definition. - pub fn from_str_name(value: &str) -> ::core::option::Option { - match value { - "EMPTY" => Some(Self::Empty), - "ADD_EDIT" => Some(Self::AddEdit), - "ADD_SUBSPACE" => Some(Self::AddSubspace), - "REMOVE_SUBSPACE" => Some(Self::RemoveSubspace), - "IMPORT_SPACE" => Some(Self::ImportSpace), - "ARCHIVE_SPACE" => Some(Self::ArchiveSpace), - "ADD_EDITOR" => Some(Self::AddEditor), - "REMOVE_EDITOR" => Some(Self::RemoveEditor), - "ADD_MEMBER" => Some(Self::AddMember), - "REMOVE_MEMBER" => Some(Self::RemoveMember), - _ => None, - } - } -} -// @@protoc_insertion_point(module) diff --git a/sdk/src/pb/mod.rs b/sdk/src/pb/mod.rs index 7e80e1c..9d314ff 100644 --- a/sdk/src/pb/mod.rs +++ b/sdk/src/pb/mod.rs @@ -4,11 +4,6 @@ pub mod geo { include!("geo.rs"); // @@protoc_insertion_point(geo) } -// @@protoc_insertion_point(attribute:grc20) -pub mod grc20 { - include!("grc20.rs"); - // @@protoc_insertion_point(grc20) -} // @@protoc_insertion_point(attribute:ipfs) pub mod ipfs { include!("ipfs.rs"); diff --git a/sdk/src/relation.rs b/sdk/src/relation.rs index 34fb987..0eec2b6 100644 --- a/sdk/src/relation.rs +++ b/sdk/src/relation.rs @@ -4,7 +4,7 @@ use crate::{ conversion::{FromTriples, ToTriples}, graph_uri::{GraphUri, InvalidGraphUri}, ids::{create_geo_id, Grc20Id}, - pb::grc20, + pb::ipfs, system_ids, }; @@ -17,44 +17,44 @@ pub struct Relation { to: Grc20Id, relationship_types: Vec, index: String, - other_attributes: HashMap, + other_attributes: HashMap, } impl ToTriples for Relation { - fn to_triples(&self) -> impl Iterator { + fn to_triples(&self) -> impl Iterator { let base_triples = vec![ // Type of Collection Item - grc20::Triple { + ipfs::Triple { entity: self.id.clone().into(), attribute: system_ids::TYPES.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id_str(system_ids::RELATION_TYPE).to_string(), }), }, // Entity value for the collection itself - grc20::Triple { + ipfs::Triple { entity: self.id.clone().into(), attribute: system_ids::RELATION_FROM_ATTRIBUTE.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id(self.from.clone()).to_string(), }), }, // Entity value for the entity referenced by this collection item - grc20::Triple { + ipfs::Triple { entity: self.id.clone().into(), attribute: system_ids::RELATION_TO_ATTRIBUTE.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id(self.to.clone()).to_string(), }), }, - grc20::Triple { + ipfs::Triple { entity: self.id.clone().into(), attribute: system_ids::RELATION_INDEX.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Text as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Text as i32, value: self.index.clone(), }), }, @@ -66,11 +66,11 @@ impl ToTriples for Relation { .chain( self.relationship_types .iter() - .map(|relationship_type| grc20::Triple { + .map(|relationship_type| ipfs::Triple { entity: self.id.clone().into(), attribute: system_ids::RELATION_TYPE_ATTRIBUTE.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id(relationship_type.clone()).to_string(), }), }), @@ -79,10 +79,10 @@ impl ToTriples for Relation { .chain( self.other_attributes .iter() - .map(|(attribute, (r#type, value))| grc20::Triple { + .map(|(attribute, (r#type, value))| ipfs::Triple { entity: self.id.clone().into(), attribute: attribute.into(), - value: Some(grc20::Value { + value: Some(ipfs::Value { r#type: *r#type as i32, value: value.into(), }), @@ -108,7 +108,7 @@ impl FromTriples for Relation { fn from_triples( id: Grc20Id, - triples: impl IntoIterator, + triples: impl IntoIterator, ) -> Result { let relation = triples .into_iter() @@ -117,12 +117,12 @@ impl FromTriples for Relation { |builder, triple| { match triple { // "Consume" the type attribute if it's a relation - grc20::Triple { + ipfs::Triple { attribute, - value: Some(grc20::Value { r#type, value }), + value: Some(ipfs::Value { r#type, value }), .. } if attribute == system_ids::TYPES - && r#type == grc20::ValueType::Url as i32 + && r#type == ipfs::ValueType::Url as i32 && value == GraphUri::from_id_str(system_ids::RELATION_TYPE).to_string() => { @@ -130,65 +130,65 @@ impl FromTriples for Relation { } // Set the FROM_ENTITY attribute - grc20::Triple { + ipfs::Triple { attribute, - value: Some(grc20::Value { r#type, value }), + value: Some(ipfs::Value { r#type, value }), .. } if attribute == system_ids::RELATION_FROM_ATTRIBUTE - && r#type == grc20::ValueType::Url as i32 => + && r#type == ipfs::ValueType::Url as i32 => { Ok(GraphUri::from_uri(&value) .map(|uri| builder.from_entity(uri.to_id()))?) } // Set the TO_ENTITY attribute - grc20::Triple { + ipfs::Triple { attribute, - value: Some(grc20::Value { r#type, value }), + value: Some(ipfs::Value { r#type, value }), .. } if attribute == system_ids::RELATION_TO_ATTRIBUTE - && r#type == grc20::ValueType::Url as i32 => + && r#type == ipfs::ValueType::Url as i32 => { Ok(GraphUri::from_uri(&value) .map(|uri| builder.to_entity(uri.to_id()))?) } // Set the RELATION_TYPE attribute - grc20::Triple { + ipfs::Triple { attribute, - value: Some(grc20::Value { r#type, value }), + value: Some(ipfs::Value { r#type, value }), .. } if attribute == system_ids::RELATION_TYPE_ATTRIBUTE - && r#type == grc20::ValueType::Url as i32 => + && r#type == ipfs::ValueType::Url as i32 => { Ok(GraphUri::from_uri(&value) .map(|uri| builder.relation_type(uri.to_id()))?) } // Set the RELATION_INDEX attribute - grc20::Triple { + ipfs::Triple { attribute, - value: Some(grc20::Value { r#type, value }), + value: Some(ipfs::Value { r#type, value }), .. } if attribute == system_ids::RELATION_INDEX - && r#type == grc20::ValueType::Text as i32 => + && r#type == ipfs::ValueType::Text as i32 => { Ok(builder.index(value)) } // Set other attributes - grc20::Triple { + ipfs::Triple { attribute, - value: Some(grc20::Value { r#type, value }), + value: Some(ipfs::Value { r#type, value }), .. } => Ok(builder.other_attribute( Grc20Id(attribute), - grc20::ValueType::try_from(r#type)?, + ipfs::ValueType::try_from(r#type)?, value, )), // Ignore triples with no value - grc20::Triple { value: None, .. } => Ok(builder), + ipfs::Triple { value: None, .. } => Ok(builder), } }, )? @@ -204,54 +204,54 @@ pub fn create_relationship( to_id: &str, relationship_type_id: &str, position: Option<&str>, -) -> impl Iterator { +) -> impl Iterator { let new_entity_id = create_geo_id(); vec![ // Set the type of the new entity to RELATION_TYPE - grc20::Triple { + ipfs::Triple { entity: new_entity_id.clone(), attribute: system_ids::TYPES.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id_str(system_ids::RELATION_TYPE).to_string(), }), }, // Set the FROM_ENTITY attribute - grc20::Triple { + ipfs::Triple { entity: new_entity_id.clone(), attribute: system_ids::RELATION_FROM_ATTRIBUTE.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id_str(from_id).to_string(), }), }, // Set the TO_ENTITY attribute - grc20::Triple { + ipfs::Triple { entity: new_entity_id.clone(), attribute: system_ids::RELATION_TO_ATTRIBUTE.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id_str(to_id).to_string(), }), }, // Set the RELATION_INDEX attribute - grc20::Triple { + ipfs::Triple { entity: new_entity_id.clone(), attribute: system_ids::RELATION_INDEX.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Text as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Text as i32, value: position .unwrap_or(INITIAL_COLLECTION_ITEM_INDEX_VALUE) .to_string(), }), }, // Set the RELATION_TYPE attribute - grc20::Triple { + ipfs::Triple { entity: new_entity_id.clone(), attribute: system_ids::RELATION_TYPE_ATTRIBUTE.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Url as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Url as i32, value: GraphUri::from_id_str(relationship_type_id).to_string(), }), }, @@ -269,7 +269,7 @@ pub struct RelationBuilder { to_entity_id: Option, relation_types_id: Vec, index: Option, - other_attributes: HashMap, + other_attributes: HashMap, } impl RelationBuilder { @@ -306,7 +306,7 @@ impl RelationBuilder { pub fn other_attribute( mut self, attribute_id: Grc20Id, - r#type: grc20::ValueType, + r#type: ipfs::ValueType, value: String, ) -> Self { self.other_attributes.insert(attribute_id, (r#type, value)); diff --git a/sink/src/bootstrap/bootstrap_root.rs b/sink/src/bootstrap/bootstrap_root.rs index 5ccd29c..4f698fe 100644 --- a/sink/src/bootstrap/bootstrap_root.rs +++ b/sink/src/bootstrap/bootstrap_root.rs @@ -1,6 +1,6 @@ // See https://github.com/geobrowser/geogenesis/blob/stream/1.0.0/packages/substream/sink/bootstrap-root.ts -use sdk::{network_ids, pb::grc20, relation::create_relationship, system_ids}; +use sdk::{network_ids, pb::ipfs, relation::create_relationship, system_ids}; use super::{bootstrap_templates, constants}; @@ -175,36 +175,36 @@ const SCHEMA_TYPES: &[(&str, &[&str])] = &[ const TYPES: &[(&str, &[&str])] = &[(network_ids::ETHEREUM, &[system_ids::NETWORK_TYPE])]; -pub fn name_ops() -> impl Iterator { - NAMES.iter().map(|(id, name)| grc20::Triple { +pub fn name_ops() -> impl Iterator { + NAMES.iter().map(|(id, name)| ipfs::Triple { entity: id.to_string(), attribute: system_ids::NAME.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Text as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Text as i32, value: name.to_string(), }), }) } -pub fn attribute_ops() -> impl Iterator { +pub fn attribute_ops() -> impl Iterator { ATTRIBUTES.iter().flat_map(|(attribute_id, _)| { create_relationship(attribute_id, system_ids::ATTRIBUTE, system_ids::TYPES, None) }) } -pub fn attribute_value_type_ops() -> impl Iterator { +pub fn attribute_value_type_ops() -> impl Iterator { ATTRIBUTES.iter().flat_map(|(attribute_id, value_type_id)| { create_relationship(attribute_id, value_type_id, system_ids::VALUE_TYPE, None) }) } -pub fn type_ops() -> impl Iterator { +pub fn type_ops() -> impl Iterator { SCHEMA_TYPES.iter().flat_map(|(type_id, _)| { create_relationship(type_id, system_ids::SCHEMA_TYPE, system_ids::TYPES, None) }) } -pub fn root_space_type() -> impl Iterator { +pub fn root_space_type() -> impl Iterator { create_relationship( constants::ROOT_SPACE_ID, system_ids::SPACE_CONFIGURATION, @@ -213,7 +213,7 @@ pub fn root_space_type() -> impl Iterator { ) } -pub fn type_schema_ops() -> impl Iterator { +pub fn type_schema_ops() -> impl Iterator { SCHEMA_TYPES.iter().flat_map(|(type_id, attributes)| { attributes .iter() @@ -224,7 +224,7 @@ pub fn type_schema_ops() -> impl Iterator { }) } -pub fn entities_types_ops() -> impl Iterator { +pub fn entities_types_ops() -> impl Iterator { TYPES.iter().flat_map(|(entity_id, types_ids)| { types_ids .iter() @@ -233,7 +233,7 @@ pub fn entities_types_ops() -> impl Iterator { }) } -pub fn bootstrap() -> impl Iterator { +pub fn bootstrap() -> impl Iterator { std::iter::empty() .chain(name_ops()) .chain(attribute_ops()) @@ -243,9 +243,12 @@ pub fn bootstrap() -> impl Iterator { .chain(type_schema_ops()) .chain(entities_types_ops()) .chain(bootstrap_templates::templates_ops()) - .map(|op| grc20::Op { - r#type: grc20::OpType::SetTriple as i32, + .map(|op| ipfs::Op { + r#type: ipfs::OpType::SetTriple as i32, triple: Some(op), + entity: None, + relation: None, + triples: vec![], }) } diff --git a/sink/src/bootstrap/bootstrap_templates.rs b/sink/src/bootstrap/bootstrap_templates.rs index 19a8f38..4b1835a 100644 --- a/sink/src/bootstrap/bootstrap_templates.rs +++ b/sink/src/bootstrap/bootstrap_templates.rs @@ -1,6 +1,6 @@ use sdk::{ blocks::{DataBlock, DataBlockType, TextBlock}, - pb::grc20, + pb::ipfs, relation::create_relationship, system_ids, }; @@ -8,11 +8,11 @@ use sdk::{ pub struct Template { id: String, name: String, - blocks: Vec, + blocks: Vec, types: Vec, #[allow(dead_code)] foreign_types: Vec, - additional_data: Vec, + additional_data: Vec, } pub fn non_profit() -> impl Iterator { @@ -321,7 +321,7 @@ pub fn person() -> impl Iterator { .into_iter() } -pub fn templates_ops() -> impl Iterator { +pub fn templates_ops() -> impl Iterator { std::iter::empty() .chain(non_profit()) .chain(company()) @@ -329,11 +329,11 @@ pub fn templates_ops() -> impl Iterator { .flat_map(|template| { std::iter::empty() // Set attribute: Template.Name - .chain(std::iter::once(grc20::Triple { + .chain(std::iter::once(ipfs::Triple { entity: template.id.clone(), attribute: system_ids::NAME.to_string(), - value: Some(grc20::Value { - r#type: grc20::ValueType::Text as i32, + value: Some(ipfs::Value { + r#type: ipfs::ValueType::Text as i32, value: template.name, }), })) diff --git a/sink/src/events/edit_published.rs b/sink/src/events/edit_published.rs index d9134fc..8db0d8e 100644 --- a/sink/src/events/edit_published.rs +++ b/sink/src/events/edit_published.rs @@ -2,7 +2,7 @@ use futures::{stream, StreamExt, TryStreamExt}; use ipfs::deserialize; use sdk::{ models::{self, EditProposal, Space}, - pb::{self, geo, grc20}, + pb::{self, geo}, }; use web3_utils::checksum_address; @@ -91,7 +91,7 @@ impl EventHandler { match metadata.r#type() { pb::ipfs::ActionType::AddEdit => { - let edit = deserialize::(&bytes)?; + let edit = deserialize::(&bytes)?; Ok(vec![EditProposal { name: edit.name, proposal_id: edit.id, @@ -106,11 +106,11 @@ impl EventHandler { }]) } pb::ipfs::ActionType::ImportSpace => { - let import = deserialize::(&bytes)?; + let import = deserialize::(&bytes)?; let edits = stream::iter(import.edits) .map(|edit| async move { let hash = edit.replace("ipfs://", ""); - self.ipfs.get::(&hash, true).await + self.ipfs.get::(&hash, true).await }) .buffer_unordered(10) .try_collect::>() diff --git a/sink/src/events/space_created.rs b/sink/src/events/space_created.rs index 9ec5c8b..b610315 100644 --- a/sink/src/events/space_created.rs +++ b/sink/src/events/space_created.rs @@ -36,7 +36,7 @@ impl EventHandler { // .filter_map(|(space_address, proposal_processed)| async move { // let ipfs_hash = proposal_processed.content_uri.replace("ipfs://", ""); // self.ipfs - // .get::(&ipfs_hash, true) + // .get::(&ipfs_hash, true) // .await // .ok() // .map(|import| { diff --git a/sink/src/kg/client.rs b/sink/src/kg/client.rs index 8a431a4..b9721be 100644 --- a/sink/src/kg/client.rs +++ b/sink/src/kg/client.rs @@ -136,13 +136,13 @@ impl Client { &self, block: &models::BlockMetadata, space_id: &str, - ops: impl IntoIterator, + ops: impl IntoIterator, ) -> Result<(), DatabaseError> { for op in ops { match (op.r#type(), op.triple) { ( - pb::grc20::OpType::SetTriple, - Some(pb::grc20::Triple { + pb::ipfs::OpType::SetTriple, + Some(pb::ipfs::Triple { entity, attribute, value: Some(value), @@ -160,7 +160,7 @@ impl Client { ) .await? } - (pb::grc20::OpType::DeleteTriple, Some(triple)) => { + (pb::ipfs::OpType::DeleteTriple, Some(triple)) => { tracing::info!( "DeleteTriple: {}, {}, {:?}", triple.entity,