Skip to content

Commit

Permalink
feat(dataverse): implement instantiate msg
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Nov 16, 2023
1 parent 1c05850 commit f5fade2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
41 changes: 37 additions & 4 deletions contracts/okp4-dataverse/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult};
use cosmwasm_std::{
instantiate2_address, to_binary, Binary, CodeInfoResponse, Deps, DepsMut, Env, MessageInfo,
Response, StdError, StdResult, WasmMsg,
};
use cw2::set_contract_version;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{Dataverse, DATAVERSE};

// version info for migration info
const CONTRACT_NAME: &str = concat!("crates.io:", env!("CARGO_PKG_NAME"));
Expand All @@ -13,13 +17,42 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut<'_>,
_env: Env,
env: Env,
_info: MessageInfo,
_msg: InstantiateMsg,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Err(StdError::generic_err("Not implemented").into())
let creator = deps.api.addr_canonicalize(env.contract.address.as_str())?;
let CodeInfoResponse { checksum, .. } = deps
.querier
.query_wasm_code_info(msg.triplestore_config.code_id.u64())?;
let salt = Binary::from(msg.name.as_bytes());

let triplestore_address = deps
.api
.addr_humanize(&instantiate2_address(&checksum, &creator, &salt)?)?;

DATAVERSE.save(
deps.storage,
&Dataverse {
name: msg.name.clone(),
triplestore_address: triplestore_address.to_string(),
},
)?;

Ok(Response::new()
.add_attribute("triplestore_address", triplestore_address)
.add_message(WasmMsg::Instantiate2 {
admin: Some(env.contract.address.to_string()),
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,
})?,
funds: vec![],
salt,
}))
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
5 changes: 4 additions & 1 deletion contracts/okp4-dataverse/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use cosmwasm_std::StdError;
use cosmwasm_std::{Instantiate2AddressError, StdError};
use thiserror::Error;

#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),

#[error("{0}")]
Instantiate2Address(#[from] Instantiate2AddressError),
}

0 comments on commit f5fade2

Please sign in to comment.