Skip to content

Commit

Permalink
feat(dataverse): dissociate triple store msg limits struct
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Nov 16, 2023
1 parent 0498747 commit c142976
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 33 deletions.
15 changes: 7 additions & 8 deletions contracts/okp4-dataverse/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn instantiate(
code_id: msg.triplestore_config.code_id.u64(),
label: format!("{}_triplestore", msg.name),
msg: to_binary(&okp4_cognitarium::msg::InstantiateMsg {
limits: msg.triplestore_config.limits,
limits: msg.triplestore_config.limits.into(),
})?,
funds: vec![],
salt,
Expand Down Expand Up @@ -85,13 +85,12 @@ pub mod query {}
#[cfg(test)]
mod tests {
use super::*;
use crate::msg::TripleStoreConfig;
use crate::msg::{TripleStoreConfig, TripleStoreLimitsInput};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{
Attribute, ContractResult, HexBinary, SubMsg, SystemError, SystemResult, Uint128, Uint64,
WasmQuery,
};
use okp4_cognitarium::msg::StoreLimitsInputBuilder;

#[test]
fn proper_instantiate() {
Expand All @@ -111,10 +110,10 @@ mod tests {
_ => SystemResult::Err(SystemError::Unknown {}),
});

let store_limits = StoreLimitsInputBuilder::default()
.max_byte_size(Uint128::from(50000u128))
.build()
.unwrap();
let store_limits = TripleStoreLimitsInput {
max_byte_size: Some(Uint128::from(50000u128)),
..Default::default()
};

let msg = InstantiateMsg {
name: "my-dataverse".to_string(),
Expand All @@ -137,7 +136,7 @@ mod tests {
code_id: 17,
label: "my-dataverse_triplestore".to_string(),
msg: to_binary(&okp4_cognitarium::msg::InstantiateMsg {
limits: store_limits,
limits: store_limits.into(),
})
.unwrap(),
funds: vec![],
Expand Down
67 changes: 64 additions & 3 deletions contracts/okp4-dataverse/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Binary, Uint64};
use cosmwasm_std::{Binary, Uint128, Uint64};

/// `InstantiateMsg` is used to initialize a new instance of the dataverse.
#[cw_serde]
Expand Down Expand Up @@ -132,8 +132,69 @@ pub struct TripleStoreConfig {
pub code_id: Uint64,

/// Limitations regarding triple store usage.
#[serde(default = "okp4_cognitarium::msg::StoreLimitsInput::default")]
pub limits: okp4_cognitarium::msg::StoreLimitsInput,
pub limits: TripleStoreLimitsInput,
}

/// # TripleStoreLimitsInput
/// Contains requested limitations regarding store usages.
#[cw_serde]
#[derive(Default)]
pub struct TripleStoreLimitsInput {
/// The maximum number of triples the store can contain.
/// Default to [Uint128::MAX] if not set, which can be considered as no limit.
pub max_triple_count: Option<Uint128>,
/// The maximum number of bytes the store can contain.
/// The size of a triple is counted as the sum of the size of its subject, predicate and object,
/// including the size of data types and language tags if any.
/// Default to [Uint128::MAX] if not set, which can be considered as no limit.
pub max_byte_size: Option<Uint128>,
/// The maximum number of bytes the store can contain for a single triple.
/// The size of a triple is counted as the sum of the size of its subject, predicate and object,
/// including the size of data types and language tags if any. The limit is used to prevent
/// storing very large triples, especially literals.
/// Default to [Uint128::MAX] if not set, which can be considered as no limit.
pub max_triple_byte_size: Option<Uint128>,
/// The maximum limit of a query, i.e. the maximum number of triples returned by a select query.
/// Default to 30 if not set.
pub max_query_limit: Option<u32>,
/// The maximum number of variables a query can select.
/// Default to 30 if not set.
pub max_query_variable_count: Option<u32>,
/// The maximum number of bytes an insert data query can contain.
/// Default to [Uint128::MAX] if not set, which can be considered as no limit.
pub max_insert_data_byte_size: Option<Uint128>,
/// The maximum number of triples an insert data query can contain (after parsing).
/// Default to [Uint128::MAX] if not set, which can be considered as no limit.
pub max_insert_data_triple_count: Option<Uint128>,
}

impl From<TripleStoreLimitsInput> for okp4_cognitarium::msg::StoreLimitsInput {
fn from(value: TripleStoreLimitsInput) -> Self {
let mut limits = okp4_cognitarium::msg::StoreLimitsInput::default();
if let Some(max_triple_count) = value.max_triple_count {
limits.max_triple_count = max_triple_count;
}
if let Some(max_byte_size) = value.max_byte_size {
limits.max_byte_size = max_byte_size;
}
if let Some(max_triple_byte_size) = value.max_triple_byte_size {
limits.max_triple_byte_size = max_triple_byte_size;
}
if let Some(max_query_limit) = value.max_query_limit {
limits.max_query_limit = max_query_limit;
}
if let Some(max_query_variable_count) = value.max_query_variable_count {
limits.max_query_variable_count = max_query_variable_count;
}
if let Some(max_insert_data_byte_size) = value.max_insert_data_byte_size {
limits.max_insert_data_byte_size = max_insert_data_byte_size;
}
if let Some(max_insert_data_triple_count) = value.max_insert_data_triple_count {
limits.max_insert_data_triple_count = max_insert_data_triple_count;
}

limits
}
}

/// # RdfFormat
Expand Down
44 changes: 22 additions & 22 deletions docs/okp4-dataverse.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Given its role and status, this smart contract serves as the primary access poin
|`name`|*(Required.) * **string**. A unique name to identify the dataverse instance.|
|`triplestore_config`|*(Required.) * **[TripleStoreConfig](#triplestoreconfig)**. The configuration used to instantiate the triple store.|
|`triplestore_config.code_id`|**[Uint64](#uint64)**. The code id that will be used to instantiate the triple store contract in which to store dataverse semantic data. It must implement the cognitarium interface.|
|`triplestore_config.limits`|**[StoreLimitsInput](#storelimitsinput)**. Limitations regarding triple store usage.<br />**Default:** `{"max_byte_size":"340282366920938463463374607431768211455","max_insert_data_byte_size":"340282366920938463463374607431768211455","max_insert_data_triple_count":"340282366920938463463374607431768211455","max_query_limit":30,"max_query_variable_count":30,"max_triple_byte_size":"340282366920938463463374607431768211455","max_triple_count":"340282366920938463463374607431768211455"}`|
|`triplestore_config.limits`|**[TripleStoreLimitsInput](#triplestorelimitsinput)**. Limitations regarding triple store usage.|

## ExecuteMsg

Expand Down Expand Up @@ -205,35 +205,35 @@ RDF/XML is a syntax to express RDF information in XML. See the [official RDF/XML
|-------|
|`"rdf_xml"`|

### StoreLimitsInput
### TripleStoreConfig

Contains requested limitations regarding store usages.
`TripleStoreConfig` represents the configuration related to the management of the triple store.

|property|description|
|----------|-----------|
|`max_byte_size`|**[Uint128](#uint128)**. The maximum number of bytes the store can contain. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_insert_data_byte_size`|**[Uint128](#uint128)**. The maximum number of bytes an insert data query can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_insert_data_triple_count`|**[Uint128](#uint128)**. The maximum number of triples an insert data query can contain (after parsing). Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_query_limit`|**integer**. The maximum limit of a query, i.e. the maximum number of triples returned by a select query. Default to 30 if not set.|
|`max_query_variable_count`|**integer**. The maximum number of variables a query can select. Default to 30 if not set.|
|`max_triple_byte_size`|**[Uint128](#uint128)**. The maximum number of bytes the store can contain for a single triple. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. The limit is used to prevent storing very large triples, especially literals. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_triple_count`|**[Uint128](#uint128)**. The maximum number of triples the store can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`code_id`|*(Required.) * **[Uint64](#uint64)**. The code id that will be used to instantiate the triple store contract in which to store dataverse semantic data. It must implement the cognitarium interface.|
|`limits`|*(Required.) * **[TripleStoreLimitsInput](#triplestorelimitsinput)**. Limitations regarding triple store usage.|
|`limits.max_byte_size`|**[Uint128](#uint128)\|null**. The maximum number of bytes the store can contain. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`limits.max_insert_data_byte_size`|**[Uint128](#uint128)\|null**. The maximum number of bytes an insert data query can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`limits.max_insert_data_triple_count`|**[Uint128](#uint128)\|null**. The maximum number of triples an insert data query can contain (after parsing). Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`limits.max_query_limit`|**integer\|null**. The maximum limit of a query, i.e. the maximum number of triples returned by a select query. Default to 30 if not set.|
|`limits.max_query_variable_count`|**integer\|null**. The maximum number of variables a query can select. Default to 30 if not set.|
|`limits.max_triple_byte_size`|**[Uint128](#uint128)\|null**. The maximum number of bytes the store can contain for a single triple. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. The limit is used to prevent storing very large triples, especially literals. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`limits.max_triple_count`|**[Uint128](#uint128)\|null**. The maximum number of triples the store can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.|

### TripleStoreConfig
### TripleStoreLimitsInput

`TripleStoreConfig` represents the configuration related to the management of the triple store.
Contains requested limitations regarding store usages.

|property|description|
|----------|-----------|
|`code_id`|*(Required.) * **[Uint64](#uint64)**. The code id that will be used to instantiate the triple store contract in which to store dataverse semantic data. It must implement the cognitarium interface.|
|`limits`|**[StoreLimitsInput](#storelimitsinput)**. Limitations regarding triple store usage.|
|`limits.max_byte_size`|**[Uint128](#uint128)**. The maximum number of bytes the store can contain. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. Default to [Uint128::MAX] if not set, which can be considered as no limit.<br />**Default:** `"340282366920938463463374607431768211455"`|
|`limits.max_insert_data_byte_size`|**[Uint128](#uint128)**. The maximum number of bytes an insert data query can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.<br />**Default:** `"340282366920938463463374607431768211455"`|
|`limits.max_insert_data_triple_count`|**[Uint128](#uint128)**. The maximum number of triples an insert data query can contain (after parsing). Default to [Uint128::MAX] if not set, which can be considered as no limit.<br />**Default:** `"340282366920938463463374607431768211455"`|
|`limits.max_query_limit`|**integer**. The maximum limit of a query, i.e. the maximum number of triples returned by a select query. Default to 30 if not set.<br />**Default:** `30`|
|`limits.max_query_variable_count`|**integer**. The maximum number of variables a query can select. Default to 30 if not set.<br />**Default:** `30`|
|`limits.max_triple_byte_size`|**[Uint128](#uint128)**. The maximum number of bytes the store can contain for a single triple. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. The limit is used to prevent storing very large triples, especially literals. Default to [Uint128::MAX] if not set, which can be considered as no limit.<br />**Default:** `"340282366920938463463374607431768211455"`|
|`limits.max_triple_count`|**[Uint128](#uint128)**. The maximum number of triples the store can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.<br />**Default:** `"340282366920938463463374607431768211455"`|
|`max_byte_size`|**[Uint128](#uint128)\|null**. The maximum number of bytes the store can contain. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_insert_data_byte_size`|**[Uint128](#uint128)\|null**. The maximum number of bytes an insert data query can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_insert_data_triple_count`|**[Uint128](#uint128)\|null**. The maximum number of triples an insert data query can contain (after parsing). Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_query_limit`|**integer\|null**. The maximum limit of a query, i.e. the maximum number of triples returned by a select query. Default to 30 if not set.|
|`max_query_variable_count`|**integer\|null**. The maximum number of variables a query can select. Default to 30 if not set.|
|`max_triple_byte_size`|**[Uint128](#uint128)\|null**. The maximum number of bytes the store can contain for a single triple. The size of a triple is counted as the sum of the size of its subject, predicate and object, including the size of data types and language tags if any. The limit is used to prevent storing very large triples, especially literals. Default to [Uint128::MAX] if not set, which can be considered as no limit.|
|`max_triple_count`|**[Uint128](#uint128)\|null**. The maximum number of triples the store can contain. Default to [Uint128::MAX] if not set, which can be considered as no limit.|

### Turtle

Expand Down Expand Up @@ -271,4 +271,4 @@ let b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```
---
*Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-dataverse.json` (`bee536f5330fd1e5`)*
*Rendered by [Fadroma](https://fadroma.tech) ([@fadroma/schema 1.1.0](https://www.npmjs.com/package/@fadroma/schema)) from `okp4-dataverse.json` (`569cd8a4d521dc5f`)*

0 comments on commit c142976

Please sign in to comment.