Address clippy complaints in pox-locking repo

Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
This commit is contained in:
Jacinta Ferrant
2023-09-19 13:48:59 -07:00
committed by Joey Yandle
parent c5ab5c5a64
commit fd0cdc3e00
5 changed files with 60 additions and 75 deletions

View File

@@ -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(),
}
}

View File

@@ -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(

View File

@@ -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(())
}

View File

@@ -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

View File

@@ -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