aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYigit Sever2021-04-20 12:21:50 +0300
committerYigit Sever2021-04-20 12:21:50 +0300
commitdebc755d949616b6e21daf8946f6002fa1be8570 (patch)
treec4a9f03949267d555c1900015425995f4f299910 /src
parenta53ccc6f5ca64d46abb94ae743dc5d063a87959e (diff)
downloadgradecoin-debc755d949616b6e21daf8946f6002fa1be8570.tar.gz
gradecoin-debc755d949616b6e21daf8946f6002fa1be8570.tar.bz2
gradecoin-debc755d949616b6e21daf8946f6002fa1be8570.zip
Change block proposal, fix tests
Diffstat (limited to 'src')
-rw-r--r--src/handlers.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/handlers.rs b/src/handlers.rs
index 6305560..bf554ab 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -18,7 +18,7 @@ use std::fs;
18use warp::{http::StatusCode, reply}; 18use warp::{http::StatusCode, reply};
19 19
20use crate::PRIVATE_KEY; 20use crate::PRIVATE_KEY;
21const BLOCK_TRANSACTION_COUNT: u8 = 5; 21const BLOCK_TRANSACTION_COUNT: u8 = 1;
22const BLOCK_REWARD: u16 = 3; 22const BLOCK_REWARD: u16 = 3;
23const TX_UPPER_LIMIT: u16 = 2; 23const TX_UPPER_LIMIT: u16 = 2;
24 24
@@ -181,7 +181,7 @@ pub async fn authenticate_user(
181 let auth_plaintext = match cipher.decrypt(&mut buf) { 181 let auth_plaintext = match cipher.decrypt(&mut buf) {
182 Ok(p) => p, 182 Ok(p) => p,
183 Err(err) => { 183 Err(err) => {
184 println!( 184 debug!(
185 "Base64 decoded auth request did not decrypt correctly {:?} {}", 185 "Base64 decoded auth request did not decrypt correctly {:?} {}",
186 &auth_packet, err 186 &auth_packet, err
187 ); 187 );
@@ -342,11 +342,12 @@ pub async fn propose_block(
342 342
343 warn!("New block proposal: {:?}", &new_block); 343 warn!("New block proposal: {:?}", &new_block);
344 344
345 if new_block.transaction_list.len() != BLOCK_TRANSACTION_COUNT as usize { 345 if new_block.transaction_list.len() < BLOCK_TRANSACTION_COUNT as usize {
346 debug!("{} transactions offered, needed {}", new_block.transaction_list.len(), BLOCK_TRANSACTION_COUNT);
346 let res_json = warp::reply::json(&GradeCoinResponse { 347 let res_json = warp::reply::json(&GradeCoinResponse {
347 res: ResponseType::Error, 348 res: ResponseType::Error,
348 message: format!( 349 message: format!(
349 "There should be {} transactions in the block", 350 "There should be at least {} transaction in the block",
350 BLOCK_TRANSACTION_COUNT 351 BLOCK_TRANSACTION_COUNT
351 ), 352 ),
352 }); 353 });
@@ -411,11 +412,11 @@ pub async fn propose_block(
411 proposed_transactions.insert(tx); 412 proposed_transactions.insert(tx);
412 } 413 }
413 414
414 if proposed_transactions.len() != BLOCK_TRANSACTION_COUNT as usize { 415 if proposed_transactions.len() < BLOCK_TRANSACTION_COUNT as usize {
415 let res_json = warp::reply::json(&GradeCoinResponse { 416 let res_json = warp::reply::json(&GradeCoinResponse {
416 res: ResponseType::Error, 417 res: ResponseType::Error,
417 message: format!( 418 message: format!(
418 "Block cannot contain less than {} unique transactions.", 419 "Block cannot contain less than {} unique transaction(s).",
419 BLOCK_TRANSACTION_COUNT 420 BLOCK_TRANSACTION_COUNT
420 ), 421 ),
421 }); 422 });