feat: add pedantic clippy lints

This commit is contained in:
Daniil Polyakov
2026-03-17 21:25:30 +03:00
parent 756f2f4135
commit efe8393ba0
145 changed files with 1549 additions and 1187 deletions
@@ -7,18 +7,17 @@ use nssa_core::{
/// Initializes a default account under the ownership of this program.
fn initialize_account(pre_state: AccountWithMetadata) -> AccountPostState {
let account_to_claim = AccountPostState::new_claimed(pre_state.account.clone());
let account_to_claim = AccountPostState::new_claimed(pre_state.account);
let is_authorized = pre_state.is_authorized;
// Continue only if the account to claim has default values
if account_to_claim.account() != &Account::default() {
panic!("Account must be uninitialized");
}
assert!(
account_to_claim.account() == &Account::default(),
"Account must be uninitialized"
);
// Continue only if the owner authorized this operation
if !is_authorized {
panic!("Account must be authorized");
}
assert!(is_authorized, "Account must be authorized");
account_to_claim
}
@@ -30,26 +29,25 @@ fn transfer(
balance_to_move: u128,
) -> Vec<AccountPostState> {
// Continue only if the sender has authorized this operation
if !sender.is_authorized {
panic!("Sender must be authorized");
}
assert!(sender.is_authorized, "Sender must be authorized");
// Continue only if the sender has enough balance
if sender.account.balance < balance_to_move {
panic!("Sender has insufficient balance");
}
assert!(
sender.account.balance >= balance_to_move,
"Sender has insufficient balance"
);
// Create accounts post states, with updated balances
let sender_post = {
// Modify sender's balance
let mut sender_post_account = sender.account.clone();
let mut sender_post_account = sender.account;
sender_post_account.balance -= balance_to_move;
AccountPostState::new(sender_post_account)
};
let recipient_post = {
// Modify recipient's balance
let mut recipient_post_account = recipient.account.clone();
let mut recipient_post_account = recipient.account;
recipient_post_account.balance += balance_to_move;
// Claim recipient account if it has default program owner
+2 -3
View File
@@ -52,9 +52,8 @@ fn main() {
instruction_words,
) = read_nssa_inputs::<Instruction>();
let [pinata, winner] = match pre_states.try_into() {
Ok(array) => array,
Err(_) => return,
let Ok([pinata, winner]) = <[_; 2]>::try_from(pre_states) else {
return;
};
let data = Challenge::new(&pinata.account.data);
@@ -59,13 +59,15 @@ fn main() {
instruction_words,
) = read_nssa_inputs::<Instruction>();
let [
pinata_definition,
pinata_token_holding,
winner_token_holding,
] = match pre_states.try_into() {
Ok(array) => array,
Err(_) => return,
let Ok(
[
pinata_definition,
pinata_token_holding,
winner_token_holding,
],
) = <[_; 3]>::try_from(pre_states)
else {
return;
};
let data = Challenge::new(&pinata_definition.account.data);
@@ -113,7 +113,7 @@ impl ExecutionState {
);
execution_state.validate_and_sync_states(
chained_call.program_id,
authorized_pdas,
&authorized_pdas,
program_output.pre_states,
program_output.post_states,
);
@@ -153,7 +153,7 @@ impl ExecutionState {
fn validate_and_sync_states(
&mut self,
program_id: ProgramId,
authorized_pdas: HashSet<AccountId>,
authorized_pdas: &HashSet<AccountId>,
pre_states: Vec<AccountWithMetadata>,
post_states: Vec<AccountPostState>,
) {
@@ -173,12 +173,12 @@ impl ExecutionState {
.pre_states
.iter()
.find(|acc| acc.account_id == pre_account_id)
.map(|acc| acc.is_authorized)
.unwrap_or_else(|| {
panic!(
.map_or_else(
|| panic!(
"Pre state must exist in execution state for account {pre_account_id:?}",
)
});
),
|acc| acc.is_authorized
);
let is_authorized =
previous_is_authorized || authorized_pdas.contains(&pre_account_id);
@@ -379,18 +379,8 @@ fn compute_nullifier_and_set_digest(
npk: &NullifierPublicKey,
nsk: &NullifierSecretKey,
) -> (Nullifier, CommitmentSetDigest) {
membership_proof_opt
.as_ref()
.map(|membership_proof| {
// Compute commitment set digest associated with provided auth path
let commitment_pre = Commitment::new(npk, pre_account);
let set_digest = compute_digest_for_path(&commitment_pre, membership_proof);
// Compute update nullifier
let nullifier = Nullifier::for_account_update(&commitment_pre, nsk);
(nullifier, set_digest)
})
.unwrap_or_else(|| {
membership_proof_opt.as_ref().map_or_else(
|| {
assert_eq!(
*pre_account,
Account::default(),
@@ -400,5 +390,15 @@ fn compute_nullifier_and_set_digest(
// Compute initialization nullifier
let nullifier = Nullifier::for_account_initialization(npk);
(nullifier, DUMMY_COMMITMENT_HASH)
})
},
|membership_proof| {
// Compute commitment set digest associated with provided auth path
let commitment_pre = Commitment::new(npk, pre_account);
let set_digest = compute_digest_for_path(&commitment_pre, membership_proof);
// Compute update nullifier
let nullifier = Nullifier::for_account_update(&commitment_pre, nsk);
(nullifier, set_digest)
},
)
}