Skip to content

Commit 190adb7

Browse files
committed
Add CyclesWalletRuntime
1 parent 4fa36b1 commit 190adb7

File tree

6 files changed

+64
-94
lines changed

6 files changed

+64
-94
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ num-traits = "0.2.19"
2828
pin-project = "1.1.10"
2929
pocket-ic = "9.0.2"
3030
proptest = "1.6.0"
31+
regex-lite = "0.1.8"
3132
serde = "1.0"
33+
serde_bytes = "0.11.19"
3234
serde_json = "1.0"
3335
sha2 = "0.10.8"
3436
strum = { version = "0.27.1", features = ["derive"] }

ic-canister-runtime/CHANGELOG.md

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,4 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [0.3.0] - 2025-10-08
9-
10-
### Added
11-
- **Breaking:** A new method `charge_cycles` that does the actual charging was added to `CyclesChargingPolicy` ([#7](https://github.com/dfinity/canhttp/pull/7))
12-
- Example of canister using the library to make HTTP requests ([#6](https://github.com/dfinity/canhttp/pull/6))
13-
14-
### Changed
15-
- **Breaking:** Update `ic-cdk` to `v0.18.7` including several changes to align with the new HTTP outcall API ([#21](https://github.com/dfinity/canhttp/pull/21)). Notably:
16-
- `IcError` is refactored into an enum
17-
- Use of the new `HttpRequestArgs` and `HttpRequestResult` types in `CyclesChargingPolicy` and `Client` trait impls
18-
- Removal of `IcHttpRequestWithCycles`, `CyclesCostEstimator`, `CyclesAccountingError` and `CyclesAccounting` due to the `ic-cdk` method for making HTTP outcalls now taking care of charging cycles
19-
20-
[0.3.0]: https://github.com/dfinity/canhttp/compare/canhttp-v0.2.1..canhttp-v0.3.0
21-
22-
## [0.2.1] - 2025-07-11
23-
24-
### Added
25-
26-
- An `iter` method to `canhttp::multi::MultiResults` returning a borrowing iterator.
27-
28-
### Changed
29-
- The `canhttp` crate has been moved from the [`evm-rpc-canister`](https://github.com/dfinity/evm-rpc-canister) repository to the new [`canhttp`](https://github.com/dfinity/canhttp) repository.
30-
31-
[0.2.1]: https://github.com/dfinity/canhttp/compare/canhttp-v0.2.0..canhttp-v0.2.1
32-
33-
## [0.2.0] - 2025-07-08
34-
35-
### Added
36-
- Data structures `TimedSizedVec<T>` and `TimedSizedMap<K, V>` to store a limited number of expiring elements ([#434](https://github.com/dfinity/evm-rpc-canister/pull/434))
37-
- Method to list `Ok` results in a `MultiResults` ([#435](https://github.com/dfinity/evm-rpc-canister/pull/435))
38-
39-
### Changed
40-
41-
- **Breaking:** change the `code` field in the `IcError` type to use `ic_error_types::RejectCode` instead of `ic_cdk::api::call::RejectionCode` ([#428](https://github.com/dfinity/evm-rpc-canister/pull/428))
42-
43-
[0.2.0]: https://github.com/dfinity/canhttp/compare/canhttp-v0.1.0..canhttp-v0.2.0
44-
45-
## [0.1.0] - 2025-06-04
46-
47-
### Added
48-
49-
- JSON-RPC request ID with constant binary size ([#397](https://github.com/dfinity/evm-rpc-canister/pull/397))
50-
- Use `canhttp` to make parallel calls ([#391](https://github.com/dfinity/evm-rpc-canister/pull/391))
51-
- Improve validation of JSON-RPC requests and responses to adhere to the JSON-RPC specification ([#386](https://github.com/dfinity/evm-rpc-canister/pull/386) and [#387](https://github.com/dfinity/evm-rpc-canister/pull/387))
52-
- Retry layer ([#378](https://github.com/dfinity/evm-rpc-canister/pull/378))
53-
- JSON RPC conversion layer ([#375](https://github.com/dfinity/evm-rpc-canister/pull/375))
54-
- HTTP conversion layer ([#374](https://github.com/dfinity/evm-rpc-canister/pull/374))
55-
- Observability layer ([#370](https://github.com/dfinity/evm-rpc-canister/pull/370))
56-
- Library `canhttp` ([#364](https://github.com/dfinity/evm-rpc-canister/pull/364))
57-
58-
[0.1.0]: https://github.com/dfinity/canhttp/releases/tag/canhttp-v0.1.0
8+
## Unreleased

ic-canister-runtime/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ include = ["src", "Cargo.toml", "CHANGELOG.md", "LICENSE", "README.md"]
1111
repository.workspace = true
1212
documentation = "https://docs.rs/canruntime"
1313

14+
[features]
15+
wallet = ["dep:regex-lite", "dep:serde_bytes"]
16+
1417
[dependencies]
1518
async-trait = { workspace = true }
1619
candid = { workspace = true }
1720
ic-cdk = { workspace = true }
1821
ic-error-types = { workspace = true }
22+
regex-lite = { workspace = true, optional = true }
1923
serde = { workspace = true }
24+
serde_bytes = { workspace = true, optional = true }
2025
thiserror = { workspace = true }
2126

2227
[dev-dependencies]

ic-canister-runtime/src/lib.rs

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ use ic_cdk::call::{Call, CallFailed, CandidDecodeFailed};
1212
use ic_error_types::RejectCode;
1313
use serde::de::DeserializeOwned;
1414
use thiserror::Error;
15+
#[cfg(feature = "wallet")]
16+
pub use wallet::CyclesWalletRuntime;
17+
18+
#[cfg(feature = "wallet")]
19+
mod wallet;
1520

1621
/// Abstract the canister runtime so that code making requests to canisters can be reused:
1722
/// * in production using [`ic_cdk`],
@@ -43,49 +48,6 @@ pub trait Runtime {
4348
Out: CandidType + DeserializeOwned;
4449
}
4550

46-
/// Runtime when interacting with a canister running on the Internet Computer.
47-
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
48-
pub struct IcRuntime;
49-
50-
#[async_trait]
51-
impl Runtime for IcRuntime {
52-
async fn update_call<In, Out>(
53-
&self,
54-
id: Principal,
55-
method: &str,
56-
args: In,
57-
cycles: u128,
58-
) -> Result<Out, IcError>
59-
where
60-
In: ArgumentEncoder + Send,
61-
Out: CandidType + DeserializeOwned,
62-
{
63-
Call::unbounded_wait(id, method)
64-
.with_args(&args)
65-
.with_cycles(cycles)
66-
.await
67-
.map_err(IcError::from)
68-
.and_then(|response| response.candid::<Out>().map_err(IcError::from))
69-
}
70-
71-
async fn query_call<In, Out>(
72-
&self,
73-
id: Principal,
74-
method: &str,
75-
args: In,
76-
) -> Result<Out, IcError>
77-
where
78-
In: ArgumentEncoder + Send,
79-
Out: CandidType + DeserializeOwned,
80-
{
81-
Call::unbounded_wait(id, method)
82-
.with_args(&args)
83-
.await
84-
.map_err(IcError::from)
85-
.and_then(|response| response.candid::<Out>().map_err(IcError::from))
86-
}
87-
}
88-
8951
/// Error returned by the Internet Computer when making an inter-canister call.
9052
#[derive(Error, Clone, Debug, PartialEq, Eq)]
9153
pub enum IcError {
@@ -151,3 +113,46 @@ impl From<CandidDecodeFailed> for IcError {
151113
}
152114
}
153115
}
116+
117+
/// Runtime when interacting with a canister running on the Internet Computer.
118+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
119+
pub struct IcRuntime;
120+
121+
#[async_trait]
122+
impl Runtime for IcRuntime {
123+
async fn update_call<In, Out>(
124+
&self,
125+
id: Principal,
126+
method: &str,
127+
args: In,
128+
cycles: u128,
129+
) -> Result<Out, IcError>
130+
where
131+
In: ArgumentEncoder + Send,
132+
Out: CandidType + DeserializeOwned,
133+
{
134+
Call::unbounded_wait(id, method)
135+
.with_args(&args)
136+
.with_cycles(cycles)
137+
.await
138+
.map_err(IcError::from)
139+
.and_then(|response| response.candid::<Out>().map_err(IcError::from))
140+
}
141+
142+
async fn query_call<In, Out>(
143+
&self,
144+
id: Principal,
145+
method: &str,
146+
args: In,
147+
) -> Result<Out, IcError>
148+
where
149+
In: ArgumentEncoder + Send,
150+
Out: CandidType + DeserializeOwned,
151+
{
152+
Call::unbounded_wait(id, method)
153+
.with_args(&args)
154+
.await
155+
.map_err(IcError::from)
156+
.and_then(|response| response.candid::<Out>().map_err(IcError::from))
157+
}
158+
}

ic-canister-runtime/src/wallet.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)