From d164241c40bd92e39c3701cc163d5ef110c3b49d Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Sun, 25 Aug 2024 11:58:08 +0000 Subject: [PATCH] remove lifetimes --- api/src/loaders.rs | 39 ++++++++++----------------------------- program/src/claim.rs | 2 +- program/src/close.rs | 2 +- program/src/initialize.rs | 5 +---- program/src/mine.rs | 2 +- program/src/open.rs | 2 +- program/src/reset.rs | 2 +- program/src/stake.rs | 2 +- program/src/update.rs | 5 +---- program/src/upgrade.rs | 5 +---- utils/src/loaders.rs | 38 +++++++++++++------------------------- 11 files changed, 32 insertions(+), 72 deletions(-) diff --git a/api/src/loaders.rs b/api/src/loaders.rs index 1c2428b..c7f4cd0 100644 --- a/api/src/loaders.rs +++ b/api/src/loaders.rs @@ -13,11 +13,7 @@ use crate::{ /// - Data cannot deserialize into a bus account. /// - Bus ID does not match the expected ID. /// - Expected to be writable, but is not. -pub fn load_bus<'a, 'info>( - info: &'a AccountInfo<'info>, - id: u64, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_bus(info: &AccountInfo<'_>, id: u64, is_writable: bool) -> Result<(), ProgramError> { if info.owner.ne(&crate::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -51,10 +47,7 @@ pub fn load_bus<'a, 'info>( /// - Bus ID is not in the expected range. /// - Address is not in set of valid bus address. /// - Expected to be writable, but is not. -pub fn load_any_bus<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_any_bus(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if info.owner.ne(&crate::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -84,10 +77,7 @@ pub fn load_any_bus<'a, 'info>( /// - Data is empty. /// - Data cannot deserialize into a config account. /// - Expected to be writable, but is not. -pub fn load_config<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_config(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if info.owner.ne(&crate::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -117,8 +107,8 @@ pub fn load_config<'a, 'info>( /// - Data cannot deserialize into a proof account. /// - Proof authority does not match the expected address. /// - Expected to be writable, but is not. -pub fn load_proof<'a, 'info>( - info: &'a AccountInfo<'info>, +pub fn load_proof( + info: &AccountInfo<'_>, authority: &Pubkey, is_writable: bool, ) -> Result<(), ProgramError> { @@ -150,8 +140,8 @@ pub fn load_proof<'a, 'info>( /// - Data cannot deserialize into a proof account. /// - Proof miner does not match the expected address. /// - Expected to be writable, but is not. -pub fn load_proof_with_miner<'a, 'info>( - info: &'a AccountInfo<'info>, +pub fn load_proof_with_miner( + info: &AccountInfo<'_>, miner: &Pubkey, is_writable: bool, ) -> Result<(), ProgramError> { @@ -182,10 +172,7 @@ pub fn load_proof_with_miner<'a, 'info>( /// - Data is empty. /// - Data cannot deserialize into a proof account. /// - Expected to be writable, but is not. -pub fn load_any_proof<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_any_proof(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if info.owner.ne(&crate::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -211,10 +198,7 @@ pub fn load_any_proof<'a, 'info>( /// - Data is empty. /// - Data cannot deserialize into a treasury account. /// - Expected to be writable, but is not. -pub fn load_treasury<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_treasury(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if info.owner.ne(&crate::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -241,10 +225,7 @@ pub fn load_treasury<'a, 'info>( /// Errors if: /// - Address does not match the expected treasury tokens address. /// - Cannot load as a token account -pub fn load_treasury_tokens<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_treasury_tokens(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if info.key.ne(&TREASURY_TOKENS_ADDRESS) { return Err(ProgramError::InvalidSeeds); } diff --git a/program/src/claim.rs b/program/src/claim.rs index 970894d..dde7e25 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -7,7 +7,7 @@ use solana_program::{ use ore_utils::{loaders::*, AccountDeserialize}; /// Claim distributes claimable ORE from the treasury to a miner. -pub fn process_claim<'a, 'info>(accounts: &'a [AccountInfo<'info>], data: &[u8]) -> ProgramResult { +pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args. let args = ClaimArgs::try_from_bytes(data)?; let amount = u64::from_le_bytes(args.amount); diff --git a/program/src/close.rs b/program/src/close.rs index 9c41fdb..bd572c9 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -7,7 +7,7 @@ use solana_program::{ use ore_utils::{loaders::*, AccountDeserialize}; /// Close closes a proof account and returns the rent to the owner. -pub fn process_close<'a, 'info>(accounts: &'a [AccountInfo<'info>], _data: &[u8]) -> ProgramResult { +pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. let [signer, proof_info, system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 245c9a8..bc116fb 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -16,10 +16,7 @@ use solana_program::{ use spl_token::state::Mint; /// Initialize sets up the ORE program to begin mining. -pub fn process_initialize<'a, 'info>( - accounts: &'a [AccountInfo<'info>], - data: &[u8], -) -> ProgramResult { +pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args. let args = InitializeArgs::try_from_bytes(data)?; diff --git a/program/src/mine.rs b/program/src/mine.rs index 4e35a62..b088e51 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -27,7 +27,7 @@ use solana_program::{ use ore_utils::{loaders::*, AccountDeserialize}; /// Mine validates hashes and increments a miner's collectable balance. -pub fn process_mine<'a, 'info>(accounts: &'a [AccountInfo<'info>], data: &[u8]) -> ProgramResult { +pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args. let args = MineArgs::try_from_bytes(data)?; diff --git a/program/src/open.rs b/program/src/open.rs index 21a0a9d..248012e 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -15,7 +15,7 @@ use solana_program::{ use ore_utils::{create_pda, loaders::*, AccountDeserialize, Discriminator}; /// Open creates a new proof account to track a miner's state. -pub fn process_open<'a, 'info>(accounts: &'a [AccountInfo<'info>], data: &[u8]) -> ProgramResult { +pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args. let args = OpenArgs::try_from_bytes(data)?; diff --git a/program/src/reset.rs b/program/src/reset.rs index 6c16a25..60451f9 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -13,7 +13,7 @@ use spl_token::state::Mint; use ore_utils::{loaders::*, AccountDeserialize}; /// Reset tops up the bus balances, updates the base reward rate, and sets up the ORE program for the next epoch. -pub fn process_reset<'a, 'info>(accounts: &'a [AccountInfo<'info>], _data: &[u8]) -> ProgramResult { +pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. let [signer, bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_7_info, config_info, mint_info, treasury_info, treasury_tokens_info, token_program] = accounts diff --git a/program/src/stake.rs b/program/src/stake.rs index dfc2f3c..12ac357 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -6,7 +6,7 @@ use solana_program::{ }; /// Stake deposits ORE into a proof account to earn multiplier. -pub fn process_stake<'a, 'info>(accounts: &'a [AccountInfo<'info>], data: &[u8]) -> ProgramResult { +pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args. let args = StakeArgs::try_from_bytes(data)?; let amount = u64::from_le_bytes(args.amount); diff --git a/program/src/update.rs b/program/src/update.rs index ca0d9bd..cc7fca4 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -5,10 +5,7 @@ use solana_program::{ }; /// Update changes the miner authority on a proof account. -pub fn process_update<'a, 'info>( - accounts: &'a [AccountInfo<'info>], - _data: &[u8], -) -> ProgramResult { +pub fn process_update(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. let [signer, miner_info, proof_info] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 9ca4f0b..c28eace 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -7,10 +7,7 @@ use solana_program::{ use spl_token::state::Mint; /// Upgrade allows a user to migrate a v1 token to a v2 token at a 1:1 exchange rate. -pub fn process_upgrade<'a, 'info>( - accounts: &'a [AccountInfo<'info>], - data: &[u8], -) -> ProgramResult { +pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args let args = StakeArgs::try_from_bytes(data)?; let amount = u64::from_le_bytes(args.amount); diff --git a/utils/src/loaders.rs b/utils/src/loaders.rs index 8bc38d3..365218f 100644 --- a/utils/src/loaders.rs +++ b/utils/src/loaders.rs @@ -8,7 +8,7 @@ use spl_token::state::Mint; /// Errors if: /// - Account is not a signer. -pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> { +pub fn load_signer(info: &AccountInfo<'_>) -> Result<(), ProgramError> { if !info.is_signer { return Err(ProgramError::MissingRequiredSignature); } @@ -19,8 +19,8 @@ pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), Progra /// Errors if: /// - Address does not match PDA derived from provided seeds. /// - Cannot load as an uninitialized account. -pub fn load_uninitialized_pda<'a, 'info>( - info: &'a AccountInfo<'info>, +pub fn load_uninitialized_pda( + info: &AccountInfo<'_>, seeds: &[&[u8]], bump: u8, program_id: &Pubkey, @@ -42,10 +42,7 @@ pub fn load_uninitialized_pda<'a, 'info>( /// - Owner is not the system program. /// - Data is not empty. /// - Account is not writable. -pub fn load_system_account<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_system_account(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if info.owner.ne(&system_program::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -64,10 +61,7 @@ pub fn load_system_account<'a, 'info>( /// Errors if: /// - Owner is not the sysvar address. /// - Account cannot load with the expected address. -pub fn load_sysvar<'a, 'info>( - info: &'a AccountInfo<'info>, - key: Pubkey, -) -> Result<(), ProgramError> { +pub fn load_sysvar(info: &AccountInfo<'_>, key: Pubkey) -> Result<(), ProgramError> { if info.owner.ne(&sysvar::id()) { return Err(ProgramError::InvalidAccountOwner); } @@ -78,8 +72,8 @@ pub fn load_sysvar<'a, 'info>( /// Errors if: /// - Address does not match the expected value. /// - Expected to be writable, but is not. -pub fn load_account<'a, 'info>( - info: &'a AccountInfo<'info>, +pub fn load_account( + info: &AccountInfo<'_>, key: Pubkey, is_writable: bool, ) -> Result<(), ProgramError> { @@ -97,10 +91,7 @@ pub fn load_account<'a, 'info>( /// Errors if: /// - Address does not match the expected value. /// - Account is not executable. -pub fn load_program<'a, 'info>( - info: &'a AccountInfo<'info>, - key: Pubkey, -) -> Result<(), ProgramError> { +pub fn load_program(info: &AccountInfo<'_>, key: Pubkey) -> Result<(), ProgramError> { if info.key.ne(&key) { return Err(ProgramError::IncorrectProgramId); } @@ -114,10 +105,7 @@ pub fn load_program<'a, 'info>( /// Errors if: /// - Account is not writable. -pub fn load_any<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { +pub fn load_any(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { if is_writable && !info.is_writable { return Err(ProgramError::InvalidAccountData); } @@ -132,8 +120,8 @@ pub fn load_any<'a, 'info>( /// - Data cannot deserialize into a mint account. /// - Expected to be writable, but is not. #[cfg(feature = "spl")] -pub fn load_mint<'a, 'info>( - info: &'a AccountInfo<'info>, +pub fn load_mint( + info: &AccountInfo<'_>, address: Pubkey, is_writable: bool, ) -> Result<(), ProgramError> { @@ -166,8 +154,8 @@ pub fn load_mint<'a, 'info>( /// - Token account mint does not match the expected mint address. /// - Expected to be writable, but is not. #[cfg(feature = "spl")] -pub fn load_token_account<'a, 'info>( - info: &'a AccountInfo<'info>, +pub fn load_token_account( + info: &AccountInfo<'_>, owner: Option<&Pubkey>, mint: &Pubkey, is_writable: bool,