Skip to content

Commit b900c51

Browse files
committed
apply suggestins, fix formatting
1 parent 8006769 commit b900c51

File tree

2 files changed

+56
-61
lines changed

2 files changed

+56
-61
lines changed

identity_iota_core/src/document/iota_document.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,11 @@ pub mod client_document {
427427
None,
428428
))
429429
})?;
430-
let (_, multi_controller, created, updated) = match unpacked {
431-
Some(data) => data,
432-
None => {
433-
return Err(Error::InvalidDoc(identity_document::Error::InvalidDocument(
434-
"given IotaObjectData did not contain a document",
435-
None,
436-
)));
437-
}
430+
let Some((_, multi_controller, created, updated)) = unpacked else {
431+
return Err(Error::InvalidDoc(identity_document::Error::InvalidDocument(
432+
"given IotaObjectData did not contain a document",
433+
None,
434+
)));
438435
};
439436
let did_doc =
440437
Self::from_iota_document_data(multi_controller.controlled_value(), allow_empty, &did, created, updated)?;

identity_iota_core/src/rebased/migration/identity.rs

+51-53
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ pub async fn get_identity(
342342
// call was successful but not data for alias id
343343
return Ok(None);
344344
};
345-
345+
346346
let did = IotaDID::from_alias_id(&object_id.to_string(), client.network());
347-
let (id, multi_controller, created, updated) = match unpack_identity_data(&did, &data)? {
348-
Some(data) => data,
349-
None => { return Ok(None); },
347+
let Some((id, multi_controller, created, updated)) = unpack_identity_data(&did, &data)? else {
348+
return Ok(None);
350349
};
351350

352-
let did_doc = IotaDocument::from_iota_document_data(multi_controller.controlled_value(), true, &did, created, updated)
353-
.map_err(|e| Error::DidDocParsingFailed(e.to_string()))?;
351+
let did_doc =
352+
IotaDocument::from_iota_document_data(multi_controller.controlled_value(), true, &did, created, updated)
353+
.map_err(|e| Error::DidDocParsingFailed(e.to_string()))?;
354354

355355
Ok(Some(OnChainIdentity {
356356
id,
@@ -365,60 +365,58 @@ fn is_identity(value: &IotaParsedMoveObject) -> bool {
365365
value.type_.module.as_ident_str().as_str() == MODULE && value.type_.name.as_ident_str().as_str() == NAME
366366
}
367367

368-
369368
/// Unpack identity data from given `IotaObjectData`
370-
///
369+
///
371370
/// # Errors:
372371
/// * in case given data for DID is not an object
373372
/// * parsing identity data from object fails
374-
pub(crate) fn unpack_identity_data(did: &IotaDID, data: &IotaObjectData) -> Result<Option::<(UID, Multicontroller<Vec<u8>>, Timestamp, Timestamp)>, Error> {
375-
let content = data
376-
.clone()
377-
.content
378-
.ok_or_else(|| Error::ObjectLookup(format!("no content in retrieved object in object id {did}")))?;
379-
let IotaParsedData::MoveObject(value) = content else {
380-
return Err(Error::ObjectLookup(format!(
381-
"given data for DID {did} is not an object"
382-
)));
383-
};
384-
if !is_identity(&value) {
385-
return Ok(None);
386-
}
387-
388-
#[derive(Deserialize)]
389-
struct TempOnChainIdentity {
390-
id: UID,
391-
did_doc: Multicontroller<Vec<u8>>,
392-
created: Number<u64>,
393-
updated: Number<u64>,
394-
}
395-
396-
let TempOnChainIdentity {
397-
id,
398-
did_doc: multi_controller,
399-
created,
400-
updated,
401-
} = serde_json::from_value::<TempOnChainIdentity>(value.fields.to_json_value()).map_err(|err| {
402-
Error::ObjectLookup(format!(
403-
"could not parse identity document with DID {did}; {err}"
404-
))
405-
})?;
406-
407-
// Parse DID document timestamps
408-
let created = {
409-
let timestamp_ms: u64 = created.try_into().expect("Move string-encoded u64 are valid u64");
410-
// `Timestamp` requires a timestamp expressed in seconds.
411-
Timestamp::from_unix(timestamp_ms as i64 / 1000).expect("On-chain clock produces valid timestamps")
412-
};
413-
let updated = {
414-
let timestamp_ms: u64 = updated.try_into().expect("Move string-encoded u64 are valid u64");
415-
// `Timestamp` requires a timestamp expressed in seconds.
416-
Timestamp::from_unix(timestamp_ms as i64 / 1000).expect("On-chain clock produces valid timestamps")
417-
};
373+
pub(crate) fn unpack_identity_data(
374+
did: &IotaDID,
375+
data: &IotaObjectData,
376+
) -> Result<Option<(UID, Multicontroller<Vec<u8>>, Timestamp, Timestamp)>, Error> {
377+
let content = data
378+
.clone()
379+
.content
380+
.ok_or_else(|| Error::ObjectLookup(format!("no content in retrieved object in object id {did}")))?;
381+
let IotaParsedData::MoveObject(value) = content else {
382+
return Err(Error::ObjectLookup(format!(
383+
"given data for DID {did} is not an object"
384+
)));
385+
};
386+
if !is_identity(&value) {
387+
return Ok(None);
388+
}
418389

419-
Ok(Some((id, multi_controller, created, updated)))
390+
#[derive(Deserialize)]
391+
struct TempOnChainIdentity {
392+
id: UID,
393+
did_doc: Multicontroller<Vec<u8>>,
394+
created: Number<u64>,
395+
updated: Number<u64>,
420396
}
421397

398+
let TempOnChainIdentity {
399+
id,
400+
did_doc: multi_controller,
401+
created,
402+
updated,
403+
} = serde_json::from_value::<TempOnChainIdentity>(value.fields.to_json_value())
404+
.map_err(|err| Error::ObjectLookup(format!("could not parse identity document with DID {did}; {err}")))?;
405+
406+
// Parse DID document timestamps
407+
let created = {
408+
let timestamp_ms: u64 = created.try_into().expect("Move string-encoded u64 are valid u64");
409+
// `Timestamp` requires a timestamp expressed in seconds.
410+
Timestamp::from_unix(timestamp_ms as i64 / 1000).expect("On-chain clock produces valid timestamps")
411+
};
412+
let updated = {
413+
let timestamp_ms: u64 = updated.try_into().expect("Move string-encoded u64 are valid u64");
414+
// `Timestamp` requires a timestamp expressed in seconds.
415+
Timestamp::from_unix(timestamp_ms as i64 / 1000).expect("On-chain clock produces valid timestamps")
416+
};
417+
418+
Ok(Some((id, multi_controller, created, updated)))
419+
}
422420

423421
/// Builder-style struct to create a new [`OnChainIdentity`].
424422
#[derive(Debug)]

0 commit comments

Comments
 (0)