Skip to content

Commit 5ff10c4

Browse files
committed
wip
1 parent df4d639 commit 5ff10c4

File tree

34 files changed

+1025
-731
lines changed

34 files changed

+1025
-731
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ panic = "abort"
3232

3333

3434
[workspace.dependencies]
35-
candid = { version = "0.10.14", features = ["value"] }
35+
candid = { version = "0.10.20", features = ["value"] }
3636
ciborium = "0.2.2"
3737
futures = "0.3.29"
3838
# Enable `custom` feature of k256's getrandom dependency. See icp_neuron/impl/src/ecdsa.rs for more details.
39-
getrandom = { version = "0.3.1", features = ["custom"] }
39+
getrandom = { version = "0.3.4", features = ["custom"] }
4040
hex = "0.4.3"
41-
ic-cdk = "0.18.3"
42-
ic-cdk-macros = "0.18.3"
41+
ic-cdk = "0.18.7"
42+
ic-cdk-macros = "0.18.7"
4343
ic-cdk-timers = "0.12.0"
4444
ic-ledger-types = "0.15.0"
45-
ic-stable-structures = "0.6.9"
46-
ic-transport-types = "0.39.3"
47-
ic0 = "0.25.1"
48-
icrc-ledger-types = "0.1.8"
45+
ic-stable-structures = "0.7.2"
46+
ic-transport-types = "0.44.3"
47+
ic0 = "1.0.1"
48+
icrc-ledger-types = "0.1.12"
4949
k256 = "0.13.1"
50-
proc-macro2 = "1.0.93"
51-
quote = "1.0.33"
50+
proc-macro2 = "1.0.103"
51+
quote = "1.0.41"
5252
rmp-serde = "1.1.2"
53-
serde = "1.0.196"
54-
serde_bytes = "0.11.12"
53+
serde = "1.0.228"
54+
serde_bytes = "0.11.19"
5555
serde_cbor = "0.11.2"
56-
serde_json = "1.0.138"
56+
serde_json = "1.0.145"
5757
serde_with = "3.7.0"
5858
serde_yaml = "0.9.33"
5959
serde_tokenstream = "0.2.2"
@@ -63,9 +63,9 @@ syn = { version = "2.0.103", features = [
6363
] }
6464
tracing = "0.1.41"
6565
tracing-attributes = "0.1.29"
66-
tracing-subscriber = "0.3.18"
66+
tracing-subscriber = "0.3.20"
6767
num-bigint = "0.4.4"
68-
time = { version = "0.3.36", features = [
68+
time = { version = "0.3.44", features = [
6969
"macros",
7070
"serde",
7171
"parsing",
@@ -79,25 +79,39 @@ canfund = "0.8.4"
7979
ic-asset-certification = "3.0.3"
8080
ic-http-certification = "3.0.3"
8181
sha256 = "1.6.0"
82-
pocket-ic = "9.0.2"
82+
pocket-ic = "10.0.0"
8383
ic-certification = "3.0.3"
8484
leb128 = "0.2.5"
8585
num-traits = { version = "0.2.12", features = ["libm"] }
8686
deluxe = "0.5.0"
8787
lazy_static = "1.4.0"
88-
anyhow = "1.0.98"
88+
anyhow = "1.0.100"
8989
ic-management-canister-types = "0.3.1"
9090

91-
bity-ic-canister-client = "0.2.4"
92-
bity-ic-canister-logger = "0.2.0"
93-
bity-ic-canister-state-macros = "0.1.0"
94-
bity-ic-canister-tracing-macros = "0.1.0"
95-
bity-ic-canister-time = "0.2.0"
96-
bity-ic-serializer = "0.1.0"
97-
bity-ic-stable-memory = "0.2.0"
98-
bity-ic-types = "0.1.1"
99-
bity-ic-utils = "0.2.0"
100-
bity-ic-subcanister-manager = "0.3.0"
101-
bity-ic-icrc3-archive-api = "0.3.0"
102-
bity-ic-icrc3-archive-c2c-client = "0.3.2"
103-
bity-ic-icrc3 = "0.4.5"
91+
# bity-ic-canister-client = "0.2.4"
92+
# bity-ic-canister-logger = "0.2.0"
93+
# bity-ic-canister-state-macros = "0.1.0"
94+
# bity-ic-canister-tracing-macros = "0.1.0"
95+
# bity-ic-canister-time = "0.2.1"
96+
# bity-ic-serializer = "0.1.0"
97+
# bity-ic-stable-memory = "0.2.0"
98+
# bity-ic-types = "0.1.1"
99+
# bity-ic-utils = "0.2.0"
100+
# bity-ic-subcanister-manager = "0.3.0"
101+
# bity-ic-icrc3-archive-api = "0.3.0"
102+
# bity-ic-icrc3-archive-c2c-client = "0.3.2"
103+
# bity-ic-icrc3 = "0.5.0"
104+
105+
bity-ic-canister-client = { path = "src/canister_client" }
106+
bity-ic-canister-logger = { path = "src/canister_logger" }
107+
bity-ic-canister-state-macros = { path = "src/canister_state_macros" }
108+
bity-ic-canister-tracing-macros = { path = "src/canister_tracing_macros" }
109+
bity-ic-canister-time = { path = "src/canister_time" }
110+
bity-ic-serializer = { path = "src/serializer" }
111+
bity-ic-stable-memory = { path = "src/stable_memory" }
112+
bity-ic-types = { path = "src/types" }
113+
bity-ic-utils = { path = "src/utils" }
114+
bity-ic-subcanister-manager = { path = "src/subcanister_manager" }
115+
bity-ic-icrc3-archive-api = { path = "src/icrc3_archive_api" }
116+
bity-ic-icrc3-archive-c2c-client = { path = "src/icrc3_archive_c2c_client" }
117+
bity-ic-icrc3 = { path = "src/icrc3" }

src/canister_state_macros/src/lib.rs

Lines changed: 7 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
macro_rules! canister_state {
6161
($type:ty) => {
6262
thread_local! {
63-
static __STATE: std::cell::RefCell<Option<std::rc::Rc<$type>>> = std::cell::RefCell::default();
63+
static __STATE: std::cell::RefCell<Option<$type>> = std::cell::RefCell::default();
6464
}
6565

6666
const __STATE_ALREADY_INITIALIZED: &str = "State has already been initialized";
@@ -74,12 +74,11 @@ macro_rules! canister_state {
7474
/// # Panics
7575
/// Panics if the state has already been initialized
7676
pub fn init_state(state: $type) {
77-
__STATE.with(|s| {
78-
let mut lock = s.write().unwrap();
79-
if lock.is_some() {
77+
__STATE.with_borrow_mut(|s| {
78+
if s.is_some() {
8079
panic!("{}", __STATE_ALREADY_INITIALIZED);
8180
} else {
82-
*s = Some(std::rc::Rc::new(state));
81+
*s = Some(state);
8382
}
8483
});
8584
}
@@ -95,7 +94,7 @@ macro_rules! canister_state {
9594
/// # Panics
9695
/// Panics if the state has not been initialized
9796
pub fn replace_state(state: $type) -> $type {
98-
__STATE.replace(Some(std::rc::Rc::new(state))).expect(__STATE_NOT_INITIALIZED).as_ref().clone()
97+
__STATE.replace(Some(state)).expect(__STATE_NOT_INITIALIZED)
9998
}
10099

101100
/// Takes ownership of the current state.
@@ -106,7 +105,7 @@ macro_rules! canister_state {
106105
/// # Panics
107106
/// Panics if the state has not been initialized
108107
pub fn take_state() -> $type {
109-
__STATE.take().expect(__STATE_NOT_INITIALIZED).as_ref().clone()
108+
__STATE.take().expect(__STATE_NOT_INITIALIZED)
110109
}
111110

112111
/// Reads the state using a closure.
@@ -123,7 +122,7 @@ macro_rules! canister_state {
123122
where
124123
F: FnOnce(&$type) -> R,
125124
{
126-
__STATE.with_borrow(|s| f(s.as_ref().expect(__STATE_NOT_INITIALIZED).as_ref()))
125+
__STATE.with_borrow(|s| f(s.as_ref().expect(__STATE_NOT_INITIALIZED)))
127126
}
128127

129128
/// Mutates the state using a closure.
@@ -139,104 +138,6 @@ macro_rules! canister_state {
139138
pub fn mutate_state<F, R>(f: F) -> R
140139
where
141140
F: FnOnce(&mut $type) -> R,
142-
{
143-
__STATE.with_borrow_mut(|s| {
144-
let state = std::rc::Rc::make_mut(s.as_mut().expect(__STATE_NOT_INITIALIZED));
145-
f(state)
146-
})
147-
}
148-
149-
/// Trait for async functions that can be used with state operations
150-
/// This is temporary trait to be replaced once rust release official AsyncFn trait definition.
151-
/// see https://github.com/rust-lang/rust/pull/132706
152-
pub trait AsyncFn<Args>: FnOnce(Args) {
153-
type Future: std::future::Future<Output = Self::Output> + Send + 'static;
154-
type Output;
155-
}
156-
157-
impl<F, Args, Fut, Out> AsyncFn<Args> for F
158-
where
159-
F: FnOnce(Args, Output = Fut),
160-
Fut: std::future::Future<Output = Out> + Send + 'static,
161-
{
162-
type Future = Fut;
163-
type Output = Out;
164-
}
165-
166-
/// Reads the state using an async closure.
167-
///
168-
/// # Arguments
169-
/// * `f` - An async closure that takes a reference to the state and returns a value
170-
///
171-
/// # Returns
172-
/// A Future that will resolve to the result of the closure
173-
///
174-
/// # Panics
175-
/// Panics if the state has not been initialized
176-
pub fn read_state_async<F>(f: F) -> F::Future
177-
where
178-
F: AsyncFn<(&$type,)>,
179-
F::Future: Send + 'static,
180-
{
181-
__STATE.with_borrow(|s| {
182-
let state = s.as_ref().expect(__STATE_NOT_INITIALIZED).as_ref();
183-
f(state)
184-
})
185-
}
186-
187-
/// Mutates the state using an async closure.
188-
///
189-
/// # Arguments
190-
/// * `f` - An async closure that takes a mutable reference to the state and returns a value
191-
///
192-
/// # Returns
193-
/// A Future that will resolve to the result of the closure
194-
///
195-
/// # Panics
196-
/// Panics if the state has not been initialized
197-
pub fn mutate_state_async<F>(f: F) -> F::Future
198-
where
199-
F: AsyncFn<(&mut $type,)>,
200-
F::Future: Send + 'static,
201-
{
202-
__STATE.with_borrow_mut(|s| {
203-
let state = std::rc::Rc::make_mut(s.as_mut().expect(__STATE_NOT_INITIALIZED));
204-
f(state)
205-
})
206-
}
207-
208-
/// Reads the state using an async closure.
209-
///
210-
/// # Arguments
211-
/// * `f` - An async closure that takes a reference to the state and returns a future
212-
///
213-
/// # Returns
214-
/// A Future that will resolve to the result of the closure
215-
///
216-
/// # Panics
217-
/// Panics if the state has not been initialized
218-
pub fn read_state_async<F, Fut, R>(f: F) -> impl std::future::Future<Output = R>
219-
where
220-
F: for<'a> FnOnce(&'a $type) -> Fut,
221-
Fut: std::future::Future<Output = R>,
222-
{
223-
__STATE.with_borrow_mut(|s| f(s.as_mut().expect(__STATE_NOT_INITIALIZED)))
224-
}
225-
226-
/// Mutates the state using an async closure.
227-
///
228-
/// # Arguments
229-
/// * `f` - An async closure that takes a mutable reference to the state and returns a future
230-
///
231-
/// # Returns
232-
/// A Future that will resolve to the result of the closure
233-
///
234-
/// # Panics
235-
/// Panics if the state has not been initialized
236-
pub fn mutate_state_async<F, Fut, R>(f: F) -> impl std::future::Future<Output = R>
237-
where
238-
F: for<'a> FnOnce(&'a mut $type) -> Fut,
239-
Fut: std::future::Future<Output = R>,
240141
{
241142
__STATE.with_borrow_mut(|s| f(s.as_mut().expect(__STATE_NOT_INITIALIZED)))
242143
}

src/icrc3/Cargo.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ hex = { workspace = true }
3333
sha2 = { workspace = true }
3434
anyhow = { workspace = true }
3535

36-
bity-ic-canister-time = "0.2.0"
37-
bity-ic-types = "0.1.1"
38-
bity-ic-utils = "0.2.0"
39-
bity-ic-subcanister-manager = "0.3.1"
40-
bity-ic-icrc3-archive-api = "0.3.1"
41-
bity-ic-icrc3-archive-c2c-client = "0.3.1"
36+
# bity-ic-canister-time = "0.2.0"
37+
# bity-ic-types = "0.1.1"
38+
# bity-ic-utils = "0.2.0"
39+
# bity-ic-subcanister-manager = "0.3.1"
40+
# bity-ic-icrc3-archive-api = { path = "../icrc3_archive_api" }
41+
# bity-ic-icrc3-archive-c2c-client = "0.3.1"
42+
43+
bity-ic-canister-time = { path = "../canister_time" }
44+
bity-ic-types = { path = "../types" }
45+
bity-ic-utils = { path = "../utils" }
46+
bity-ic-subcanister-manager = { path = "../subcanister_manager" }
47+
bity-ic-icrc3-archive-api = { path = "../icrc3_archive_api" }
48+
bity-ic-icrc3-archive-c2c-client = { path = "../icrc3_archive_c2c_client" }

src/icrc3/src/blockchain/archive_canister.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl ArchiveCanister {
5353
bity_ic_icrc3_archive_api::insert_blocks::Response::Success => {
5454
// Update the archive info: increment the `end` by the number of blocks inserted
5555
let block_count = blocks.len() as u64;
56-
self.archive_info.end += block_count;
56+
self.archive_info.end += block_count - 1;
5757

5858
// Log the updated archive info for debugging
5959
ic_cdk::println!(

0 commit comments

Comments
 (0)