Skip to content

Commit

Permalink
fix: change types on api (#358)
Browse files Browse the repository at this point in the history
# What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `cargo fmt`.

Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Jan 18, 2024
1 parent fb9f6bd commit a43e955
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use axum::extract::State;
use axum::extract::{Path, Query, State};
use axum::{http::StatusCode, routing::get, Json, Router};
use ethers::abi::Address;
use ethers::types::{H256, U256};
Expand All @@ -8,7 +8,6 @@ use storage::UserWithdrawal;

#[derive(Deserialize, Serialize, Clone)]
struct WithdrawalRequest {
pub from: Address,
pub limit: u64,
}
#[derive(Deserialize, Serialize, Clone)]
Expand All @@ -32,7 +31,7 @@ impl From<UserWithdrawal> for WithdrawalResponse {

pub async fn run_server(pool: PgPool) {
let app = Router::new()
.route("/withdrawals", get(get_withdrawals))
.route("/withdrawals/:from", get(get_withdrawals))
.with_state(pool);

// run our app with hyper, listening globally on port 3000
Expand All @@ -41,10 +40,11 @@ pub async fn run_server(pool: PgPool) {
}

async fn get_withdrawals(
Path(from): Path<Address>,
State(pool): State<PgPool>,
Json(payload): Json<WithdrawalRequest>,
Query(payload): Query<WithdrawalRequest>,
) -> Result<Json<Vec<WithdrawalResponse>>, StatusCode> {
let result: Vec<_> = storage::withdrawals_for_address(&pool, payload.from, payload.limit)
let result: Vec<_> = storage::withdrawals_for_address(&pool, from, payload.limit)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
.into_iter()
Expand Down

0 comments on commit a43e955

Please sign in to comment.