-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from ourzora/erik/back-2440-mark-mints-as-seen-…
…prune [back-2440] Move to alloy, implement watching chain
- Loading branch information
Showing
14 changed files
with
1,450 additions
and
98 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,69 @@ | ||
use crate::controller::ControllerCommands; | ||
use crate::types::Premint; | ||
use alloy::network::Ethereum; | ||
use alloy::pubsub::PubSubFrontend; | ||
use alloy_provider::{Provider, RootProvider}; | ||
use alloy_rpc_client::{RpcClient, WsConnect}; | ||
use futures_util::StreamExt; | ||
use tokio::sync::mpsc::Sender; | ||
|
||
/// Checks for new premints being brought onchain then sends to controller to handle | ||
struct MintChecker { | ||
chain_id: u64, | ||
rpc_url: String, | ||
channel: Sender<ControllerCommands>, | ||
} | ||
|
||
impl MintChecker { | ||
pub async fn poll_for_new_mints<T: Premint>(&self) -> eyre::Result<()> { | ||
let mut highest_block: Option<u64> = None; | ||
|
||
let rpc = self.make_provider().await?; | ||
let mut filter = if let Some(filter) = T::check_filter(self.chain_id) { | ||
filter | ||
} else { | ||
let err = eyre::eyre!("No filter for chain / premint type, skipping spawning checker"); | ||
tracing::warn!(error = err.to_string(), "checking failed"); | ||
return Err(err); | ||
}; | ||
|
||
loop { | ||
// set start block incase of WS disconnect | ||
if let Some(highest_block) = highest_block { | ||
filter = filter.from_block(highest_block); | ||
} | ||
let mut stream = rpc.subscribe_logs(&filter).await?.into_stream(); | ||
|
||
while let Some(log) = stream.next().await { | ||
match T::map_claim(self.chain_id, log.clone()) { | ||
Ok(claim) => { | ||
if let Err(err) = self | ||
.channel | ||
.send(ControllerCommands::ResolveOnchainMint(claim)) | ||
.await | ||
{ | ||
tracing::error!("Error sending claim to controller: {}", err); | ||
} | ||
} | ||
Err(e) => { | ||
tracing::error!("Error processing log while checking premint: {}", e); | ||
} | ||
} | ||
if let Some(block_number) = log.block_number { | ||
highest_block = Some(block_number.to()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
async fn make_provider(&self) -> eyre::Result<RootProvider<Ethereum, PubSubFrontend>> { | ||
let ws_transport = WsConnect::new(self.rpc_url.clone()); | ||
|
||
// Connect to the WS client. | ||
let rpc_client = RpcClient::connect_pubsub(ws_transport).await?; | ||
|
||
// Create the provider. | ||
let provider = RootProvider::<Ethereum, _>::new(rpc_client); | ||
Ok(provider) | ||
} | ||
} |
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
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
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 @@ | ||
pub mod zora_v2; |
Oops, something went wrong.