From 7523fe839542f14e9e5fd8ebd5496e792c7ce19c Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Mon, 4 Nov 2024 14:52:10 -0600 Subject: [PATCH] Remove balance endpoint (#20095) ## Description Remove balance endpoint for Deepbook Indexer ## Test plan How did you test the new or updated feature? Local indexer ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [x] Indexer: Deepbook Indexer endpoint removal - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- crates/sui-deepbook-indexer/src/server.rs | 30 ----------------------- 1 file changed, 30 deletions(-) diff --git a/crates/sui-deepbook-indexer/src/server.rs b/crates/sui-deepbook-indexer/src/server.rs index 0d2b1ff85092f..518db2353da49 100644 --- a/crates/sui-deepbook-indexer/src/server.rs +++ b/crates/sui-deepbook-indexer/src/server.rs @@ -29,7 +29,6 @@ pub const GET_24HR_VOLUME_BY_BALANCE_MANAGER_ID: &str = pub const GET_HISTORICAL_VOLUME_PATH: &str = "/get_historical_volume/:pool_ids/:start_time/:end_time"; pub const GET_NET_DEPOSITS: &str = "/get_net_deposits/:asset_ids/:timestamp"; -pub const GET_MANAGER_BALANCE: &str = "/get_manager_balance/:manager_id"; pub fn run_server(socket_address: SocketAddr, state: PgDeepbookPersistent) -> JoinHandle<()> { tokio::spawn(async move { @@ -48,7 +47,6 @@ pub(crate) fn make_router(state: PgDeepbookPersistent) -> Router { GET_24HR_VOLUME_BY_BALANCE_MANAGER_ID, get(get_24hr_volume_by_balance_manager_id), ) - .route(GET_MANAGER_BALANCE, get(get_manager_balance)) .route(GET_NET_DEPOSITS, get(get_net_deposits)) .with_state(state) } @@ -189,34 +187,6 @@ async fn get_24hr_volume_by_balance_manager_id( Ok(Json(vec![maker_vol, taker_vol])) } -async fn get_manager_balance( - Path(manager_id): Path, - State(state): State, -) -> Result>, DeepBookError> { - let connection = &mut state.pool.get().await?; - - // Query to get the balance for all assets for the specified manager_id - let query = format!( - "SELECT asset, SUM(CASE WHEN deposit THEN amount ELSE -amount END)::bigint AS amount, deposit FROM balances \ - WHERE balance_manager_id = '{}' GROUP BY asset, deposit", - manager_id - ); - - let results: Vec = diesel::sql_query(query).load(connection).await?; - - // Aggregate results into a HashMap as {asset: balance} - let mut manager_balances = HashMap::new(); - for result in results { - let mut asset = result.asset; - if !asset.starts_with("0x") { - asset.insert_str(0, "0x"); - } - manager_balances.insert(asset, result.amount); - } - - Ok(Json(manager_balances)) -} - #[debug_handler] async fn get_net_deposits( Path((asset_ids, timestamp)): Path<(String, String)>,