diff --git a/contracts/treasury/src/contract.rs b/contracts/treasury/src/contract.rs index c09bd6ef..6c676d64 100644 --- a/contracts/treasury/src/contract.rs +++ b/contracts/treasury/src/contract.rs @@ -27,6 +27,7 @@ pub fn instantiate( msg.type_urls, msg.grant_configs, msg.fee_config, + msg.params, ) } @@ -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), } } diff --git a/contracts/treasury/src/error.rs b/contracts/treasury/src/error.rs index 9beb6da4..cfa7af0b 100644 --- a/contracts/treasury/src/error.rs +++ b/contracts/treasury/src/error.rs @@ -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), } diff --git a/contracts/treasury/src/execute.rs b/contracts/treasury/src/execute.rs index 02f2563d..21a11c9a 100644 --- a/contracts/treasury/src/execute.rs +++ b/contracts/treasury/src/execute.rs @@ -25,6 +25,7 @@ pub fn init( type_urls: Vec, grant_configs: Vec, fee_config: FeeConfig, + params: Params, ) -> ContractResult { let treasury_admin = match admin { None => info.sender, @@ -42,6 +43,9 @@ pub fn init( FEE_CONFIG.save(deps.storage, &fee_config)?; + validate_params(¶ms)?; + PARAMS.save(deps.storage, ¶ms)?; + Ok(Response::new().add_event( Event::new("create_treasury_instance") .add_attributes(vec![("admin", treasury_admin.into_string())]), @@ -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 { - 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 { + let admin = ADMIN.load(deps.storage)?; + if admin != info.sender { + return Err(Unauthorized); + } + + validate_params(¶ms)?; + PARAMS.save(deps.storage, ¶ms)?; Ok(Response::new().add_event(Event::new("updated_params"))) diff --git a/contracts/treasury/src/msg.rs b/contracts/treasury/src/msg.rs index c71cf550..755b60ca 100644 --- a/contracts/treasury/src/msg.rs +++ b/contracts/treasury/src/msg.rs @@ -9,6 +9,7 @@ pub struct InstantiateMsg { pub type_urls: Vec, pub grant_configs: Vec, pub fee_config: FeeConfig, + pub params: Params, } #[cw_serde] @@ -71,4 +72,4 @@ pub enum QueryMsg { } #[cw_serde] -pub struct MigrateMsg {} \ No newline at end of file +pub struct MigrateMsg {}