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)
| 685 | /// |
| 686 | /// The hash of the last change, or None if view is empty. |
| 687 | pub 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 |
no test coverage detected