diff options
author | Yigit Sever | 2021-04-14 22:40:33 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-14 22:40:33 +0300 |
commit | 3f649d6233b06589480713f507924286d297e120 (patch) | |
tree | 6f7660e164a57da58f7708830de1ae5082ad975f | |
parent | 0599e005daa03e1cf4dc8e238c1c803c1970beb2 (diff) | |
download | gradecoin-3f649d6233b06589480713f507924286d297e120.tar.gz gradecoin-3f649d6233b06589480713f507924286d297e120.tar.bz2 gradecoin-3f649d6233b06589480713f507924286d297e120.zip |
Transactions return as dict
-rw-r--r-- | src/handlers.rs | 7 | ||||
-rw-r--r-- | tests/route_tests.rs | 2 |
2 files changed, 5 insertions, 4 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}; | |||
13 | use serde::Serialize; | 13 | use serde::Serialize; |
14 | use serde_json; | 14 | use serde_json; |
15 | use sha2::Sha256; | 15 | use sha2::Sha256; |
16 | use std::collections::HashMap; | ||
16 | use std::convert::Infallible; | 17 | use std::convert::Infallible; |
17 | use std::fs; | 18 | use std::fs; |
18 | use warp::{http::StatusCode, reply}; | 19 | use warp::{http::StatusCode, reply}; |
@@ -208,13 +209,13 @@ pub async fn authenticate_user( | |||
208 | /// Cannot fail | 209 | /// Cannot fail |
209 | pub async fn list_transactions(db: Db) -> Result<impl warp::Reply, Infallible> { | 210 | pub 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)) |
diff --git a/tests/route_tests.rs b/tests/route_tests.rs index 5c2d891..55a536d 100644 --- a/tests/route_tests.rs +++ b/tests/route_tests.rs | |||
@@ -98,7 +98,7 @@ sQIDAQAB | |||
98 | 98 | ||
99 | assert_eq!(res.status(), StatusCode::OK); | 99 | assert_eq!(res.status(), StatusCode::OK); |
100 | 100 | ||
101 | let expected_json_body = r#"[{"by":"source_public_key_signature","source":"source_public_key_signature","target":"target_public_key_signature","amount":3,"timestamp":"2021-04-13T20:55:30"}]"#; | 101 | let expected_json_body = r#"{"source_public_key_signature":{"by":"source_public_key_signature","source":"source_public_key_signature","target":"target_public_key_signature","amount":3,"timestamp":"2021-04-13T20:55:30"}}"#; |
102 | 102 | ||
103 | assert_eq!(res.body(), expected_json_body); | 103 | assert_eq!(res.body(), expected_json_body); |
104 | } | 104 | } |