Skip to content

Commit f5018ab

Browse files
committed
Migrate get_user_orders endpoint to alloy
1 parent e5b1671 commit f5018ab

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

crates/orderbook/src/api/get_user_orders.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use {
22
crate::{api::ApiReply, orderbook::Orderbook},
3+
alloy::primitives::Address,
34
anyhow::Result,
4-
primitive_types::H160,
55
serde::Deserialize,
66
std::{convert::Infallible, sync::Arc},
77
warp::{Filter, Rejection, hyper::StatusCode, reply::with_status},
@@ -13,16 +13,16 @@ struct Query {
1313
limit: Option<u64>,
1414
}
1515

16-
fn request() -> impl Filter<Extract = (H160, Query), Error = Rejection> + Clone {
17-
warp::path!("v1" / "account" / H160 / "orders")
16+
fn request() -> impl Filter<Extract = (Address, Query), Error = Rejection> + Clone {
17+
warp::path!("v1" / "account" / Address / "orders")
1818
.and(warp::get())
1919
.and(warp::query::<Query>())
2020
}
2121

2222
pub fn get_user_orders(
2323
orderbook: Arc<Orderbook>,
2424
) -> impl Filter<Extract = (ApiReply,), Error = Rejection> + Clone {
25-
request().and_then(move |owner: H160, query: Query| {
25+
request().and_then(move |owner: Address, query: Query| {
2626
let orderbook = orderbook.clone();
2727
async move {
2828
const DEFAULT_OFFSET: u64 = 0;
@@ -54,7 +54,7 @@ pub fn get_user_orders(
5454

5555
#[cfg(test)]
5656
mod tests {
57-
use {super::*, shared::addr};
57+
use super::*;
5858

5959
#[tokio::test]
6060
async fn request_() {
@@ -65,7 +65,7 @@ mod tests {
6565
.filter(&request())
6666
.await
6767
.unwrap();
68-
assert_eq!(result.0, addr!("0000000000000000000000000000000000000001"));
68+
assert_eq!(result.0, Address::with_last_byte(1));
6969
assert_eq!(result.1.offset, None);
7070
assert_eq!(result.1.limit, None);
7171

crates/orderbook/src/database/orders.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub trait OrderStoring: Send + Sync {
7272
/// orders first).
7373
async fn user_orders(
7474
&self,
75-
owner: &H160,
75+
owner: &Address,
7676
offset: u64,
7777
limit: Option<u64>,
7878
) -> Result<Vec<Order>>;
@@ -329,7 +329,7 @@ impl OrderStoring for Postgres {
329329

330330
async fn user_orders(
331331
&self,
332-
owner: &H160,
332+
owner: &Address,
333333
offset: u64,
334334
limit: Option<u64>,
335335
) -> Result<Vec<Order>> {
@@ -341,7 +341,7 @@ impl OrderStoring for Postgres {
341341
let mut ex = self.pool.acquire().await?;
342342
database::order_history::user_orders(
343343
&mut ex,
344-
&ByteArray(owner.0),
344+
&ByteArray(owner.0.0),
345345
i64::try_from(offset).unwrap_or(i64::MAX),
346346
limit.map(|l| i64::try_from(l).unwrap_or(i64::MAX)),
347347
)
@@ -641,6 +641,7 @@ mod tests {
641641
SigningScheme as DbSigningScheme,
642642
},
643643
},
644+
ethrpc::alloy::conversions::IntoAlloy,
644645
model::{
645646
interaction::InteractionData,
646647
order::{Order, OrderData, OrderMetadata, OrderStatus, OrderUid},
@@ -904,7 +905,7 @@ mod tests {
904905
.unwrap();
905906

906907
let order_statuses = db
907-
.user_orders(&owner, 0, None)
908+
.user_orders(&owner.into_alloy(), 0, None)
908909
.await
909910
.unwrap()
910911
.iter()

crates/orderbook/src/orderbook.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use {
77
dto,
88
solver_competition::{Identifier, LoadSolverCompetitionError, SolverCompetitionStoring},
99
},
10-
alloy::primitives::B256,
10+
alloy::primitives::{Address, B256},
1111
anyhow::{Context, Result},
1212
app_data::{AppDataHash, Validator},
1313
bigdecimal::ToPrimitive,
@@ -512,7 +512,7 @@ impl Orderbook {
512512

513513
pub async fn get_user_orders(
514514
&self,
515-
owner: &H160,
515+
owner: &Address,
516516
offset: u64,
517517
limit: u64,
518518
) -> Result<Vec<Order>> {

0 commit comments

Comments
 (0)