-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11078f1
commit 3c621c2
Showing
2 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
//! Vote program instructions. | ||
use { | ||
crate::state::{ | ||
tower_sync::{serde_tower_sync, TowerSync}, | ||
vote::Vote, | ||
vote_state_update::{serde_compact_vote_state_update, VoteStateUpdate}, | ||
}, | ||
serde::{Deserialize, Serialize}, | ||
solana_program::{hash::Hash, pubkey::Pubkey}, | ||
}; | ||
|
||
#[derive(Default, Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)] | ||
pub struct VoteInit { | ||
pub node_pubkey: Pubkey, | ||
pub authorized_voter: Pubkey, | ||
pub authorized_withdrawer: Pubkey, | ||
pub commission: u8, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)] | ||
pub enum VoteAuthorize { | ||
Voter, | ||
Withdrawer, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] | ||
pub struct VoteAuthorizeWithSeedArgs { | ||
pub authorization_type: VoteAuthorize, | ||
pub current_authority_derived_key_owner: Pubkey, | ||
pub current_authority_derived_key_seed: String, | ||
pub new_authority: Pubkey, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] | ||
pub struct VoteAuthorizeCheckedWithSeedArgs { | ||
pub authorization_type: VoteAuthorize, | ||
pub current_authority_derived_key_owner: Pubkey, | ||
pub current_authority_derived_key_seed: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] | ||
pub enum VoteInstruction { | ||
/// Initialize a vote account | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Uninitialized vote account | ||
/// 1. `[]` Rent sysvar | ||
/// 2. `[]` Clock sysvar | ||
/// 3. `[SIGNER]` New validator identity (node_pubkey) | ||
InitializeAccount(VoteInit), | ||
|
||
/// Authorize a key to send votes or issue a withdrawal | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to be updated with the Pubkey for | ||
/// authorization | ||
/// 1. `[]` Clock sysvar | ||
/// 2. `[SIGNER]` Vote or withdraw authority | ||
Authorize(Pubkey, VoteAuthorize), | ||
|
||
/// A Vote instruction with recent votes | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to vote with | ||
/// 1. `[]` Slot hashes sysvar | ||
/// 2. `[]` Clock sysvar | ||
/// 3. `[SIGNER]` Vote authority | ||
Vote(Vote), | ||
|
||
/// Withdraw some amount of funds | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to withdraw from | ||
/// 1. `[WRITE]` Recipient account | ||
/// 2. `[SIGNER]` Withdraw authority | ||
Withdraw(u64), | ||
|
||
/// Update the vote account's validator identity (node_pubkey) | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to be updated with the given authority | ||
/// public key | ||
/// 1. `[SIGNER]` New validator identity (node_pubkey) | ||
/// 2. `[SIGNER]` Withdraw authority | ||
UpdateValidatorIdentity, | ||
|
||
/// Update the commission for the vote account | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to be updated | ||
/// 1. `[SIGNER]` Withdraw authority | ||
UpdateCommission(u8), | ||
|
||
/// A Vote instruction with recent votes | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to vote with | ||
/// 1. `[]` Slot hashes sysvar | ||
/// 2. `[]` Clock sysvar | ||
/// 3. `[SIGNER]` Vote authority | ||
VoteSwitch(Vote, Hash), | ||
|
||
/// Authorize a key to send votes or issue a withdrawal | ||
/// | ||
/// This instruction behaves like `Authorize` with the additional | ||
/// requirement that the new vote or withdraw authority must also be a | ||
/// signer. | ||
/// | ||
/// # Account references | ||
/// 0. `[WRITE]` Vote account to be updated with the Pubkey for | ||
/// authorization | ||
/// 1. `[]` Clock sysvar | ||
/// 2. `[SIGNER]` Vote or withdraw authority | ||
/// 3. `[SIGNER]` New vote or withdraw authority | ||
AuthorizeChecked(VoteAuthorize), | ||
|
||
/// Update the onchain vote state for the signer. | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to vote with | ||
/// 1. `[SIGNER]` Vote authority | ||
UpdateVoteState(VoteStateUpdate), | ||
|
||
/// Update the onchain vote state for the signer along with a switching | ||
/// proof. | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to vote with | ||
/// 1. `[SIGNER]` Vote authority | ||
UpdateVoteStateSwitch(VoteStateUpdate, Hash), | ||
|
||
/// Given that the current Voter or Withdrawer authority is a derived key, | ||
/// this instruction allows someone who can sign for that derived key's | ||
/// base key to authorize a new Voter or Withdrawer for a vote account. | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to be updated | ||
/// 1. `[]` Clock sysvar | ||
/// 2. `[SIGNER]` Base key of current Voter or Withdrawer authority's | ||
/// derived key | ||
AuthorizeWithSeed(VoteAuthorizeWithSeedArgs), | ||
|
||
/// Given that the current Voter or Withdrawer authority is a derived key, | ||
/// this instruction allows someone who can sign for that derived key's | ||
/// base key to authorize a new Voter or Withdrawer for a vote account. | ||
/// | ||
/// This instruction behaves like `AuthorizeWithSeed` with the additional | ||
/// requirement that the new vote or withdraw authority must also be a | ||
/// signer. | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to be updated | ||
/// 1. `[]` Clock sysvar | ||
/// 2. `[SIGNER]` Base key of current Voter or Withdrawer authority's | ||
/// derived key | ||
/// 3. `[SIGNER]` New vote or withdraw authority | ||
AuthorizeCheckedWithSeed(VoteAuthorizeCheckedWithSeedArgs), | ||
|
||
/// Update the onchain vote state for the signer. | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to vote with | ||
/// 1. `[SIGNER]` Vote authority | ||
#[serde(with = "serde_compact_vote_state_update")] | ||
CompactUpdateVoteState(VoteStateUpdate), | ||
|
||
/// Update the onchain vote state for the signer along with a switching | ||
/// proof. | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to vote with | ||
/// 1. `[SIGNER]` Vote authority | ||
CompactUpdateVoteStateSwitch( | ||
#[serde(with = "serde_compact_vote_state_update")] VoteStateUpdate, | ||
Hash, | ||
), | ||
|
||
/// Sync the onchain vote state with local tower | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to vote with | ||
/// 1. `[SIGNER]` Vote authority | ||
#[serde(with = "serde_tower_sync")] | ||
TowerSync(TowerSync), | ||
|
||
/// Sync the onchain vote state with local tower along with a switching | ||
/// proof | ||
/// | ||
/// # Account references | ||
/// 0. `[Write]` Vote account to vote with | ||
/// 1. `[SIGNER]` Vote authority | ||
TowerSyncSwitch(#[serde(with = "serde_tower_sync")] TowerSync, Hash), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters