From 3f649d6233b06589480713f507924286d297e120 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 22:40:33 +0300 Subject: Transactions return as dict --- src/handlers.rs | 7 ++++--- 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}; use serde::Serialize; use serde_json; use sha2::Sha256; +use std::collections::HashMap; use std::convert::Infallible; use std::fs; use warp::{http::StatusCode, reply}; @@ -208,13 +209,13 @@ pub async fn authenticate_user( /// Cannot fail pub async fn list_transactions(db: Db) -> Result { debug!("GET request to /transaction, list_transactions"); - let mut result = Vec::new(); + let mut result = HashMap::new(); let transactions = db.pending_transactions.read(); // let transactions = transactions.clone().into_iter().collect(); - for (_, value) in transactions.iter() { - result.push(value) + for (fp, tx) in transactions.iter() { + result.insert(fp, tx); } 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 assert_eq!(res.status(), StatusCode::OK); - 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"}]"#; + 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"}}"#; assert_eq!(res.body(), expected_json_body); } -- cgit v1.2.3-70-g09d2