summaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 482f5b1..e63933d 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -8,6 +8,7 @@ use jsonwebtoken::errors::ErrorKind;
8use jsonwebtoken::{decode, Algorithm, DecodingKey, TokenData, Validation}; 8use jsonwebtoken::{decode, Algorithm, DecodingKey, TokenData, Validation};
9use log::{debug, warn}; 9use log::{debug, warn};
10use md5::Md5; 10use md5::Md5;
11use parking_lot::RwLockUpgradableReadGuard;
11use rsa::{PaddingScheme, RSAPrivateKey}; 12use rsa::{PaddingScheme, RSAPrivateKey};
12use serde::Serialize; 13use serde::Serialize;
13use sha2::Sha256; 14use sha2::Sha256;
@@ -334,7 +335,7 @@ pub async fn authorized_propose_block(
334 335
335 let users_store = db.users.upgradable_read(); 336 let users_store = db.users.upgradable_read();
336 337
337 println!("{:?}", &new_block); 338 warn!("{:?}", &new_block);
338 339
339 if new_block.transaction_list.is_empty() { 340 if new_block.transaction_list.is_empty() {
340 let res_json = warp::reply::json(&GradeCoinResponse { 341 let res_json = warp::reply::json(&GradeCoinResponse {
@@ -455,7 +456,7 @@ pub async fn authorized_propose_block(
455 456
456 { 457 {
457 let pending_transactions = db.pending_transactions.read(); 458 let pending_transactions = db.pending_transactions.read();
458 let mut users = db.users.write(); 459 let mut users_store = RwLockUpgradableReadGuard::upgrade(users_store);
459 460
460 let coinbase_fingerprint = new_block.transaction_list.get(0).unwrap(); 461 let coinbase_fingerprint = new_block.transaction_list.get(0).unwrap();
461 462
@@ -464,17 +465,17 @@ pub async fn authorized_propose_block(
464 let source = &transaction.source; 465 let source = &transaction.source;
465 let target = &transaction.target; 466 let target = &transaction.target;
466 467
467 if let Some(from) = users.get_mut(source) { 468 if let Some(from) = users_store.get_mut(source) {
468 from.balance -= transaction.amount; 469 from.balance -= transaction.amount;
469 } 470 }
470 471
471 if let Some(to) = users.get_mut(target) { 472 if let Some(to) = users_store.get_mut(target) {
472 to.balance += transaction.amount; 473 to.balance += transaction.amount;
473 } 474 }
474 } 475 }
475 } 476 }
476 477
477 if let Some(coinbase_user) = users.get_mut(coinbase_fingerprint) { 478 if let Some(coinbase_user) = users_store.get_mut(coinbase_fingerprint) {
478 coinbase_user.balance += BLOCK_REWARD as i32; 479 coinbase_user.balance += BLOCK_REWARD as i32;
479 } 480 }
480 } 481 }