Skip to content

Commit 6764b80

Browse files
authored
Migrate get_total_surplus_endpoint to alloy (#3886)
# Description Migrate get_total_surplus_endpoint to alloy # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Migrate get_total_surplus_endpoint to alloy - [ ] Refactor where needed ## How to test Existing tests <!-- ## Related Issues Fixes # -->
1 parent a54a04d commit 6764b80

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

crates/orderbook/src/api/get_total_surplus.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use {
22
crate::database::Postgres,
3-
primitive_types::H160,
3+
alloy::primitives::Address,
44
serde_json::json,
55
std::convert::Infallible,
66
warp::{Filter, Rejection, http::StatusCode, reply::with_status},
77
};
88

99
pub fn get(db: Postgres) -> impl Filter<Extract = (super::ApiReply,), Error = Rejection> + Clone {
10-
warp::path!("v1" / "users" / H160 / "total_surplus")
10+
warp::path!("v1" / "users" / Address / "total_surplus")
1111
.and(warp::get())
1212
.and_then(move |user| {
1313
let db = db.clone();

crates/orderbook/src/database/total_surplus.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {
2+
alloy::primitives::U256,
23
anyhow::Result,
34
database::{Address, byte_array::ByteArray},
4-
primitive_types::{H160, U256},
55
sqlx::PgConnection,
66
};
77

@@ -61,8 +61,8 @@ trade_components AS (
6161
JOIN trades t ON j.uid = t.order_uid
6262
JOIN order_execution oe ON j.uid = oe.order_uid
6363
WHERE j.owner = $1 AND NOT EXISTS (
64-
SELECT 1
65-
FROM orders o
64+
SELECT 1
65+
FROM orders o
6666
WHERE o.uid = j.uid
6767
)
6868
),
@@ -88,14 +88,14 @@ FROM trade_surplus
8888
}
8989

9090
impl super::Postgres {
91-
pub async fn total_surplus(&self, user: &H160) -> Result<U256> {
91+
pub async fn total_surplus(&self, user: &alloy::primitives::Address) -> Result<U256> {
9292
let _timer = super::Metrics::get()
9393
.database_queries
9494
.with_label_values(&["get_total_surplus"])
9595
.start_timer();
9696

9797
let mut ex = self.pool.acquire().await?;
98-
let surplus = fetch_total_surplus(&mut ex, &ByteArray(user.0)).await?;
99-
Ok(U256::from_f64_lossy(surplus))
98+
let surplus = fetch_total_surplus(&mut ex, &ByteArray(user.0.0)).await?;
99+
Ok(U256::from(surplus))
100100
}
101101
}

0 commit comments

Comments
 (0)