Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion contracts/treasury/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn instantiate(
msg.type_urls,
msg.grant_configs,
msg.fee_config,
msg.params,
)
}

Expand Down Expand Up @@ -58,7 +59,10 @@ pub fn execute(
ExecuteMsg::RevokeAllowance { grantee } => revoke_allowance(deps, env, info, grantee),
ExecuteMsg::UpdateParams { params } => update_params(deps, info, params),
ExecuteMsg::Withdraw { coins } => withdraw_coins(deps, info, coins),
ExecuteMsg::Migrate { new_code_id, migrate_msg } => execute::migrate(deps, env, info, new_code_id, migrate_msg),
ExecuteMsg::Migrate {
new_code_id,
migrate_msg,
} => execute::migrate(deps, env, info, new_code_id, migrate_msg),
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/treasury/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum ContractError {

#[error("grant config for {type_url} not found")]
GrantConfigNotFound { type_url: String },

#[error(transparent)]
JsonError(#[from] serde_json::Error),
}
Expand Down
24 changes: 17 additions & 7 deletions contracts/treasury/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn init(
type_urls: Vec<String>,
grant_configs: Vec<GrantConfig>,
fee_config: FeeConfig,
params: Params,
) -> ContractResult<Response> {
let treasury_admin = match admin {
None => info.sender,
Expand All @@ -42,6 +43,9 @@ pub fn init(

FEE_CONFIG.save(deps.storage, &fee_config)?;

validate_params(&params)?;
PARAMS.save(deps.storage, &params)?;

Ok(Response::new().add_event(
Event::new("create_treasury_instance")
.add_attributes(vec![("admin", treasury_admin.into_string())]),
Expand Down Expand Up @@ -208,20 +212,26 @@ pub fn update_fee_config(
Ok(Response::new().add_event(Event::new("updated_treasury_fee_config")))
}

pub fn update_params(deps: DepsMut, info: MessageInfo, params: Params) -> ContractResult<Response> {
let admin = ADMIN.load(deps.storage)?;
if admin != info.sender {
return Err(Unauthorized);
}

pub fn validate_params(params: &Params) -> ContractResult<()> {
Url::parse(params.display_url.as_str())?;
for url in params.redirect_urls.iter() {
Url::parse(url.as_str())?;
}

Url::parse(params.icon_url.as_str())?;
serde_json::from_str::<()>(params.metadata.as_str())?;

Ok(())
}

pub fn update_params(deps: DepsMut, info: MessageInfo, params: Params) -> ContractResult<Response> {
let admin = ADMIN.load(deps.storage)?;
if admin != info.sender {
return Err(Unauthorized);
}

validate_params(&params)?;

PARAMS.save(deps.storage, &params)?;

Ok(Response::new().add_event(Event::new("updated_params")))
Expand Down
3 changes: 2 additions & 1 deletion contracts/treasury/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct InstantiateMsg {
pub type_urls: Vec<String>,
pub grant_configs: Vec<GrantConfig>,
pub fee_config: FeeConfig,
pub params: Params,
}

#[cw_serde]
Expand Down Expand Up @@ -71,4 +72,4 @@ pub enum QueryMsg {
}

#[cw_serde]
pub struct MigrateMsg {}
pub struct MigrateMsg {}
Loading