Read NetworkId from ScannerFeed trait, not env

This commit is contained in:
Luke Parker 2024-09-19 02:58:02 -04:00
parent 1a08d50e16
commit 53567e91c8
2 changed files with 7 additions and 12 deletions

View file

@ -5,13 +5,15 @@ use tokio::sync::mpsc;
use scale::Encode; use scale::Encode;
use serai_client::{ use serai_client::{
primitives::{NetworkId, Signature}, primitives::Signature,
validator_sets::primitives::Session, validator_sets::primitives::Session,
in_instructions::primitives::{Batch, SignedBatch}, in_instructions::primitives::{Batch, SignedBatch},
}; };
use serai_db::{Get, DbTxn, Db, create_db, db_channel}; use serai_db::{Get, DbTxn, Db, create_db, db_channel};
use serai_env as env;
use scanner::ScannerFeed;
use message_queue::{Service, Metadata, client::MessageQueue}; use message_queue::{Service, Metadata, client::MessageQueue};
create_db! { create_db! {
@ -60,18 +62,11 @@ pub(crate) struct Coordinator {
} }
impl Coordinator { impl Coordinator {
pub(crate) fn new(db: crate::Db) -> Self { pub(crate) fn new<S: ScannerFeed>(db: crate::Db) -> Self {
let (received_message_send, received_message_recv) = mpsc::unbounded_channel(); let (received_message_send, received_message_recv) = mpsc::unbounded_channel();
let (sent_message_send, mut sent_message_recv) = mpsc::unbounded_channel(); let (sent_message_send, mut sent_message_recv) = mpsc::unbounded_channel();
let network_id = match env::var("NETWORK").expect("network wasn't specified").as_str() { let service = Service::Processor(S::NETWORK);
"bitcoin" => NetworkId::Bitcoin,
"ethereum" => NetworkId::Ethereum,
"monero" => NetworkId::Monero,
_ => panic!("unrecognized network"),
};
// TODO: Read this from ScannerFeed
let service = Service::Processor(network_id);
let message_queue = Arc::new(MessageQueue::from_env(service)); let message_queue = Arc::new(MessageQueue::from_env(service));
// Spawn a task to move messages from the message-queue to our database so we can achieve // Spawn a task to move messages from the message-queue to our database so we can achieve

View file

@ -182,7 +182,7 @@ pub async fn main_loop<
scheduler: Sch, scheduler: Sch,
publisher: impl TransactionPublisher<TransactionFor<Sch::SignableTransaction>>, publisher: impl TransactionPublisher<TransactionFor<Sch::SignableTransaction>>,
) { ) {
let mut coordinator = Coordinator::new(db.clone()); let mut coordinator = Coordinator::new::<S>(db.clone());
let mut key_gen = key_gen::<K>(); let mut key_gen = key_gen::<K>();
let mut scanner = Scanner::new(db.clone(), feed.clone(), scheduler.clone()).await; let mut scanner = Scanner::new(db.clone(), feed.clone(), scheduler.clone()).await;