Skip to content

Commit

Permalink
Add SudoMsg::UpdateConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Aug 31, 2023
1 parent 1f3e012 commit 3cfd65f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
15 changes: 10 additions & 5 deletions contracts/vip/minter/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ pub enum ExecuteMsg {
pub enum SudoMsg {
BeginBlock {}, // Is called by x/cron module BeginBlocker
EndBlock {}, // Is called by x/cron module EndBlocker
// UpdateParams {
// // fair_burn: Option<String>,
// // trading_fee_percent: Option<Decimal>,
// // min_bid_increment_percent: Option<Decimal>,
// },
// UpdateParams {
// // fair_burn: Option<String>,
// // trading_fee_percent: Option<Decimal>,
// // min_bid_increment_percent: Option<Decimal>,
// },
UpdateConfig {
vip_collection: Option<String>,
name_collection: Option<String>,
update_interval: Option<u64>,
},
}

#[cw_serde]
Expand Down
40 changes: 37 additions & 3 deletions contracts/vip/minter/src/sudo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{DepsMut, Env, Response};
use cosmwasm_std::{DepsMut, Env, Event, Response};

use crate::{
contract::{associated_address, mint},
Expand All @@ -14,6 +14,11 @@ pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response, ContractE
match msg {
SudoMsg::BeginBlock {} => sudo_begin_block(deps, env),
SudoMsg::EndBlock {} => sudo_end_block(deps, env),
SudoMsg::UpdateConfig {
vip_collection,
name_collection,
update_interval,
} => sudo_execute_update_config(deps, vip_collection, name_collection, update_interval),
// SudoMsg::UpdateParams {
// fair_burn,
// trading_fee_percent,
Expand All @@ -33,7 +38,7 @@ pub fn sudo_begin_block(deps: DepsMut, env: Env) -> Result<Response, ContractErr
}

pub fn sudo_end_block(deps: DepsMut, env: Env) -> Result<Response, ContractError> {
let Config {
/*let Config {
vip_collection,
update_interval,
..
Expand All @@ -59,5 +64,34 @@ pub fn sudo_end_block(deps: DepsMut, env: Env) -> Result<Response, ContractError
NAME_QUEUE.remove(deps.storage, env.block.height);
NAME_QUEUE.save(deps.storage, env.block.height + update_interval, &names)?;
Ok(Response::new().add_messages(mint_msgs))
Ok(Response::new().add_messages(mint_msgs))*/
Ok(Response::new())
}

pub fn sudo_execute_update_config(
deps: DepsMut,
vip_collection: Option<String>,
name_collection: Option<String>,
update_interval: Option<u64>,
) -> Result<Response, ContractError> {
let mut config = CONFIG.load(deps.storage)?;
if let Some(vip_collection) = vip_collection {
config.vip_collection = deps.api.addr_validate(&vip_collection)?;
}
if let Some(name_collection) = name_collection {
config.name_collection = deps.api.addr_validate(&name_collection)?;
}
if let Some(update_interval) = update_interval {
// TODO: define a min and max for update_interval (and update the error)
if update_interval < 1 {
return Err(ContractError::InvalidUpdateInterval {});
}
config.update_interval = update_interval;
}
CONFIG.save(deps.storage, &config)?;
let event = Event::new("sudo_update_config")
.add_attribute("vip_collection", config.vip_collection)
.add_attribute("name_collection", config.name_collection)
.add_attribute("update_interval", config.update_interval.to_string());
Ok(Response::new().add_event(event))
}

0 comments on commit 3cfd65f

Please sign in to comment.