Skip to content

Commit

Permalink
chore: improve idempotent-proxy-canister API
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jul 8, 2024
1 parent 5bd4943 commit 45bd33e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ strip = true
opt-level = 's'

[workspace.package]
version = "1.0.0"
version = "1.0.3"
edition = "2021"
repository = "https://github.com/ldclabs/idempotent-proxy"
keywords = ["idempotent", "reverse", "proxy", "icp"]
Expand Down
10 changes: 10 additions & 0 deletions examples/eth-canister-lite/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
"candid": "eth-canister-lite.did",
"package": "eth-canister-lite",
"type": "rust"
},
"idempotent-proxy-canister": {
"candid": "https://github.com/ldclabs/idempotent-proxy/releases/download/v1.0.3/idempotent_proxy_canister.did",
"type": "custom",
"wasm": "https://github.com/ldclabs/idempotent-proxy/releases/download/v1.0.3/idempotent_proxy_canister.wasm.gz",
"metadata": [
{
"name": "candid:service"
}
]
}
},
"defaults": {
Expand Down
3 changes: 2 additions & 1 deletion src/idempotent-proxy-canister/idempotent-proxy-canister.did
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ type UpgradeArgs = record { proxy_token_refresh_interval : opt nat64 };
service : (opt ChainArgs) -> {
admin_add_caller : (principal) -> (Result);
admin_remove_caller : (principal) -> (Result);
admin_set_agent : (vec Agent) -> (Result_1);
admin_set_agents : (vec Agent) -> (Result_1);
admin_set_managers : (vec principal) -> (Result_1);
get_state : () -> (Result_2) query;
parallel_call_all_ok : (CanisterHttpRequestArgument) -> (HttpResponse);
parallel_call_any_ok : (CanisterHttpRequestArgument) -> (HttpResponse);
proxy_http_request : (CanisterHttpRequestArgument) -> (HttpResponse);
validate_admin_set_agents : (vec Agent) -> (Result_1) query;
validate_admin_set_managers : (vec principal) -> (Result_1) query;
}
16 changes: 12 additions & 4 deletions src/idempotent-proxy-canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static ANONYMOUS: Principal = Principal::anonymous();

#[ic_cdk::update(guard = "is_controller")]
fn admin_set_managers(args: BTreeSet<Principal>) -> Result<(), String> {
validate_admin_set_managers(args.clone())?;
store::state::with_mut(|r| {
r.managers = args;
});
Expand All @@ -34,17 +35,24 @@ fn validate_admin_set_managers(args: BTreeSet<Principal>) -> Result<(), String>
}

#[ic_cdk::update(guard = "is_controller_or_manager")]
async fn admin_set_agent(agents: Vec<agent::Agent>) -> Result<(), String> {
if agents.is_empty() {
return Err("agents cannot be empty".to_string());
}
async fn admin_set_agents(agents: Vec<agent::Agent>) -> Result<(), String> {
validate_admin_set_agents(agents.clone())?;

let (ecdsa_key_name, proxy_token_refresh_interval) =
store::state::with(|s| (s.ecdsa_key_name.clone(), s.proxy_token_refresh_interval));
tasks::update_proxy_token(ecdsa_key_name, proxy_token_refresh_interval, agents).await;
Ok(())
}

#[ic_cdk::query]
fn validate_admin_set_agents(agents: Vec<agent::Agent>) -> Result<(), String> {
if agents.is_empty() {
return Err("agents cannot be empty".to_string());
}

Ok(())
}

#[ic_cdk::update(guard = "is_controller_or_manager")]
fn admin_add_caller(id: Principal) -> Result<bool, String> {
store::state::with_mut(|r| Ok(r.allowed_callers.insert(id)))
Expand Down

0 comments on commit 45bd33e

Please sign in to comment.