diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index 420e82a..0dfea15 100644 --- a/src/handlers.rs +++ b/src/handlers.rs | |||
@@ -19,6 +19,7 @@ use warp::{http::StatusCode, reply}; | |||
19 | 19 | ||
20 | use crate::PRIVATE_KEY; | 20 | use crate::PRIVATE_KEY; |
21 | const BLOCK_TRANSACTION_COUNT: u8 = 10; | 21 | const BLOCK_TRANSACTION_COUNT: u8 = 10; |
22 | const BLOCK_REWARD: u8 = 3; | ||
22 | 23 | ||
23 | // Encryption primitive | 24 | // Encryption primitive |
24 | type Aes128Cbc = Cbc<Aes128, Pkcs7>; | 25 | type Aes128Cbc = Cbc<Aes128, Pkcs7>; |
@@ -360,19 +361,26 @@ pub async fn authorized_propose_block( | |||
360 | let pending_transactions = db.pending_transactions.read(); | 361 | let pending_transactions = db.pending_transactions.read(); |
361 | let mut users = db.users.write(); | 362 | let mut users = db.users.write(); |
362 | 363 | ||
364 | let coinbase_fingerprint = new_block.transaction_list.get(0).unwrap(); | ||
365 | |||
363 | for fingerprint in new_block.transaction_list.iter() { | 366 | for fingerprint in new_block.transaction_list.iter() { |
364 | let transaction = pending_transactions.get(fingerprint).unwrap(); | 367 | if let Some(transaction) = pending_transactions.get(fingerprint) { |
365 | let source = &transaction.source; | 368 | let source = &transaction.source; |
366 | let target = &transaction.target; | 369 | let target = &transaction.target; |
367 | 370 | ||
368 | if let Some(from) = users.get_mut(source) { | 371 | if let Some(from) = users.get_mut(source) { |
369 | from.balance -= transaction.amount; | 372 | from.balance -= transaction.amount; |
370 | } | 373 | } |
371 | 374 | ||
372 | if let Some(to) = users.get_mut(target) { | 375 | if let Some(to) = users.get_mut(target) { |
373 | to.balance += transaction.amount; | 376 | to.balance += transaction.amount; |
377 | } | ||
374 | } | 378 | } |
375 | } | 379 | } |
380 | |||
381 | if let Some(coinbase_user) = users.get_mut(coinbase_fingerprint) { | ||
382 | coinbase_user.balance += BLOCK_REWARD as i32; | ||
383 | } | ||
376 | } | 384 | } |
377 | 385 | ||
378 | { | 386 | { |