use cosmwasm_std::{DepsMut, MessageInfo, Response};
pub use hub_base::execute::execute_update_owner;
use hub_base::execute::{check_owner, next_entry_id};
use hub_base::validating::{
validate_by_basic_rule, validate_ipfs_cid, validate_particle, validate_url,
};
use hub_base::ContractError;
use crate::state::{Entry, LIST};
pub fn execute_create_entry(
mut deps: DepsMut,
info: MessageInfo,
address: String,
init_particle: String,
execute_particle: String,
query_particle: String,
version: String,
chain_id: String,
particle: Option<String>,
) -> Result<Response, ContractError> {
check_owner(&deps, &info)?;
validate_particle(&particle)?;
validate_by_basic_rule(address.clone(), "address".to_string())?;
validate_ipfs_cid(init_particle.clone(), "init_particle".to_string())?;
validate_ipfs_cid(execute_particle.clone(), "execute_particle".to_string())?;
validate_ipfs_cid(query_particle.clone(), "query_particle".to_string())?;
validate_url(version.clone(), "version".to_string())?;
validate_url(chain_id.clone(), "chain_id".to_string())?;
let id = next_entry_id(&mut deps)?;
let new_entry = Entry {
id,
address,
init_particle,
execute_particle,
query_particle,
version,
chain_id,
particle: particle.unwrap_or("".to_string()),
};
LIST.save(deps.storage, id, &new_entry)?;
Ok(Response::new()
.add_attribute("method", "execute_create_entry")
.add_attribute("new_entry_id", id.to_string()))
}
pub fn execute_update_entry(
deps: DepsMut,
info: MessageInfo,
id: u64,
address: Option<String>,
init_particle: Option<String>,
execute_particle: Option<String>,
query_particle: Option<String>,
version: Option<String>,
chain_id: Option<String>,
particle: Option<String>,
) -> Result<Response, ContractError> {
check_owner(&deps, &info)?;
validate_particle(&particle)?;
if let Some(ref v) = address {
validate_by_basic_rule(v.clone(), "address".to_string())?;
}
if let Some(ref v) = init_particle {
validate_ipfs_cid(v.clone(), "init_particle".to_string())?;
}
if let Some(ref v) = execute_particle {
validate_ipfs_cid(v.clone(), "execute_particle".to_string())?;
}
if let Some(ref v) = query_particle {
validate_ipfs_cid(v.clone(), "query_particle".to_string())?;
}
if let Some(ref v) = version {
validate_url(v.clone(), "version".to_string())?;
}
if let Some(ref v) = chain_id {
validate_url(v.clone(), "chain_id".to_string())?;
}
let entry = LIST.load(deps.storage, id)?;
let updated_entry = Entry {
id,
address: address.unwrap_or(entry.address),
init_particle: init_particle.unwrap_or(entry.init_particle),
execute_particle: execute_particle.unwrap_or(entry.execute_particle),
query_particle: query_particle.unwrap_or(entry.query_particle),
version: version.unwrap_or(entry.version),
chain_id: chain_id.unwrap_or(entry.chain_id),
particle: particle.unwrap_or(entry.particle),
};
LIST.save(deps.storage, id, &updated_entry)?;
Ok(Response::new()
.add_attribute("method", "execute_update_entry")
.add_attribute("updated_entry_id", id.to_string()))
}
cw-cyber/contracts/hub-libs/src/execute.rs
ฯ 0.0%
use ;
pub use execute_update_owner;
use ;
use ;
use ContractError;
use crate;