Skip to content

Commit

Permalink
get_latest_record()
Browse files Browse the repository at this point in the history
  • Loading branch information
ddd-mtl committed Jul 1, 2024
1 parent 5d9489a commit badb7d7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,21 @@ pub fn get_latest_entry(target: EntryHash, option: GetOptions) -> ExternResult<O
};
let record = get(eh.clone(), GetOptions::network())?.unwrap();
Ok(record.entry.into_option())
}
}


/// Recursively call get_details() until no updates are found
/// 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")};
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()),
None => Ok(element_details.record),
}
},
}
}

0 comments on commit badb7d7

Please sign in to comment.