MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / get_last_change

Function get_last_change

atomic-repository/src/unrecord.rs:687–708  ·  view source on GitHub ↗

Get the hash of the last change in a view. # Arguments `txn` - Read transaction `view` - View to query # Returns The hash of the last change, or None if view is empty.

(_txn: &T, view: &ViewState)

Source from the content-addressed store, hash-verified

685///
686/// The hash of the last change, or None if view is empty.
687pub fn get_last_change<T: ViewTxnT>(_txn: &T, view: &ViewState) -> UnrecordResult<Option<Hash>> {
688 if view.change_count == 0 {
689 return Ok(None);
690 }
691
692 let last_seq = view.change_count - 1;
693 let node_id = _txn
694 .get_change_at_seq(view, last_seq)
695 .map_err(|e| UnrecordError::Database(e.to_string()))?
696 .ok_or_else(|| UnrecordError::Inconsistent {
697 reason: format!("No change at sequence {}", last_seq),
698 })?;
699
700 let hash = _txn
701 .get_external(node_id)
702 .map_err(|e| UnrecordError::Database(e.to_string()))?
703 .ok_or_else(|| UnrecordError::ChangeNotFound {
704 hash: format!("{:?}", node_id),
705 })?;
706
707 Ok(Some(hash))
708}
709
710// Tests
711

Callers 1

unrecord_lastMethod · 0.85

Calls 2

get_change_at_seqMethod · 0.45
get_externalMethod · 0.45

Tested by

no test coverage detected