Skip to content

Commit

Permalink
feat: support receiving cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jul 17, 2024
1 parent d18895a commit 0aae62a
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 70 deletions.
88 changes: 44 additions & 44 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.3"
version = "1.1.0"
edition = "2021"
repository = "https://github.com/ldclabs/idempotent-proxy"
keywords = ["idempotent", "reverse", "proxy", "icp"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ This service can be used to proxy [HTTPS outcalls](https://internetcomputer.org/
- Deployable with Docker or Cloudflare Worker
- On-chain Idempotent Proxy service on the ICP

## Packages
## Libraries

| Package | Description |
| Library | Description |
| :----------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------- |
| [idempotent-proxy-server](https://github.com/ldclabs/idempotent-proxy/tree/main/src/idempotent-proxy-server) | Idempotent Proxy implemented in Rust. |
| [idempotent-proxy-cf-worker](https://github.com/ldclabs/idempotent-proxy/tree/main/src/idempotent-proxy-cf-worker) | Idempotent Proxy implemented as Cloudflare Worker. |
Expand Down
21 changes: 13 additions & 8 deletions examples/eth-canister-lite/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,19 @@ impl EthereumRPC {
transform: None,
};

let (res,): (HttpResponse,) = ic_cdk::call(self.proxy, proxy_method, (request,))
.await
.map_err(|(code, msg)| {
format!(
"failed to call {} on {:?}, code: {}, message: {}",
proxy_method, &self.proxy, code as u32, msg
)
})?;
let (res,): (HttpResponse,) = ic_cdk::api::call::call_with_payment128(
self.proxy,
proxy_method,
(request,),
1_000_000_000, // max cycles, unspent cycles will be refunded
)
.await
.map_err(|(code, msg)| {
format!(
"failed to call {} on {:?}, code: {}, message: {}",
proxy_method, &self.proxy, code as u32, msg
)
})?;

if res.status >= 200u64 && res.status < 300u64 {
Ok(res.body)
Expand Down
11 changes: 11 additions & 0 deletions src/idempotent-proxy-canister/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ dfx deploy idempotent-proxy-canister --argument "(opt variant {Init =
record {
ecdsa_key_name = \"dfx_test_key\";
proxy_token_refresh_interval = 3600;
subnet_size = 1;
service_fee = 10_000_000;
}
})"

dfx canister call idempotent-proxy-canister get_state '()'

# upgrade
dfx deploy idempotent-proxy-canister --argument "(opt variant {Upgrade =
record {
proxy_token_refresh_interval = null;
subnet_size = opt 13;
service_fee = opt 100_000_000;
}
})"

# 3 same agents for testing
dfx canister call idempotent-proxy-canister admin_set_agents '
(vec {
Expand Down
Loading

0 comments on commit 0aae62a

Please sign in to comment.