Просмотр исходного кода

event_graph: add Event::with_timestamp() method to create an event with the timestamp explicitly provided.

darkfi 1 год назад
Родитель
Сommit
f65a643bd0
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      src/event_graph/event.rs

+ 11 - 0
src/event_graph/event.rs

@@ -57,6 +57,17 @@ impl Event {
         }
         }
     }
     }
 
 
+    /// Same as `Event::new()` but allows specifying the timestamp explicitly.
+    pub async fn with_timestamp(timestamp: u64, data: Vec<u8>, event_graph: &EventGraph) -> Self {
+        let (layer, parents) = event_graph.get_next_layer_with_parents().await;
+        Self {
+            timestamp,
+            content: data,
+            parents,
+            layer,
+        }
+    }
+
     /// Hash the [`Event`] to retrieve its ID
     /// Hash the [`Event`] to retrieve its ID
     pub fn id(&self) -> blake3::Hash {
     pub fn id(&self) -> blake3::Hash {
         let mut hasher = blake3::Hasher::new();
         let mut hasher = blake3::Hasher::new();