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_chain_id, validate_particle, validate_url,
};
use hub_base::ContractError;
use crate::state::{Entry, LIST};
pub fn execute_create_entry(
mut deps: DepsMut,
info: MessageInfo,
active: String,
source_chain_id: String,
destination_chain_id: String,
source_channel_id: String,
destination_channel_id: String,
explorer_url: String,
particle: Option<String>,
) -> Result<Response, ContractError> {
check_owner(&deps, &info)?;
validate_particle(&particle)?;
validate_chain_id(source_chain_id.clone(), "source_chain_id".to_string())?;
validate_chain_id(
destination_chain_id.clone(),
"destination_chain_id".to_string(),
)?;
validate_by_basic_rule(source_channel_id.clone(), "source_channel_id".to_string())?;
validate_by_basic_rule(
destination_channel_id.clone(),
"destination_channel_id".to_string(),
)?;
validate_url(explorer_url.clone(), "explorer_url".to_string())?;
let id = next_entry_id(&mut deps)?;
let new_entry = Entry {
id,
active,
source_chain_id,
destination_chain_id,
source_channel_id,
destination_channel_id,
explorer_url,
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,
active: Option<String>,
source_chain_id: Option<String>,
destination_chain_id: Option<String>,
source_channel_id: Option<String>,
destination_channel_id: Option<String>,
explorer_url: Option<String>,
particle: Option<String>,
) -> Result<Response, ContractError> {
check_owner(&deps, &info)?;
validate_particle(&particle)?;
if let Some(ref v) = source_chain_id {
validate_chain_id(v.clone(), "source_chain_id".to_string())?;
}
if let Some(ref v) = destination_chain_id {
validate_chain_id(v.clone(), "destination_chain_id".to_string())?;
}
if let Some(ref v) = source_channel_id {
validate_by_basic_rule(v.clone(), "source_channel_id".to_string())?;
}
if let Some(ref v) = destination_channel_id {
validate_by_basic_rule(v.clone(), "destination_channel_id".to_string())?;
}
if let Some(ref v) = explorer_url {
validate_url(v.clone(), "explorer_url".to_string())?;
}
let entry = LIST.load(deps.storage, id)?;
let updated_entry = Entry {
id,
active: active.unwrap_or(entry.active),
source_chain_id: source_chain_id.unwrap_or(entry.source_chain_id),
destination_chain_id: destination_chain_id.unwrap_or(entry.destination_chain_id),
source_channel_id: source_channel_id.unwrap_or(entry.source_channel_id),
destination_channel_id: destination_channel_id.unwrap_or(entry.destination_channel_id),
explorer_url: explorer_url.unwrap_or(entry.explorer_url),
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-channels/src/execute.rs
ฯ 0.0%
use ;
pub use execute_update_owner;
use ;
use ;
use ContractError;
use crate;