Skip to content

Commit

Permalink
fix(cognitarium): fix incorrect variable resolution on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Aug 7, 2023
1 parent 31ec289 commit 2c45f11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 14 additions & 4 deletions contracts/okp4-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,21 @@ pub mod execute {
.collect();

let response = QueryEngine::new(deps.storage).select(plan, variables)?;
let atoms: Vec<Atom> = response
.results
.bindings
let atoms = delete
.iter()
.flat_map(|row| delete.iter().map(|pattern| pattern.resolve(row, &prefixes)))
.flat_map(|pattern| {
if response.results.bindings.is_empty() {
vec![pattern.resolve(&BTreeMap::new(), &prefixes)]
} else {
response
.results
.bindings
.iter()
.map(|row| pattern.resolve(row, &prefixes))
.collect::<Vec<_>>()
}
})
.into_iter()
.collect::<Result<Vec<_>, _>>()?;

let mut storer = StoreEngine::new(deps.storage)?;
Expand Down
8 changes: 7 additions & 1 deletion contracts/okp4-cognitarium/src/storer/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ impl<'a> StoreEngine<'a> {
.map_err(ContractError::Std)
}

/// Flushes the store to the storage.
/// Returns the number of triples added or removed (absolute value).
pub fn finish(&mut self) -> Result<Uint128, ContractError> {
STORE.save(self.storage, &self.store)?;
NAMESPACE_KEY_INCREMENT.save(self.storage, &self.ns_key_inc_offset)?;
for entry in &self.ns_cache {
namespaces().save(self.storage, entry.0.to_string(), entry.1)?;
}

Ok(self.store.stat.triple_count - self.initial_triple_count)
if self.store.stat.triple_count > self.initial_triple_count {
Ok(self.store.stat.triple_count - self.initial_triple_count)
} else {
Ok(self.initial_triple_count - self.store.stat.triple_count)
}
}

fn resolve_namespace_key(&mut self, ns_str: String) -> StdResult<u128> {
Expand Down

0 comments on commit 2c45f11

Please sign in to comment.