Skip to content

Commit a0f3efc

Browse files
committed
service_id in query_image_filters
1 parent 937d4b9 commit a0f3efc

File tree

2 files changed

+74
-73
lines changed

2 files changed

+74
-73
lines changed

src/contract.rs

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -138,80 +138,80 @@ fn parse_tdx_attestation(quote: &[u8], collateral: &[u8]) -> Option<tdx_quote_t>
138138
#[entry_point]
139139
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> StdResult<Response> {
140140
match msg {
141-
MigrateMsg::Migrate {} => {
142-
// Phase 1: load all old entries into memory to avoid borrow conflicts
143-
let mut old_buf: Vec<(String, OldService)> = Vec::new();
144-
for it in OLD_SERVICES_MAP.iter(deps.storage)? {
145-
let (k, v) = it?;
146-
old_buf.push((k, v));
147-
}
148-
149-
let mut moved: u64 = 0;
150-
let mut merged: u64 = 0;
151-
let mut skipped: u64 = 0;
152-
153-
// Phase 2: move/merge into new map and remove from old map
154-
for (key, old) in old_buf.into_iter() {
155-
// Convert Vec<OldFilterEntry> -> Vec<FilterEntry> (timestamp = None)
156-
let old_to_new_filters = |ofs: &Vec<OldFilterEntry>| -> Vec<FilterEntry> {
157-
ofs.iter().map(|e| FilterEntry {
158-
filter: e.filter.clone(),
159-
description: e.description.clone(),
160-
timestamp: None, // legacy entries have no timestamp
161-
}).collect()
162-
};
163-
164-
let converted_filters = old_to_new_filters(&old.filters);
165-
166-
// If there is already a new-format Service with the same key, merge filters.
167-
if let Some(mut existing) = SERVICES_MAP.get(deps.storage, &key) {
168-
// Merge strategy:
169-
// - Keep existing fields from `existing`
170-
// - Prefer existing.secrets_plaintext if present; otherwise take old.secrets_plaintext
171-
// - Append converted filters that are not already present (match by {filter, description}, ignore timestamp)
172-
let mut appended = 0usize;
173-
174-
for nf in converted_filters.into_iter() {
175-
let dup = existing.filters.iter().any(|ef| {
176-
ef.description == nf.description && ef.filter == nf.filter
177-
});
178-
if !dup {
179-
existing.filters.push(nf);
180-
appended += 1;
181-
}
182-
}
183-
184-
if existing.secrets_plaintext.is_none() && old.secrets_plaintext.is_some() {
185-
existing.secrets_plaintext = old.secrets_plaintext.clone();
186-
}
187-
188-
SERVICES_MAP.insert(deps.storage, &key, &existing)?;
189-
OLD_SERVICES_MAP.remove(deps.storage, &key)?;
190-
merged += 1;
191-
if appended == 0 { skipped += 1; }
192-
continue;
193-
}
194-
195-
// No existing new-format entry → create a new one directly
196-
let new_svc = Service {
197-
id: old.id.clone(),
198-
name: old.name.clone(),
199-
admin: old.admin.clone(),
200-
filters: converted_filters,
201-
secret_key: old.secret_key.clone(),
202-
secrets_plaintext: old.secrets_plaintext.clone(),
203-
};
204-
205-
SERVICES_MAP.insert(deps.storage, &key, &new_svc)?;
206-
OLD_SERVICES_MAP.remove(deps.storage, &key)?;
207-
moved += 1;
208-
}
141+
MigrateMsg::Migrate {} => {
142+
// // Phase 1: load all old entries into memory to avoid borrow conflicts
143+
// let mut old_buf: Vec<(String, OldService)> = Vec::new();
144+
// for it in OLD_SERVICES_MAP.iter(deps.storage)? {
145+
// let (k, v) = it?;
146+
// old_buf.push((k, v));
147+
// }
148+
//
149+
// let mut moved: u64 = 0;
150+
// let mut merged: u64 = 0;
151+
// let mut skipped: u64 = 0;
152+
//
153+
// // Phase 2: move/merge into new map and remove from old map
154+
// for (key, old) in old_buf.into_iter() {
155+
// // Convert Vec<OldFilterEntry> -> Vec<FilterEntry> (timestamp = None)
156+
// let old_to_new_filters = |ofs: &Vec<OldFilterEntry>| -> Vec<FilterEntry> {
157+
// ofs.iter().map(|e| FilterEntry {
158+
// filter: e.filter.clone(),
159+
// description: e.description.clone(),
160+
// timestamp: None, // legacy entries have no timestamp
161+
// }).collect()
162+
// };
163+
//
164+
// let converted_filters = old_to_new_filters(&old.filters);
165+
//
166+
// // If there is already a new-format Service with the same key, merge filters.
167+
// if let Some(mut existing) = SERVICES_MAP.get(deps.storage, &key) {
168+
// // Merge strategy:
169+
// // - Keep existing fields from `existing`
170+
// // - Prefer existing.secrets_plaintext if present; otherwise take old.secrets_plaintext
171+
// // - Append converted filters that are not already present (match by {filter, description}, ignore timestamp)
172+
// let mut appended = 0usize;
173+
//
174+
// for nf in converted_filters.into_iter() {
175+
// let dup = existing.filters.iter().any(|ef| {
176+
// ef.description == nf.description && ef.filter == nf.filter
177+
// });
178+
// if !dup {
179+
// existing.filters.push(nf);
180+
// appended += 1;
181+
// }
182+
// }
183+
//
184+
// if existing.secrets_plaintext.is_none() && old.secrets_plaintext.is_some() {
185+
// existing.secrets_plaintext = old.secrets_plaintext.clone();
186+
// }
187+
//
188+
// SERVICES_MAP.insert(deps.storage, &key, &existing)?;
189+
// OLD_SERVICES_MAP.remove(deps.storage, &key)?;
190+
// merged += 1;
191+
// if appended == 0 { skipped += 1; }
192+
// continue;
193+
// }
194+
//
195+
// // No existing new-format entry → create a new one directly
196+
// let new_svc = Service {
197+
// id: old.id.clone(),
198+
// name: old.name.clone(),
199+
// admin: old.admin.clone(),
200+
// filters: converted_filters,
201+
// secret_key: old.secret_key.clone(),
202+
// secrets_plaintext: old.secrets_plaintext.clone(),
203+
// };
204+
//
205+
// SERVICES_MAP.insert(deps.storage, &key, &new_svc)?;
206+
// OLD_SERVICES_MAP.remove(deps.storage, &key)?;
207+
// moved += 1;
208+
// }
209209

210210
Ok(Response::new()
211-
.add_attribute("action", "migrate_services_map_new_to_new_timestamp")
212-
.add_attribute("moved", moved.to_string())
213-
.add_attribute("merged", merged.to_string())
214-
.add_attribute("skipped", skipped.to_string()))
211+
.add_attribute("action", "migrate"))
212+
// .add_attribute("moved", moved.to_string())
213+
// .add_attribute("merged", merged.to_string())
214+
// .add_attribute("skipped", skipped.to_string()))
215215
}
216216
MigrateMsg::StdError {} => Err(StdError::generic_err("this is an std error")),
217217
}
@@ -978,7 +978,7 @@ fn query_image_filters(deps: Deps, service_id: String) -> StdResult<ListImageRes
978978
}
979979
}).collect();
980980

981-
Ok(ListImageResponse { filters: list })
981+
Ok(ListImageResponse {service_id, filters: list })
982982
}
983983

984984
/// NEW: Retrieve the environment secret using an attestation.

src/msg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub struct ImageFilterHex {
111111
/// Response wrapper for listing filters
112112
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
113113
pub struct ListImageResponse {
114+
pub service_id: String,
114115
pub filters: Vec<ImageFilterHexEntry>,
115116
}
116117

0 commit comments

Comments
 (0)