Skip to content

Commit

Permalink
feat(cognitarium): perform authorization before insert
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jun 1, 2023
1 parent 2bc8be5 commit 9c19cf3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions contracts/okp4-cognitarium/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::contract::execute::insert;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128,
};
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult};
use cw2::set_contract_version;

use crate::error::ContractError;
Expand Down Expand Up @@ -33,11 +31,11 @@ pub fn instantiate(
pub fn execute(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::InsertData { input } => insert(deps, input),
ExecuteMsg::InsertData { input } => insert(deps, info, input),
}
}

Expand All @@ -47,8 +45,16 @@ pub mod execute {
use crate::rdf;
use crate::state::TripleStorer;

pub fn insert(deps: DepsMut, graph: DataInput) -> Result<Response, ContractError> {
let mut reader = rdf::read_triples(&graph);
pub fn insert(
deps: DepsMut,
info: MessageInfo,
data: DataInput,
) -> Result<Response, ContractError> {
if STORE.load(deps.storage)?.owner != info.sender {
Err(ContractError::Unauthorized)?
}

let mut reader = rdf::read_triples(&data);
let mut storer = TripleStorer::new(deps.storage)?;
let count = storer.store_all(&mut reader)?;

Expand All @@ -71,7 +77,7 @@ mod tests {
use crate::state;
use crate::state::{namespaces, triples, Namespace};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{Attribute, Order};
use cosmwasm_std::{Attribute, Order, Uint128};
use std::env;
use std::fs::File;
use std::io::Read;
Expand Down

0 comments on commit 9c19cf3

Please sign in to comment.