Skip to content

Commit

Permalink
fix get_latest_record()
Browse files Browse the repository at this point in the history
  • Loading branch information
ddd-mtl committed Nov 12, 2024
1 parent 8be7b6a commit dc0b199
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,18 @@ pub fn get_latest_entry(target: EntryHash, option: GetOptions) -> ExternResult<O
/// If multiple updates are found. It will take the last one in the list.
pub fn get_latest_record(action_hash: ActionHash) -> ExternResult<Record> {
let Some(details) = get_details(action_hash, GetOptions::default())?
else { return zome_error!("Record not found")};
else { return zome_error!("Record not found")};
match details {
Details::Entry(_) => zome_error!("Malformed details"),
Details::Record(element_details) => {
match element_details.updates.last() {
Some(update) => get_latest_record(update.action_address().clone()),
Some(update) => match get_latest_record(update.action_address().clone()) {
Ok(record) => Ok(record),
Err(_) => {
//println!("Failed to find latest record. Returning previous one.");
Ok(element_details.record)
},
}
None => Ok(element_details.record),
}
},
Expand Down

0 comments on commit dc0b199

Please sign in to comment.