From 3ebeefe4f5bccfee0e8522b6ae81c8ee04d84046 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Tue, 2 May 2023 16:56:49 +0200 Subject: [PATCH] style(cognitarium): make linters happy --- contracts/okp4-cognitarium/src/contract.rs | 14 +++++------- contracts/okp4-cognitarium/src/error.rs | 22 +++++++------------ contracts/okp4-cognitarium/src/state/serde.rs | 4 ++-- .../okp4-cognitarium/src/state/storer.rs | 18 +++++++-------- .../okp4-cognitarium/src/state/triples.rs | 7 +++--- 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/contracts/okp4-cognitarium/src/contract.rs b/contracts/okp4-cognitarium/src/contract.rs index 2f27263a..cf4e2e20 100644 --- a/contracts/okp4-cognitarium/src/contract.rs +++ b/contracts/okp4-cognitarium/src/contract.rs @@ -79,7 +79,7 @@ mod tests { use super::*; use crate::error::StoreError; use crate::msg::ExecuteMsg::InsertData; - use crate::msg::{DataInput, StoreLimitsInput, StoreLimitsInputBuilder}; + use crate::msg::{StoreLimitsInput, StoreLimitsInputBuilder}; use crate::state; use crate::state::{namespaces, triples, Namespace}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; @@ -240,9 +240,7 @@ mod tests { .max_triple_count(30u128) .build() .unwrap(), - Some(ContractError::from(StoreError::MaxTriplesLimitExceeded( - 30u128.into(), - ))), + Some(ContractError::from(StoreError::TripleCount(30u128.into()))), ), ( StoreLimitsInputBuilder::default() @@ -256,7 +254,7 @@ mod tests { .max_byte_size(50u128) .build() .unwrap(), - Some(ContractError::from(StoreError::MaxByteSize(50u128.into()))), + Some(ContractError::from(StoreError::ByteSize(50u128.into()))), ), ( StoreLimitsInputBuilder::default() @@ -270,7 +268,7 @@ mod tests { .max_insert_data_byte_size(500u128) .build() .unwrap(), - Some(ContractError::from(StoreError::MaxInsertDataByteSize( + Some(ContractError::from(StoreError::InsertDataByteSize( 500u128.into(), ))), ), @@ -286,7 +284,7 @@ mod tests { .max_triple_byte_size(150u128) .build() .unwrap(), - Some(ContractError::from(StoreError::MaxTripleByteSize( + Some(ContractError::from(StoreError::TripleByteSize( 176u128.into(), 150u128.into(), ))), @@ -303,7 +301,7 @@ mod tests { .max_insert_data_triple_count(30u128) .build() .unwrap(), - Some(ContractError::from(StoreError::MaxInsertDataTripleCount( + Some(ContractError::from(StoreError::InsertDataTripleCount( 30u128.into(), ))), ), diff --git a/contracts/okp4-cognitarium/src/error.rs b/contracts/okp4-cognitarium/src/error.rs index 7ac54707..62fedeb7 100644 --- a/contracts/okp4-cognitarium/src/error.rs +++ b/contracts/okp4-cognitarium/src/error.rs @@ -33,31 +33,25 @@ impl From for ContractError { #[derive(Error, Debug, PartialEq)] pub enum StoreError { #[error("Maximum triples number exceeded: {0}")] - MaxTriplesLimitExceeded(Uint128), + TripleCount(Uint128), #[error("Maximum byte size exceeded: {0}")] - MaxByteSize(Uint128), + ByteSize(Uint128), #[error("Maximum triple byte size exceeded: {0} / {1}")] - MaxTripleByteSize(Uint128, Uint128), - - #[error("Maximum query limit exceeded: {0} / {1}")] - MaxQueryLimit(Uint128, Uint128), - - #[error("Maximum query variable count exceeded: {0} / {1}")] - MaxQueryVariableCount(Uint128, Uint128), + TripleByteSize(Uint128, Uint128), #[error("Maximum insert byte size exceeded: {0}")] - MaxInsertDataByteSize(Uint128), + InsertDataByteSize(Uint128), #[error("Maximum insert triple count exceeded: {0}")] - MaxInsertDataTripleCount(Uint128), + InsertDataTripleCount(Uint128), } #[derive(Error, Debug, PartialEq)] pub enum RDFParseError { #[error("Error parsing XML RDF: {0}")] - XML(String), + Xml(String), #[error("Error parsing Turtle RDF: {0}")] Turtle(String), @@ -65,12 +59,12 @@ pub enum RDFParseError { impl From for RDFParseError { fn from(value: RdfXmlError) -> Self { - RDFParseError::XML(value.to_string()) + RDFParseError::Xml(value.to_string()) } } impl From for RDFParseError { fn from(value: TurtleError) -> Self { - RDFParseError::XML(value.to_string()) + RDFParseError::Xml(value.to_string()) } } diff --git a/contracts/okp4-cognitarium/src/state/serde.rs b/contracts/okp4-cognitarium/src/state/serde.rs index 5eff8963..27d18057 100644 --- a/contracts/okp4-cognitarium/src/state/serde.rs +++ b/contracts/okp4-cognitarium/src/state/serde.rs @@ -45,8 +45,8 @@ impl KeyDeserialize for Subject { fn from_vec(mut value: Vec) -> StdResult { let val = value.split_off(3); match val[2] { - b'n' => Node::from_vec(value).map(|n| Subject::Named(n)), - b'b' => String::from_vec(value).map(|n| Subject::Blank(n)), + b'n' => Node::from_vec(value).map(Subject::Named), + b'b' => String::from_vec(value).map(Subject::Blank), _ => Err(StdError::generic_err("Could not deserialize subject key")), } } diff --git a/contracts/okp4-cognitarium/src/state/storer.rs b/contracts/okp4-cognitarium/src/state/storer.rs index 1e558a58..c00be88d 100644 --- a/contracts/okp4-cognitarium/src/state/storer.rs +++ b/contracts/okp4-cognitarium/src/state/storer.rs @@ -46,21 +46,19 @@ impl<'a> TripleStorer<'a> { pub fn store_triple(&mut self, t: model::Triple) -> Result<(), ContractError> { self.store.stat.triple_count += Uint128::one(); if self.store.stat.triple_count > self.store.limits.max_triple_count { - Err(StoreError::MaxTriplesLimitExceeded( - self.store.limits.max_triple_count, - ))? + Err(StoreError::TripleCount(self.store.limits.max_triple_count))? } if self.store.stat.triple_count - self.initial_triple_count > self.store.limits.max_insert_data_triple_count { - Err(StoreError::MaxInsertDataTripleCount( + Err(StoreError::InsertDataTripleCount( self.store.limits.max_insert_data_triple_count, ))? } let t_size = Uint128::from(Self::triple_size(t) as u128); if t_size > self.store.limits.max_triple_byte_size { - Err(StoreError::MaxTripleByteSize( + Err(StoreError::TripleByteSize( t_size, self.store.limits.max_triple_byte_size, ))? @@ -68,12 +66,12 @@ impl<'a> TripleStorer<'a> { self.store.stat.byte_size += t_size; if self.store.stat.byte_size > self.store.limits.max_byte_size { - Err(StoreError::MaxByteSize(self.store.limits.max_byte_size))? + Err(StoreError::ByteSize(self.store.limits.max_byte_size))? } if self.store.stat.byte_size - self.initial_byte_size > self.store.limits.max_insert_data_byte_size { - Err(StoreError::MaxInsertDataByteSize( + Err(StoreError::InsertDataByteSize( self.store.limits.max_insert_data_byte_size, ))? } @@ -140,7 +138,7 @@ impl<'a> TripleStorer<'a> { fn subject(&mut self, subject: model::Subject) -> StdResult { match subject { - model::Subject::NamedNode(node) => self.node(node).map(|n| Subject::Named(n)), + model::Subject::NamedNode(node) => self.node(node).map(Subject::Named), model::Subject::BlankNode(node) => Ok(Subject::Blank(node.id.to_string())), _ => Err(StdError::generic_err("RDF star syntax unsupported")), } @@ -157,8 +155,8 @@ impl<'a> TripleStorer<'a> { fn object(&mut self, object: model::Term) -> StdResult { match object { Term::BlankNode(node) => Ok(Object::Blank(node.id.to_string())), - Term::NamedNode(node) => self.node(node).map(|n| Object::Named(n)), - Term::Literal(literal) => self.literal(literal).map(|l| Object::Literal(l)), + Term::NamedNode(node) => self.node(node).map(Object::Named), + Term::Literal(literal) => self.literal(literal).map(Object::Literal), _ => Err(StdError::generic_err("RDF star syntax unsupported")), } } diff --git a/contracts/okp4-cognitarium/src/state/triples.rs b/contracts/okp4-cognitarium/src/state/triples.rs index 1b9c6fd6..560dd839 100644 --- a/contracts/okp4-cognitarium/src/state/triples.rs +++ b/contracts/okp4-cognitarium/src/state/triples.rs @@ -2,9 +2,10 @@ use blake3::Hash; use cw_storage_plus::{Index, IndexList, IndexedMap, MultiIndex}; use serde::{Deserialize, Serialize}; +pub type TriplePK<'a> = (&'a [u8], Predicate, Subject); + pub struct TripleIndexes<'a> { - subject_and_predicate: - MultiIndex<'a, (Subject, Predicate), Triple, (&'a [u8], Predicate, Subject)>, + subject_and_predicate: MultiIndex<'a, (Subject, Predicate), Triple, TriplePK<'a>>, } impl IndexList for TripleIndexes<'_> { @@ -13,7 +14,7 @@ impl IndexList for TripleIndexes<'_> { } } -pub fn triples<'a>() -> IndexedMap<'a, (&'a [u8], Predicate, Subject), Triple, TripleIndexes<'a>> { +pub fn triples<'a>() -> IndexedMap<'a, TriplePK<'a>, Triple, TripleIndexes<'a>> { IndexedMap::new( "TRIPLE", TripleIndexes {