Skip to content

Commit

Permalink
Make database path configurable (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Feb 26, 2024
1 parent 995ea01 commit 4f62905
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
9 changes: 5 additions & 4 deletions payments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,8 +38,9 @@ pub struct TransactionPayment {

impl TransactionPayment {
/// Create the local database if it does not exist
pub async fn initialize() -> anyhow::Result<Self> {
let client = new_client().await?;
pub async fn initialize(url: &str) -> anyhow::Result<Self> {
let url = format!("file:{}", url);
let client = new_client_with_url(&url).await?;
#[cfg(debug_assertions)]
client._db_push().await?;
#[cfg(not(debug_assertions))]
Expand Down
2 changes: 1 addition & 1 deletion payments/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion relayer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:?}"))?,
);
Expand Down
3 changes: 2 additions & 1 deletion relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
4 changes: 2 additions & 2 deletions relayer/src/tx_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand All @@ -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");
Expand Down

0 comments on commit 4f62905

Please sign in to comment.