-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Minimal Implementation of MEV-Share SSE Collector (#8)
* Minimal implementation of MEV-Share collector event source via SSE * Comments * Better error handling * Change SSE lib to mev-share-rs
- Loading branch information
1 parent
f1b7bab
commit 41fecab
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use async_trait::async_trait; | ||
use tokio_stream::{StreamExt}; | ||
use mev_share_rs::{EventClient, sse::{Event}}; | ||
use crate::types::{Collector, CollectorStream}; | ||
use anyhow::Result; | ||
|
||
/// A collector that streams from MEV-Share SSE endpoint | ||
/// and generates [events](Event), which return tx hash, logs, and bundled txs. | ||
pub struct MevShareCollector { | ||
mevshare_sse_url: String, | ||
} | ||
|
||
impl MevShareCollector { | ||
pub fn new(mevshare_sse_url: String) -> Self { | ||
Self { mevshare_sse_url } | ||
} | ||
} | ||
|
||
/// Implementation of the [Collector](Collector) trait for the | ||
/// [MevShareCollector](MevShareCollector). | ||
#[async_trait] | ||
impl Collector<Event> for MevShareCollector | ||
{ | ||
async fn get_event_stream(&self) -> Result<CollectorStream<Event>> { | ||
let client = EventClient::default(); | ||
let stream = client.subscribe(&self.mevshare_sse_url).await.unwrap(); | ||
let stream = stream.filter_map(|event| match event { | ||
Ok(evt) => Some(evt), | ||
Err(_) => None | ||
}); | ||
Ok(Box::pin(stream)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters