From 981e340977477d52374458fa9d5a0ac7db62b971 Mon Sep 17 00:00:00 2001 From: necrashter Date: Sat, 23 Apr 2022 02:21:47 +0300 Subject: Fix coinbase block rewards --- src/handlers.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 23adffb..e31a4ad 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -548,11 +548,11 @@ pub async fn propose_block( let mut users_store = RwLockUpgradableReadGuard::upgrade(users_store); // Reward the block proposer - let coinbase_fingerprint = new_block.transaction_list.get(0).unwrap(); - - if let Some(coinbase_user) = users_store.get_mut(coinbase_fingerprint) { - coinbase_user.balance += BLOCK_REWARD; - } + // All unwrap calls here are guaranteed to succeed because they are already checked above + // See: internal_user_fingerprint, internal_user + let coinbase = pending_transactions.get(&new_block.transaction_list[0]).unwrap(); + let mut coinbase_user = users_store.get_mut(&coinbase.source).unwrap(); + coinbase_user.balance += BLOCK_REWARD; let mut holding: HashMap = HashMap::new(); -- cgit v1.2.3-70-g09d2