Skip to content

Commit

Permalink
chore(clippy): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joeymeere committed Jun 23, 2024
1 parent 07cb3fa commit e41b318
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 59 deletions.
9 changes: 2 additions & 7 deletions src/state/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ impl Participant {
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug, Default)]
pub enum AcceptanceStatus {
Accepted,
#[default]
Pending,
Denied,
}

impl Default for AcceptanceStatus {
fn default() -> Self {
AcceptanceStatus::Pending
}
}
37 changes: 11 additions & 26 deletions src/state/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ impl Pool {
bump: u8
) -> Result<Self, StockpileError> {
if name.as_bytes().len() > Self::MAX_NAME_LEN {
return Err(StockpileError::DefaultError.into());
return Err(StockpileError::DefaultError);
}

let current = Clock::get().unwrap();
let timestamp = current.unix_timestamp as u64;
if timestamp > start {
return Err(StockpileError::DefaultError.into());
return Err(StockpileError::DefaultError);
}

Ok(Self {
Expand All @@ -74,47 +74,37 @@ impl Pool {
let current = Clock::get().unwrap();
let timestamp = current.unix_timestamp as u64;
if timestamp > self.end {
return Err(StockpileError::DefaultError.into());
return Err(StockpileError::DefaultError);
}

if timestamp > self.start {
self.pool_state = PoolState::Active;
}

match self.pool_state {
PoolState::PendingStart => Err(StockpileError::DefaultError.into()),
PoolState::PendingStart => Err(StockpileError::DefaultError),
PoolState::Active => Ok(()),
PoolState::Distributed => Err(StockpileError::DefaultError.into()),
PoolState::Distributed => Err(StockpileError::DefaultError),
}
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, Default)]
pub enum PoolState {
#[default]
PendingStart,
Active,
Distributed,
}

impl Default for PoolState {
fn default() -> Self {
PoolState::PendingStart
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug, Default)]
pub enum PoolAccess {
Open,
#[default]
Manual,
TokenGated(TokenGateInfo),
}

impl Default for PoolAccess {
fn default() -> Self {
PoolAccess::Manual
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug)]
pub struct TokenGateInfo {
pub mint: Pubkey,
Expand All @@ -126,19 +116,14 @@ pub struct TokenGateInfo {
// 2. Civic - Runs a Civic Gateway check on the user & requires them to have a pass
// 3. Relayer - Requires signing by specified keys (usually via an API endpoint)
// 4. Custom - Add a serialized ix, and perform the check via your own on-chain program.
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, Default)]
pub enum SybilStrategy {
#[default]
None,
Relayer(Vec<Pubkey>),
Custom(CustomStrategy)
}

impl Default for SybilStrategy {
fn default() -> Self {
SybilStrategy::None
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, Debug)]
pub struct CustomStrategy {
pub program_id: Pubkey,
Expand Down
13 changes: 4 additions & 9 deletions src/state/pool_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,16 @@ impl PoolResult {
+ 4 // Enum (Singleton)
+ 1 // u8
+ 128; // Padding
return size

size
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, PartialEq, Debug, Default)]
pub enum ResultState {
#[default]
NotStarted, // Calculations have not begun yet
Pending, // Calculations are in progress, but not all participants & tables have been accounted
Confirmed, // Participant calculations are confirmed, final proportions are pending
Completed // All calculations completed
}

impl Default for ResultState {
fn default() -> Self {
ResultState::NotStarted
}
}
15 changes: 5 additions & 10 deletions src/state/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Vault {
bump: u8
) -> Result<Self, StockpileError> {
if name.as_bytes().len() > Self::MAX_NAME_LEN {
return Err(StockpileError::DefaultError.into());
return Err(StockpileError::DefaultError);
}

Ok(Self {
Expand All @@ -44,22 +44,17 @@ impl Vault {

pub fn is_active(&mut self) -> Result<(), StockpileError> {
match self.vault_state {
VaultState::Closed => Err(StockpileError::DefaultError.into()),
VaultState::Closed => Err(StockpileError::DefaultError),
VaultState::Active => Ok(()),
VaultState::Deactivated => Err(StockpileError::DefaultError.into()),
VaultState::Deactivated => Err(StockpileError::DefaultError),
}
}
}

#[derive(BorshDeserialize, BorshSerialize, Clone, Debug)]
#[derive(BorshDeserialize, BorshSerialize, Clone, Debug, Default)]
pub enum VaultState {
#[default]
Active,
Deactivated,
Closed,
}

impl Default for VaultState {
fn default() -> Self {
VaultState::Active
}
}
9 changes: 2 additions & 7 deletions src/state/vote_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,13 @@ impl VoteTable {
}
}

#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq)]
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq, Default)]
pub enum VoteStatus {
#[default]
Valid,
Invalid
}

impl Default for VoteStatus {
fn default() -> Self {
VoteStatus::Valid
}
}

#[derive(BorshDeserialize, BorshSerialize, Debug, Clone)]
pub struct VoteTicket {
pub voter: Pubkey,
Expand Down

0 comments on commit e41b318

Please sign in to comment.