aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index a5070a4..e12d83e 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -1,5 +1,5 @@
1use aes::Aes128;
2/// API handlers, the ends of each filter chain 1/// API handlers, the ends of each filter chain
2use aes::Aes128;
3use askama::Template; 3use askama::Template;
4use blake2::{Blake2s, Digest}; 4use blake2::{Blake2s, Digest};
5use block_modes::block_padding::Pkcs7; 5use block_modes::block_padding::Pkcs7;
@@ -12,7 +12,7 @@ use parking_lot::RwLockUpgradableReadGuard;
12use rsa::{PaddingScheme, RSAPrivateKey}; 12use rsa::{PaddingScheme, RSAPrivateKey};
13use serde::Serialize; 13use serde::Serialize;
14use sha2::Sha256; 14use sha2::Sha256;
15use std::collections::HashMap; 15use std::collections::{HashMap, HashSet};
16use std::convert::Infallible; 16use std::convert::Infallible;
17use std::fs; 17use std::fs;
18use warp::{http::StatusCode, reply}; 18use warp::{http::StatusCode, reply};
@@ -404,6 +404,26 @@ pub async fn propose_block(
404 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); 404 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));
405 } 405 }
406 406
407 // scope the HashSet
408 {
409 let mut proposed_transactions = HashSet::new();
410 for tx in new_block.transaction_list.iter() {
411 proposed_transactions.insert(tx);
412 }
413
414 if proposed_transactions.len() != BLOCK_TRANSACTION_COUNT as usize {
415 let res_json = warp::reply::json(&GradeCoinResponse {
416 res: ResponseType::Error,
417 message: format!(
418 "Block cannot contain less than {} unique transactions.",
419 BLOCK_TRANSACTION_COUNT
420 ),
421 });
422
423 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));
424 }
425 }
426
407 // Scope the RwLocks, there are hashing stuff below 427 // Scope the RwLocks, there are hashing stuff below
408 { 428 {
409 let pending_transactions = db.pending_transactions.read(); 429 let pending_transactions = db.pending_transactions.read();
@@ -457,7 +477,7 @@ pub async fn propose_block(
457 } 477 }
458 478
459 // All clear, block accepted! 479 // All clear, block accepted!
460 debug!("We have a new block! {:?}", new_block); 480 warn!("ACCEPTED BLOCK {:?}", new_block);
461 481
462 // Scope the pending_transactions 482 // Scope the pending_transactions
463 { 483 {
@@ -529,6 +549,8 @@ pub async fn propose_transaction(
529) -> Result<impl warp::Reply, warp::Rejection> { 549) -> Result<impl warp::Reply, warp::Rejection> {
530 debug!("POST /transaction, propose_transaction() is handling"); 550 debug!("POST /transaction, propose_transaction() is handling");
531 551
552 warn!("New transaction proposal: {:?}", &new_transaction);
553
532 let users_store = db.users.read(); 554 let users_store = db.users.read();
533 555
534 // Is this transaction from an authorized source? 556 // Is this transaction from an authorized source?
@@ -672,7 +694,7 @@ pub async fn propose_transaction(
672 )); 694 ));
673 } 695 }
674 696
675 warn!("NEW TRANSACTION {:?}", new_transaction); 697 warn!("ACCEPTED TRANSACTION {:?}", new_transaction);
676 698
677 let mut transactions = db.pending_transactions.write(); 699 let mut transactions = db.pending_transactions.write();
678 700