From 907768964db67ba29bf38aad715ded3813852c09 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 2 Jan 2025 13:33:00 +0000 Subject: [PATCH] Plain to enc dump conversions --- matching_engine/src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/matching_engine/src/main.rs b/matching_engine/src/main.rs index 7830258..2297aaf 100644 --- a/matching_engine/src/main.rs +++ b/matching_engine/src/main.rs @@ -2,6 +2,7 @@ use std::fs; use std::io; use dotenv::dotenv; +use matching_engine::Dump; use matching_engine::EncryptedDump; use matching_engine::{MatchingEngine, MatchingEngineConfig}; @@ -31,6 +32,7 @@ async fn main() -> Result<(), Box> { "../matching_engine_config/encrypted_dump.json", "./matching_engine_config/encrypted_dump.json", ]; + match read_file_from_paths(&encrypted_dump_paths) { Ok(dump_content) => { let enc_dump: EncryptedDump = serde_json::from_str(&dump_content)?; @@ -38,6 +40,27 @@ async fn main() -> Result<(), Box> { .run_from_encrypted_dump(enc_dump, encrypted_dump_paths[1].to_string()) .await?; } + Err(e) if e.kind() == io::ErrorKind::NotFound => { + // Handle the NotFound error case + let plain_dump = [ + "../matching_engine_config/dump.json", + "./matching_engine_config/dump.json", + ]; + + match read_file_from_paths(&plain_dump) { + Ok(dump_content) => { + let dump: Dump = serde_json::from_str(&dump_content)?; + matching_engine + .run_from_dump(dump, encrypted_dump_paths[1].to_string()) + .await?; + } + Err(_) => { + matching_engine + .run(encrypted_dump_paths[1].to_string()) + .await?; + } + } + } Err(_) => { matching_engine .run(encrypted_dump_paths[1].to_string())