use crate::pda::PDA;
use anchor_lang::prelude::*;
use std::convert::TryFrom;
pub const SEED_AUTHORITY: &[u8] = b"authority";
#[account]
#[derive(Debug)]
pub struct Authority {
pub bump: u8,
}
impl Authority {
pub fn pda() -> PDA {
Pubkey::find_program_address(&[SEED_AUTHORITY], &crate::ID)
}
}
impl TryFrom<Vec<u8>> for Authority {
type Error = Error;
fn try_from(data: Vec<u8>) -> std::result::Result<Self, Self::Error> {
Authority::try_deserialize(&mut data.as_slice())
}
}
pub trait AuthorityAccount {
fn init(&mut self, bump: u8) -> Result<()>;
}
impl AuthorityAccount for Account<'_, Authority> {
fn init(&mut self, bump: u8) -> Result<()> {
self.bump = bump;
Ok(())
}
}