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_ipfs_cid, validate_particle,
    validate_period,
};
use hub_base::ContractError;

use crate::state::{Entry, LIST};

pub fn execute_create_entry(
    mut deps: DepsMut,
    info: MessageInfo,
    name: String,
    chain_id: String,
    prefix: String,
    genesis_hash: String,
    protocol: String,
    unbonding_period: String,
    logo: String,
    particle: Option<String>,
) -> Result<Response, ContractError> {
    check_owner(&deps, &info)?;

    validate_ipfs_cid(genesis_hash.clone(), "genesis_hash".to_string())?;
    validate_ipfs_cid(logo.clone(), "logo".to_string())?;
    validate_particle(&particle)?;
    validate_chain_id(chain_id.clone(), "chain_id".to_string())?;
    validate_by_basic_rule(prefix.clone(), "prefix".to_string())?;
    validate_by_basic_rule(name.clone(), "name".to_string())?;
    validate_by_basic_rule(protocol.clone(), "protocol".to_string())?;
    validate_period(unbonding_period.clone(), "unbonding_period".to_string())?;

    let id = next_entry_id(&mut deps)?;

    let new_entry = Entry {
        id,
        name,
        chain_id,
        prefix,
        genesis_hash,
        protocol,
        unbonding_period,
        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,
    name: Option<String>,
    chain_id: Option<String>,
    prefix: Option<String>,
    genesis_hash: Option<String>,
    protocol: Option<String>,
    unbonding_period: Option<String>,
    logo: Option<String>,
    particle: Option<String>,
) -> Result<Response, ContractError> {
    check_owner(&deps, &info)?;

    if let Some(ref v) = genesis_hash {
        validate_ipfs_cid(v.clone(), "genesis_hash".to_string())?;
    }
    if let Some(ref v) = logo {
        validate_ipfs_cid(v.clone(), "logo".to_string())?;
    }
    validate_particle(&particle)?;
    if let Some(ref v) = chain_id {
        validate_chain_id(v.clone(), "chain_id".to_string())?;
    }
    if let Some(ref v) = prefix {
        validate_by_basic_rule(v.clone(), "prefix".to_string())?;
    }
    if let Some(ref v) = name {
        validate_by_basic_rule(v.clone(), "name".to_string())?;
    }
    if let Some(ref v) = protocol {
        validate_by_basic_rule(v.clone(), "protocol".to_string())?;
    }
    if let Some(ref v) = unbonding_period {
        validate_period(v.clone(), "unbonding_period".to_string())?;
    }

    let entry = LIST.load(deps.storage, id)?;
    let updated_entry = Entry {
        id,
        name: name.unwrap_or(entry.name),
        chain_id: chain_id.unwrap_or(entry.chain_id),
        prefix: prefix.unwrap_or(entry.prefix),
        genesis_hash: genesis_hash.unwrap_or(entry.genesis_hash),
        protocol: protocol.unwrap_or(entry.protocol),
        unbonding_period: unbonding_period.unwrap_or(entry.unbonding_period),
        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()))
}

Dimensions

trident/src/neural/inference/execute.rs
cw-cyber/packages/hub-base/src/execute.rs
cw-cyber/contracts/hub-channels/src/execute.rs
cw-cyber/contracts/hub-skills/src/execute.rs
cw-cyber/contracts/graph-filter/src/execute.rs
cw-cyber/contracts/cw-cyber-gift/src/execute.rs
cw-cyber/contracts/cw-cyber-subgraph/src/execute.rs
cw-cyber/contracts/hub-tokens/src/execute.rs
cw-cyber/contracts/hub-libs/src/execute.rs
cw-cyber/contracts/hub-protocols/src/execute.rs
cw-cyber/contracts/cw-cyber-passport/src/execute.rs

Local Graph