Skip to content

Commit

Permalink
add index
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Dec 6, 2024
1 parent 18e0061 commit e795c9d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/load_exchange_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ pub async fn impl_batch_tx_insert(pool: &Graph, batch_txs: &[ExchangeOrder]) ->

pub async fn load_from_json(path: &Path, pool: &Graph, batch_size: usize) -> Result<(u64, u64)> {
let mut orders = extract_exchange_orders::read_orders_from_file(path)?;
info!("completed parsing orders");

// add RMS stats to each order
enrich_rms::include_rms_stats(&mut orders);
info!("completed rms statistics");

// find likely shill bids
enrich_rms::process_sell_order_shill(&mut orders);
enrich_rms::process_buy_order_shill(&mut orders);
info!("completed shill bid calculation");

let mut balances = BalanceTracker::new();
balances.replay_transactions(&mut orders)?;
Expand Down
6 changes: 6 additions & 0 deletions src/neo4j_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub static INDEX_SWAP_ID: &str =
pub static INDEX_SWAP_TIME: &str =
"CREATE INDEX swap_time IF NOT EXISTS FOR ()-[r:Swap]-() ON (r.filled_at)";

pub static INDEX_EXCHANGE_LEDGER: &str = r#"
CREATE INDEX user_ledger IF NOT EXISTS FOR (ul:UserExchangeLedger) ON (ul.date)
CREATE INDEX link_ledger IF NOT EXISTS FOR ()-[r:DailyLedger]->() ON (r.date)
"#;

/// get the testing neo4j connection
pub async fn get_neo4j_localhost_pool(port: u16) -> Result<Graph> {
let uri = format!("127.0.0.1:{port}");
Expand Down Expand Up @@ -67,6 +72,7 @@ pub async fn maybe_create_indexes(graph: &Graph) -> Result<()> {
INDEX_TX_HASH,
INDEX_TX_FUNCTION,
INDEX_SWAP_ID,
INDEX_EXCHANGE_LEDGER,
])
.await?;
txn.commit().await?;
Expand Down
6 changes: 4 additions & 2 deletions tests/test_enrich_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,16 @@ async fn e2e_swap_data() -> Result<()> {
}

#[tokio::test]
async fn test_entry_point_exchange_load() -> Result<()>{
async fn test_entry_point_exchange_load() -> Result<()> {
libra_forensic_db::log_setup();

let c = start_neo4j_container();
let port = c.get_host_port_ipv4(7687);
let graph = get_neo4j_localhost_pool(port).await?;
maybe_create_indexes(&graph).await?;

let path = env!("CARGO_MANIFEST_DIR");
let buf = PathBuf::from(path).join("tests/fixtures/savedOlOrders2.json");
load_exchange_orders::load_from_json(&buf, &graph, 250).await?;
load_exchange_orders::load_from_json(&buf, &graph, 10).await?;
Ok(())
}

0 comments on commit e795c9d

Please sign in to comment.