use cosmwasm_std::{DepsMut, MessageInfo, Response, Uint64};
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_by_basic_uppercase_rule, validate_ipfs_cid, validate_particle,
};
use hub_base::ContractError;
use crate::state::{Entry, LIST};
pub fn execute_create_entry(
mut deps: DepsMut,
info: MessageInfo,
ticker: String,
chain_id: String,
contract: String,
decimals: Uint64,
channel_id: String,
logo: String,
particle: Option<String>,
) -> Result<Response, ContractError> {
check_owner(&deps, &info)?;
validate_by_basic_uppercase_rule(ticker.clone(), "ticker".to_string())?;
validate_by_basic_rule(chain_id.clone(), "chain_id".to_string())?;
validate_ipfs_cid(logo.clone(), "logo".to_string())?;
validate_particle(&particle)?;
let id = next_entry_id(&mut deps)?;
let new_entry = Entry {
id,
ticker,
chain_id,
contract,
decimals,
channel_id,
logo,
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,
ticker: Option<String>,
chain_id: Option<String>,
contract: Option<String>,
decimals: Option<Uint64>,
channel_id: Option<String>,
logo: Option<String>,
particle: Option<String>,
) -> Result<Response, ContractError> {
check_owner(&deps, &info)?;
if let Some(ref v) = ticker {
validate_by_basic_uppercase_rule(v.clone(), "ticker".to_string())?;
}
if let Some(ref v) = chain_id {
validate_by_basic_rule(v.clone(), "chain_id".to_string())?;
}
if let Some(ref v) = logo {
validate_ipfs_cid(v.clone(), "logo".to_string())?;
}
validate_particle(&particle)?;
if let Some(ref v) = contract {
validate_by_basic_rule(v.clone(), "contract".to_string())?;
}
if let Some(ref v) = channel_id {
validate_by_basic_rule(v.clone(), "channel_id".to_string())?;
}
let entry = LIST.load(deps.storage, id)?;
let updated_entry = Entry {
id,
ticker: ticker.unwrap_or(entry.ticker),
chain_id: chain_id.unwrap_or(entry.chain_id),
contract: contract.unwrap_or(entry.contract),
decimals: decimals.unwrap_or(entry.decimals),
channel_id: channel_id.unwrap_or(entry.channel_id),
logo: logo.unwrap_or(entry.logo),
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-tokens/src/execute.rs
ฯ 0.0%
use ;
pub use execute_update_owner;
use ;
use ;
use ContractError;
use crate;