|
|
@@ -1,13 +1,35 @@
|
|
|
+use async_std::sync::Arc;
|
|
|
use std::{fmt, io};
|
|
|
|
|
|
use fxhash::FxHashMap;
|
|
|
use ripemd::{Digest, Ripemd256};
|
|
|
|
|
|
-use darkfi::serial::{Decodable, Encodable, ReadExt, SerialDecodable, SerialEncodable};
|
|
|
+use darkfi::{
|
|
|
+ serial::{Decodable, Encodable, ReadExt, SerialDecodable, SerialEncodable},
|
|
|
+ Error, Result,
|
|
|
+};
|
|
|
|
|
|
use crate::settings::get_current_time;
|
|
|
|
|
|
pub type EventId = [u8; 32];
|
|
|
+pub type EventQueueArc = Arc<EventQueue>;
|
|
|
+
|
|
|
+pub struct EventQueue(async_channel::Sender<Event>, async_channel::Receiver<Event>);
|
|
|
+
|
|
|
+impl EventQueue {
|
|
|
+ pub fn new() -> EventQueueArc {
|
|
|
+ let (sn, rv) = async_channel::unbounded();
|
|
|
+ Arc::new(Self(sn, rv))
|
|
|
+ }
|
|
|
+
|
|
|
+ pub async fn fetch(&self) -> Result<Event> {
|
|
|
+ self.1.recv().await.map_err(Error::from)
|
|
|
+ }
|
|
|
+
|
|
|
+ pub async fn dispatch(&self, event: &Event) -> Result<()> {
|
|
|
+ self.0.send(event.clone()).await.map_err(Error::from)
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
const MAX_DEPTH: u32 = 300;
|
|
|
const MAX_HEIGHT: u32 = 300;
|