Skip to content

Commit 031c49c

Browse files
authored
Migrate get_orders_by_tx endpoint to alloy (#3883)
# Description Migrate get_orders_by_tx endpoint to alloy # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Migrates the endpoint types to alloy - [ ] Refactors were applicable ## How to test Existing tests <!-- ## Related Issues Fixes # -->
1 parent 29137fe commit 031c49c

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

crates/orderbook/src/api/get_orders_by_tx.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use {
22
crate::{api::ApiReply, orderbook::Orderbook},
3+
alloy::primitives::B256,
34
anyhow::Result,
4-
ethcontract::H256,
55
reqwest::StatusCode,
66
std::{convert::Infallible, sync::Arc},
77
warp::{Filter, Rejection, reply::with_status},
88
};
99

10-
pub fn get_orders_by_tx_request() -> impl Filter<Extract = (H256,), Error = Rejection> + Clone {
11-
warp::path!("v1" / "transactions" / H256 / "orders").and(warp::get())
10+
pub fn get_orders_by_tx_request() -> impl Filter<Extract = (B256,), Error = Rejection> + Clone {
11+
warp::path!("v1" / "transactions" / B256 / "orders").and(warp::get())
1212
}
1313

1414
pub fn get_orders_by_tx(
1515
orderbook: Arc<Orderbook>,
1616
) -> impl Filter<Extract = (ApiReply,), Error = Rejection> + Clone {
17-
get_orders_by_tx_request().and_then(move |hash: H256| {
17+
get_orders_by_tx_request().and_then(move |hash: B256| {
1818
let orderbook = orderbook.clone();
1919
async move {
2020
let result = orderbook.get_orders_for_tx(&hash).await;
@@ -42,6 +42,6 @@ mod tests {
4242
.filter(&get_orders_by_tx_request())
4343
.await
4444
.unwrap();
45-
assert_eq!(result.0, H256::from_str(hash_str).unwrap().0);
45+
assert_eq!(result.0, B256::from_str(hash_str).unwrap().0);
4646
}
4747
}

crates/orderbook/src/database/orders.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use {
22
super::Postgres,
33
crate::dto::TokenMetadata,
4+
alloy::primitives::B256,
45
anyhow::{Context as _, Result},
56
app_data::AppDataHash,
67
async_trait::async_trait,
@@ -66,7 +67,7 @@ pub trait OrderStoring: Send + Sync {
6667
old_order: &OrderUid,
6768
new_order: &Order,
6869
) -> Result<(), InsertionError>;
69-
async fn orders_for_tx(&self, tx_hash: &H256) -> Result<Vec<Order>>;
70+
async fn orders_for_tx(&self, tx_hash: &B256) -> Result<Vec<Order>>;
7071
/// All orders of a single user ordered by creation date descending (newest
7172
/// orders first).
7273
async fn user_orders(
@@ -315,7 +316,7 @@ impl OrderStoring for Postgres {
315316
.transpose()
316317
}
317318

318-
async fn orders_for_tx(&self, tx_hash: &H256) -> Result<Vec<Order>> {
319+
async fn orders_for_tx(&self, tx_hash: &B256) -> Result<Vec<Order>> {
319320
tokio::try_join!(
320321
self.user_order_for_tx(tx_hash),
321322
self.jit_orders_for_tx(tx_hash)
@@ -367,7 +368,7 @@ impl OrderStoring for Postgres {
367368

368369
impl Postgres {
369370
/// Retrieve all user posted orders for a given transaction.
370-
pub async fn user_order_for_tx(&self, tx_hash: &H256) -> Result<Vec<Order>> {
371+
pub async fn user_order_for_tx(&self, tx_hash: &B256) -> Result<Vec<Order>> {
371372
let _timer = super::Metrics::get()
372373
.database_queries
373374
.with_label_values(&["user_order_for_tx"])
@@ -384,7 +385,7 @@ impl Postgres {
384385
}
385386

386387
/// Retrieve all JIT orders for a given transaction.
387-
pub async fn jit_orders_for_tx(&self, tx_hash: &H256) -> Result<Vec<Order>> {
388+
pub async fn jit_orders_for_tx(&self, tx_hash: &B256) -> Result<Vec<Order>> {
388389
let _timer = super::Metrics::get()
389390
.database_queries
390391
.with_label_values(&["jit_orders_for_tx"])

crates/orderbook/src/orderbook.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use {
77
dto,
88
solver_competition::{Identifier, LoadSolverCompetitionError, SolverCompetitionStoring},
99
},
10+
alloy::primitives::B256,
1011
anyhow::{Context, Result},
1112
app_data::{AppDataHash, Validator},
1213
bigdecimal::ToPrimitive,
1314
chrono::Utc,
1415
database::order_events::OrderEventLabel,
15-
ethcontract::H256,
1616
ethrpc::alloy::conversions::IntoLegacy,
1717
model::{
1818
DomainSeparator,
@@ -496,7 +496,7 @@ impl Orderbook {
496496
self.database_replica.single_order(uid).await
497497
}
498498

499-
pub async fn get_orders_for_tx(&self, hash: &H256) -> Result<Vec<Order>> {
499+
pub async fn get_orders_for_tx(&self, hash: &B256) -> Result<Vec<Order>> {
500500
self.database_replica.orders_for_tx(hash).await
501501
}
502502

0 commit comments

Comments
 (0)