Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use serde(skip) rather than implementing Serialize #48

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions rs/canister/impl/src/model/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use ic_stable_structures::{StableLog, Storable};
use serde::Serialize;
use std::borrow::Cow;

#[derive(Serialize, Deserialize)]
pub struct Events {
#[serde(skip, default = "init_events")]
events: StableLog<StorableEvent, Memory, Memory>,
string_to_num_map: StringToNumMap,
}
Expand Down
4 changes: 0 additions & 4 deletions rs/canister/impl/src/model/string_to_num_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ use crate::memory::{
Memory,
};
use ic_stable_structures::{StableBTreeMap, StableLog};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct StringToNumMap {
#[serde(skip, default = "init_string_to_num")]
string_to_num: StableBTreeMap<String, u32, Memory>,
#[serde(skip, default = "init_num_to_string")]
num_to_string: StableLog<String, Memory, Memory>,
}

Expand Down
13 changes: 7 additions & 6 deletions rs/canister/impl/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ thread_local! {
pub struct State {
push_events_whitelist: HashSet<Principal>,
read_events_whitelist: HashSet<Principal>,
events_v2: Events,
#[serde(skip)]
events: Events,
event_deduper: EventDeduper,
salt: Salt,
anonymization_config: AnonymizationConfig,
Expand Down Expand Up @@ -60,7 +61,7 @@ impl State {
State {
push_events_whitelist,
read_events_whitelist,
events_v2: Events::default(),
events: Events::default(),
event_deduper: EventDeduper::default(),
anonymization_config: anonymization_config.into(),
salt: Salt::default(),
Expand All @@ -85,7 +86,7 @@ impl State {
}

pub fn events(&self) -> &Events {
&self.events_v2
&self.events
}

pub fn set_salt(&mut self, salt: [u8; 32]) {
Expand Down Expand Up @@ -117,12 +118,12 @@ impl State {
}
}

self.events_v2.push(event);
self.events.push(event);
}

pub fn migrate_events(&mut self, count: u32) {
for event in self.events_v2.get(self.events_v2.len(), count as u64) {
self.events_v2.push(IdempotentEvent {
for event in self.events.get(self.events.len(), count as u64) {
self.events.push(IdempotentEvent {
idempotency_key: 0,
name: event.name,
timestamp: event.timestamp,
Expand Down
Loading