Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
- All API errors must go through the `ApiError` enum, never return raw status codes
- Keep OpenAPI annotations (`#[utoipa::path(...)]`) in sync when adding or modifying routes
- Do not commit `.env` or secrets; use `.env.example` for documenting env vars
- Use the `address!` macro from `alloy::primitives` for creating `Address` constants instead of parsing from strings
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ rain_orderbook_common = { path = "lib/rain.orderbook/crates/common", default-fea
rain_orderbook_app_settings = { path = "lib/rain.orderbook/crates/settings", default-features = false }
rain_orderbook_bindings = { path = "lib/rain.orderbook/crates/bindings", default-features = false }
rain-math-float = { path = "lib/rain.orderbook/lib/rain.interpreter/lib/rain.interpreter.interface/lib/rain.math.float/crates/float" }
futures = "0.3"
wasm-bindgen = "=0.2.100"
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum ApiError {
Internal(String),
#[error("Rate limited: {0}")]
RateLimited(String),
#[error("Not yet indexed: {0}")]
NotYetIndexed(String),
}

impl<'r> Responder<'r, 'static> for ApiError {
Expand All @@ -42,6 +44,7 @@ impl<'r> Responder<'r, 'static> for ApiError {
ApiError::NotFound(msg) => (Status::NotFound, "NOT_FOUND", msg.clone()),
ApiError::Internal(msg) => (Status::InternalServerError, "INTERNAL_ERROR", msg.clone()),
ApiError::RateLimited(msg) => (Status::TooManyRequests, "RATE_LIMITED", msg.clone()),
ApiError::NotYetIndexed(msg) => (Status::Accepted, "NOT_YET_INDEXED", msg.clone()),
};
let span = request_span_for(req);
span.in_scope(|| {
Expand All @@ -52,6 +55,13 @@ impl<'r> Responder<'r, 'static> for ApiError {
error_message = %message,
"request failed"
);
} else if matches!(self, ApiError::NotYetIndexed(_)) {
tracing::info!(
status = status.code,
code = %code,
error_message = %message,
"transaction not yet indexed"
);
} else {
tracing::warn!(
status = status.code,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl Modify for SecurityAddon {
routes::order::post_order_cancel,
routes::orders::get_orders_by_tx,
routes::orders::get_orders_by_address,
routes::trades::get_trades_by_tx,
routes::trades::get_trades_by_address,
routes::trades::get_by_tx::get_trades_by_tx,
routes::trades::get_by_address::get_trades_by_address,
),
components(),
modifiers(&SecurityAddon),
Expand Down
85 changes: 0 additions & 85 deletions src/routes/trades.rs

This file was deleted.

45 changes: 45 additions & 0 deletions src/routes/trades/get_by_address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::auth::AuthenticatedKey;
use crate::error::{ApiError, ApiErrorResponse};
use crate::fairings::{GlobalRateLimit, TracingSpan};
use crate::types::common::ValidatedAddress;
use crate::types::trades::{TradesByAddressResponse, TradesPaginationParams};
use rocket::serde::json::Json;
use rocket::State;
use tracing::Instrument;

#[utoipa::path(
get,
path = "/v1/trades/{address}",
tag = "Trades",
security(("basicAuth" = [])),
params(
("address" = String, Path, description = "Owner address"),
TradesPaginationParams,
),
responses(
(status = 200, description = "Paginated list of trades", body = TradesByAddressResponse),
(status = 400, description = "Bad request", body = ApiErrorResponse),
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
(status = 429, description = "Rate limited", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
)
)]
#[get("/<address>?<params..>", rank = 2)]
pub async fn get_trades_by_address(
_global: GlobalRateLimit,
_key: AuthenticatedKey,
raindex: &State<crate::raindex::RaindexProvider>,
span: TracingSpan,
address: ValidatedAddress,
params: TradesPaginationParams,
) -> Result<Json<TradesByAddressResponse>, ApiError> {
async move {
tracing::info!(address = ?address, params = ?params, "request received");
raindex
.run_with_client(move |_client| async move { todo!() })
.await
.map_err(ApiError::from)?
}
.instrument(span.0)
.await
}
Loading