diff --git a/payments/src/lib.rs b/payments/src/lib.rs index 3b34fba71..bb37bcb32 100644 --- a/payments/src/lib.rs +++ b/payments/src/lib.rs @@ -4,9 +4,9 @@ #![allow(unused)] use crate::db::{ deliveries::{Data, WhereParam}, - new_client, + new_client_with_url, read_filters::{IntFilter, StringFilter}, - PrismaClient, + PrismaClient, PrismaClientBuilder, }; use anyhow::anyhow; use codec::Encode; @@ -38,8 +38,9 @@ pub struct TransactionPayment { impl TransactionPayment { /// Create the local database if it does not exist - pub async fn initialize() -> anyhow::Result { - let client = new_client().await?; + pub async fn initialize(url: &str) -> anyhow::Result { + let url = format!("file:{}", url); + let client = new_client_with_url(&url).await?; #[cfg(debug_assertions)] client._db_push().await?; #[cfg(not(debug_assertions))] diff --git a/payments/src/tests.rs b/payments/src/tests.rs index d80feab07..42f7fe3e7 100644 --- a/payments/src/tests.rs +++ b/payments/src/tests.rs @@ -10,7 +10,7 @@ use tesseract_primitives::{mocks::MockHost, Hasher, Query, TxReceipt}; #[tokio::test] async fn transaction_payments_flow() { - let tx_payment = TransactionPayment::initialize().await.unwrap(); + let tx_payment = TransactionPayment::initialize("./dev.db").await.unwrap(); let receipts = (0..500).into_iter().map(|i| { let post = Post { source: StateMachine::Bsc, diff --git a/relayer/src/cli.rs b/relayer/src/cli.rs index bb95285dd..13997c7ed 100644 --- a/relayer/src/cli.rs +++ b/relayer/src/cli.rs @@ -40,6 +40,11 @@ pub struct Cli { #[arg(short, long)] pub config: String, + /// Path to the relayer database file + /// e.g /home/root/dev.db + #[arg(short, long)] + pub db: String, + /// Should we initialize the relevant consensus states on Eth chains? #[arg(short, long)] setup_eth: bool, @@ -122,7 +127,7 @@ impl Cli { log::warn!("Setting the minimum_profit_percentage=0 is not reccomended in live environments!"); } let tx_payment = Arc::new( - TransactionPayment::initialize() + TransactionPayment::initialize(&self.db) .await .map_err(|err| anyhow!("Error initializing database: {err:?}"))?, ); diff --git a/relayer/src/main.rs b/relayer/src/main.rs index 47e174c4e..86ba38dd7 100644 --- a/relayer/src/main.rs +++ b/relayer/src/main.rs @@ -21,7 +21,8 @@ async fn main() -> Result<(), anyhow::Error> { let cli = Cli::parse(); if let Some(command) = cli.subcommand { match command { - Subcommand::AccumulateFees(cmd) => cmd.accumulate_fees(cli.config.clone()).await?, + Subcommand::AccumulateFees(cmd) => + cmd.accumulate_fees(cli.config.clone(), cli.db.clone()).await?, } return Ok(()) } diff --git a/relayer/src/tx_payment.rs b/relayer/src/tx_payment.rs index fdb88084e..44cf07116 100644 --- a/relayer/src/tx_payment.rs +++ b/relayer/src/tx_payment.rs @@ -46,7 +46,7 @@ pub struct AccumulateFees { impl AccumulateFees { /// Accumulate fees accrued through deliveries from source to dest and dest to source - pub async fn accumulate_fees(&self, config_path: String) -> anyhow::Result<()> { + pub async fn accumulate_fees(&self, config_path: String, db: String) -> anyhow::Result<()> { logging::setup()?; let config = HyperbridgeConfig::parse_conf(&config_path).await?; @@ -62,7 +62,7 @@ impl AccumulateFees { let clients = create_client_map(config).await?; - let tx_payment = TransactionPayment::initialize().await?; + let tx_payment = TransactionPayment::initialize(&db).await?; log::info!("Initialized database"); let source_chain = StateMachine::from_str(&self.source).expect("Invalid Source State Machine provided");