This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get transactions per addresses (#161)
This PR add an endpoint to collect all of the transactions related to an address.
- Loading branch information
Showing
5 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod account; | ||
pub mod address; | ||
pub mod block; | ||
pub mod transaction; | ||
pub mod validator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use axum::{ | ||
extract::{Path, State}, | ||
Json, | ||
}; | ||
use tracing::info; | ||
|
||
use crate::{ | ||
server::{ServerState, TxInfo}, | ||
Error, | ||
}; | ||
|
||
pub async fn get_txs_by_address( | ||
State(state): State<ServerState>, | ||
Path(address): Path<String>, | ||
) -> Result<Json<Option<Vec<TxInfo>>>, Error> { | ||
info!("calling /address/:{}", address); | ||
|
||
let rows = state.db.get_txs_by_address(&address).await?; | ||
|
||
if rows.is_empty() { | ||
return Ok(Json(None)); | ||
} | ||
|
||
let mut response: Vec<TxInfo> = vec![]; | ||
for row in rows { | ||
let tx = TxInfo::try_from(row)?; | ||
response.push(tx); | ||
} | ||
|
||
Ok(Json(Some(response))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters