From fe42ec7802f4a43c0c24bee8bf77d45b511f2131 Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Thu, 26 Sep 2024 08:06:28 +0800 Subject: [PATCH] fix: fix validation function for SNS proposal --- Cargo.lock | 6 ++--- Cargo.toml | 2 +- .../idempotent-proxy-canister.did | 4 ++++ .../src/api_admin.rs | 24 +++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 719278e..6afe7a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1241,7 +1241,7 @@ dependencies = [ [[package]] name = "idempotent-proxy-canister" -version = "1.2.0" +version = "1.2.1" dependencies = [ "base64", "candid", @@ -1259,7 +1259,7 @@ dependencies = [ [[package]] name = "idempotent-proxy-server" -version = "1.2.0" +version = "1.2.1" dependencies = [ "async-trait", "axum", @@ -1285,7 +1285,7 @@ dependencies = [ [[package]] name = "idempotent-proxy-types" -version = "1.2.0" +version = "1.2.1" dependencies = [ "base64", "ciborium", diff --git a/Cargo.toml b/Cargo.toml index c658906..baf94cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ strip = true opt-level = 's' [workspace.package] -version = "1.2.0" +version = "1.2.1" edition = "2021" repository = "https://github.com/ldclabs/idempotent-proxy" keywords = ["idempotent", "reverse", "proxy", "icp"] diff --git a/src/idempotent-proxy-canister/idempotent-proxy-canister.did b/src/idempotent-proxy-canister/idempotent-proxy-canister.did index f39fcb5..30816fa 100644 --- a/src/idempotent-proxy-canister/idempotent-proxy-canister.did +++ b/src/idempotent-proxy-canister/idempotent-proxy-canister.did @@ -30,6 +30,7 @@ type InitArgs = record { }; type Result = variant { Ok : bool; Err : text }; type Result_1 = variant { Ok; Err : text }; +type Result_2 = variant { Ok : text; Err : text }; type StateInfo = record { proxy_token_public_key : text; service_fee : nat64; @@ -68,6 +69,9 @@ service : (opt ChainArgs) -> { proxy_http_request : (CanisterHttpRequestArgument) -> (HttpResponse); proxy_http_request_cost : (CanisterHttpRequestArgument) -> (nat) query; state_info : () -> (StateInfo) query; + validate2_admin_add_managers : (vec principal) -> (Result_2); + validate2_admin_remove_managers : (vec principal) -> (Result_2); + validate2_admin_set_agents : (vec Agent) -> (Result_2); validate_admin_add_managers : (vec principal) -> (Result_1); validate_admin_remove_managers : (vec principal) -> (Result_1); validate_admin_set_agents : (vec Agent) -> (Result_1); diff --git a/src/idempotent-proxy-canister/src/api_admin.rs b/src/idempotent-proxy-canister/src/api_admin.rs index 9d00c53..1885551 100644 --- a/src/idempotent-proxy-canister/src/api_admin.rs +++ b/src/idempotent-proxy-canister/src/api_admin.rs @@ -67,18 +67,33 @@ async fn admin_set_agents(agents: Vec) -> Result<(), String> { Ok(()) } +// Use validate2_admin_add_managers instead of validate_admin_add_managers #[ic_cdk::update] fn validate_admin_add_managers(args: BTreeSet) -> Result<(), String> { validate_principals(&args)?; Ok(()) } +#[ic_cdk::update] +fn validate2_admin_add_managers(args: BTreeSet) -> Result { + validate_principals(&args)?; + Ok("ok".to_string()) +} + +// Use validate2_admin_remove_managers instead of validate_admin_remove_managers #[ic_cdk::update] fn validate_admin_remove_managers(args: BTreeSet) -> Result<(), String> { validate_principals(&args)?; Ok(()) } +#[ic_cdk::update] +fn validate2_admin_remove_managers(args: BTreeSet) -> Result { + validate_principals(&args)?; + Ok("ok".to_string()) +} + +// Use validate2_admin_set_agents instead of validate_admin_set_agents #[ic_cdk::update] fn validate_admin_set_agents(agents: Vec) -> Result<(), String> { if agents.is_empty() { @@ -87,3 +102,12 @@ fn validate_admin_set_agents(agents: Vec) -> Result<(), String> { Ok(()) } + +#[ic_cdk::update] +fn validate2_admin_set_agents(agents: Vec) -> Result { + if agents.is_empty() { + return Err("agents cannot be empty".to_string()); + } + + Ok("ok".to_string()) +}