From fd0cdc3e00d8b59f426dca157c08dd23ce96465d Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Tue, 19 Sep 2023 13:48:59 -0700 Subject: [PATCH] Address clippy complaints in pox-locking repo Signed-off-by: Jacinta Ferrant --- pox-locking/src/events.rs | 2 +- pox-locking/src/lib.rs | 6 ++-- pox-locking/src/pox_1.rs | 25 ++++++++--------- pox-locking/src/pox_2.rs | 58 ++++++++++++++++++--------------------- pox-locking/src/pox_3.rs | 44 +++++++++++++---------------- 5 files changed, 60 insertions(+), 75 deletions(-) diff --git a/pox-locking/src/events.rs b/pox-locking/src/events.rs index f37fdc68e..9f44330c3 100644 --- a/pox-locking/src/events.rs +++ b/pox-locking/src/events.rs @@ -335,7 +335,7 @@ fn create_event_info_data_code(function_name: &str, args: &[Value]) -> String { pox_addr = &args[3], ) } - _ => format!("{{ data: {{ unimplemented: true }} }}"), + _ => "{{ data: {{ unimplemented: true }} }}".into(), } } diff --git a/pox-locking/src/lib.rs b/pox-locking/src/lib.rs index 9d8da8148..b195f4cc9 100644 --- a/pox-locking/src/lib.rs +++ b/pox-locking/src/lib.rs @@ -49,9 +49,9 @@ pub enum LockingError { PoxInvalidIncrease, } -pub const POX_1_NAME: &'static str = "pox"; -pub const POX_2_NAME: &'static str = "pox-2"; -pub const POX_3_NAME: &'static str = "pox-3"; +pub const POX_1_NAME: &str = "pox"; +pub const POX_2_NAME: &str = "pox-2"; +pub const POX_3_NAME: &str = "pox-3"; /// Handle special cases of contract-calls -- namely, those into PoX that should lock up STX pub fn handle_contract_call_special_cases( diff --git a/pox-locking/src/pox_1.rs b/pox-locking/src/pox_1.rs index fb8e29097..a737c8547 100644 --- a/pox-locking/src/pox_1.rs +++ b/pox-locking/src/pox_1.rs @@ -40,19 +40,19 @@ fn parse_pox_stacking_result_v1( let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let lock_amount = tuple_data .get("lock-amount") - .expect(&format!("FATAL: no 'lock-amount'")) + .expect("FATAL: no 'lock-amount'") .to_owned() .expect_u128(); let unlock_burn_height = tuple_data .get("unlock-burn-height") - .expect(&format!("FATAL: no 'unlock-burn-height'")) + .expect("FATAL: no 'unlock-burn-height'") .to_owned() .expect_u128() .try_into() @@ -158,7 +158,7 @@ pub fn handle_contract_call( &mut global_context.database, &stacker, locked_amount, - unlock_height as u64, + unlock_height, ) { Ok(_) => { if let Some(batch) = global_context.event_batches.last_mut() { @@ -171,19 +171,18 @@ pub fn handle_contract_call( }), )); } + Ok(()) } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )) - } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(LockingError::PoxAlreadyLocked) => { // the caller tried to lock tokens into both pox-1 and pox-2 - return Err(ClarityError::Runtime( + Err(ClarityError::Runtime( RuntimeErrorType::PoxAlreadyLocked, None, - )); + )) } Err(e) => { panic!( @@ -192,6 +191,4 @@ pub fn handle_contract_call( ); } } - - Ok(()) } diff --git a/pox-locking/src/pox_2.rs b/pox-locking/src/pox_2.rs index 11a6fff7a..a7b7e78d4 100644 --- a/pox-locking/src/pox_2.rs +++ b/pox-locking/src/pox_2.rs @@ -68,19 +68,19 @@ pub fn parse_pox_stacking_result( let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let lock_amount = tuple_data .get("lock-amount") - .expect(&format!("FATAL: no 'lock-amount'")) + .expect("FATAL: no 'lock-amount'") .to_owned() .expect_u128(); let unlock_burn_height = tuple_data .get("unlock-burn-height") - .expect(&format!("FATAL: no 'unlock-burn-height'")) + .expect("FATAL: no 'unlock-burn-height'") .to_owned() .expect_u128() .try_into() @@ -102,13 +102,13 @@ pub fn parse_pox_extend_result(result: &Value) -> std::result::Result<(Principal let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let unlock_burn_height = tuple_data .get("unlock-burn-height") - .expect(&format!("FATAL: no 'unlock-burn-height'")) + .expect("FATAL: no 'unlock-burn-height'") .to_owned() .expect_u128() .try_into() @@ -131,13 +131,13 @@ pub fn parse_pox_increase(result: &Value) -> std::result::Result<(PrincipalData, let tuple_data = res.expect_tuple(); let stacker = tuple_data .get("stacker") - .expect(&format!("FATAL: no 'stacker'")) + .expect("FATAL: no 'stacker'") .to_owned() .expect_principal(); let total_locked = tuple_data .get("total-locked") - .expect(&format!("FATAL: no 'total-locked'")) + .expect("FATAL: no 'total-locked'") .to_owned() .expect_u128(); @@ -300,7 +300,7 @@ fn handle_stack_lockup_pox_v2( &mut global_context.database, &stacker, locked_amount, - unlock_height as u64, + unlock_height, ) { Ok(_) => { let event = @@ -310,20 +310,18 @@ fn handle_stack_lockup_pox_v2( locked_address: stacker, contract_identifier: boot_code_id("pox-2", global_context.mainnet), })); - return Ok(Some(event)); - } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )); + Ok(Some(event)) } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(LockingError::PoxAlreadyLocked) => { // the caller tried to lock tokens into both pox-1 and pox-2 - return Err(ClarityError::Runtime( + Err(ClarityError::Runtime( RuntimeErrorType::PoxAlreadyLocked, None, - )); + )) } Err(e) => { panic!( @@ -368,7 +366,7 @@ fn handle_stack_lockup_extension_pox_v2( } }; - match pox_lock_extend_v2(&mut global_context.database, &stacker, unlock_height as u64) { + match pox_lock_extend_v2(&mut global_context.database, &stacker, unlock_height) { Ok(locked_amount) => { let event = StacksTransactionEvent::STXEvent(STXEventType::STXLockEvent(STXLockEventData { @@ -377,14 +375,12 @@ fn handle_stack_lockup_extension_pox_v2( locked_address: stacker, contract_identifier: boot_code_id("pox-2", global_context.mainnet), })); - return Ok(Some(event)); - } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )) + Ok(Some(event)) } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(e) => { // Error results *other* than a DefunctPoxContract panic, because // those errors should have been caught by the PoX contract before @@ -439,14 +435,12 @@ fn handle_stack_lockup_increase_pox_v2( contract_identifier: boot_code_id("pox-2", global_context.mainnet), })); - return Ok(Some(event)); - } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )) + Ok(Some(event)) } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(e) => { // Error results *other* than a DefunctPoxContract panic, because // those errors should have been caught by the PoX contract before diff --git a/pox-locking/src/pox_3.rs b/pox-locking/src/pox_3.rs index c1bb470a5..97b8f31c3 100644 --- a/pox-locking/src/pox_3.rs +++ b/pox-locking/src/pox_3.rs @@ -183,7 +183,7 @@ fn handle_stack_lockup_pox_v3( &mut global_context.database, &stacker, locked_amount, - unlock_height as u64, + unlock_height, ) { Ok(_) => { let event = @@ -193,20 +193,18 @@ fn handle_stack_lockup_pox_v3( locked_address: stacker, contract_identifier: boot_code_id(POX_3_NAME, global_context.mainnet), })); - return Ok(Some(event)); - } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )); + Ok(Some(event)) } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(LockingError::PoxAlreadyLocked) => { // the caller tried to lock tokens into multiple pox contracts - return Err(ClarityError::Runtime( + Err(ClarityError::Runtime( RuntimeErrorType::PoxAlreadyLocked, None, - )); + )) } Err(e) => { panic!( @@ -251,7 +249,7 @@ fn handle_stack_lockup_extension_pox_v3( } }; - match pox_lock_extend_v3(&mut global_context.database, &stacker, unlock_height as u64) { + match pox_lock_extend_v3(&mut global_context.database, &stacker, unlock_height) { Ok(locked_amount) => { let event = StacksTransactionEvent::STXEvent(STXEventType::STXLockEvent(STXLockEventData { @@ -260,14 +258,12 @@ fn handle_stack_lockup_extension_pox_v3( locked_address: stacker, contract_identifier: boot_code_id(POX_3_NAME, global_context.mainnet), })); - return Ok(Some(event)); - } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )) + Ok(Some(event)) } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(e) => { // Error results *other* than a DefunctPoxContract panic, because // those errors should have been caught by the PoX contract before @@ -321,14 +317,12 @@ fn handle_stack_lockup_increase_pox_v3( contract_identifier: boot_code_id(POX_3_NAME, global_context.mainnet), })); - return Ok(Some(event)); - } - Err(LockingError::DefunctPoxContract) => { - return Err(ClarityError::Runtime( - RuntimeErrorType::DefunctPoxContract, - None, - )) + Ok(Some(event)) } + Err(LockingError::DefunctPoxContract) => Err(ClarityError::Runtime( + RuntimeErrorType::DefunctPoxContract, + None, + )), Err(e) => { // Error results *other* than a DefunctPoxContract panic, because // those errors should have been caught by the PoX contract before