miclockwork_network_program/state/
unstake.rs

1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3pub const SEED_UNSTAKE: &[u8] = b"unstake";
4
5/// Unstake
6#[account]
7#[derive(Debug)]
8pub struct Unstake {
9    pub amount: u64,
10    pub authority: Pubkey,
11    pub delegation: Pubkey,
12    pub id: u64,
13    pub worker: Pubkey,
14}
15
16impl Unstake {
17    pub fn pubkey(id: u64) -> Pubkey {
18        Pubkey::find_program_address(&[SEED_UNSTAKE, id.to_be_bytes().as_ref()], &crate::ID).0
19    }
20}
21
22/// UnstakeAccount
23pub trait UnstakeAccount {
24    fn pubkey(&self) -> Pubkey;
25
26    fn init(
27        &mut self,
28        amount: u64,
29        authority: Pubkey,
30        delegation: Pubkey,
31        id: u64,
32        worker: Pubkey,
33    ) -> Result<()>;
34}
35
36impl UnstakeAccount for Account<'_, Unstake> {
37    fn pubkey(&self) -> Pubkey {
38        Unstake::pubkey(self.id)
39    }
40
41    fn init(
42        &mut self,
43        amount: u64,
44        authority: Pubkey,
45        delegation: Pubkey,
46        id: u64,
47        worker: Pubkey,
48    ) -> Result<()> {
49        self.amount = amount;
50        self.authority = authority.key();
51        self.delegation = delegation;
52        self.id = id;
53        self.worker = worker;
54        Ok(())
55    }
56}