aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-14 22:40:33 +0300
committerYigit Sever2021-04-14 22:40:33 +0300
commit21e62ad7e312bbe57bf7098f0b3607e72fcffddb (patch)
treecaba4d95573cd27698878790a1e4683e2ab24082 /src/handlers.rs
parent271ac922b8e47a74fc467c2a4c54beae7a4fe60d (diff)
downloadgradecoin-21e62ad7e312bbe57bf7098f0b3607e72fcffddb.tar.gz
gradecoin-21e62ad7e312bbe57bf7098f0b3607e72fcffddb.tar.bz2
gradecoin-21e62ad7e312bbe57bf7098f0b3607e72fcffddb.zip
Transactions return as dict
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 0dfea15..90cc8c4 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -13,6 +13,7 @@ use rsa::{PaddingScheme, RSAPrivateKey};
13use serde::Serialize; 13use serde::Serialize;
14use serde_json; 14use serde_json;
15use sha2::Sha256; 15use sha2::Sha256;
16use std::collections::HashMap;
16use std::convert::Infallible; 17use std::convert::Infallible;
17use std::fs; 18use std::fs;
18use warp::{http::StatusCode, reply}; 19use warp::{http::StatusCode, reply};
@@ -208,13 +209,13 @@ pub async fn authenticate_user(
208/// Cannot fail 209/// Cannot fail
209pub async fn list_transactions(db: Db) -> Result<impl warp::Reply, Infallible> { 210pub async fn list_transactions(db: Db) -> Result<impl warp::Reply, Infallible> {
210 debug!("GET request to /transaction, list_transactions"); 211 debug!("GET request to /transaction, list_transactions");
211 let mut result = Vec::new(); 212 let mut result = HashMap::new();
212 213
213 let transactions = db.pending_transactions.read(); 214 let transactions = db.pending_transactions.read();
214 // let transactions = transactions.clone().into_iter().collect(); 215 // let transactions = transactions.clone().into_iter().collect();
215 216
216 for (_, value) in transactions.iter() { 217 for (fp, tx) in transactions.iter() {
217 result.push(value) 218 result.insert(fp, tx);
218 } 219 }
219 220
220 Ok(reply::with_status(reply::json(&result), StatusCode::OK)) 221 Ok(reply::with_status(reply::json(&result), StatusCode::OK))