Skip to content

Commit

Permalink
Add a transaction and instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
garious committed Mar 6, 2019
1 parent 5979627 commit 97f2c96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions programs/vote_api/src/vote_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum VoteInstruction {
InitializeAccount,
/// `Delegate` or `Assign` a vote account to a particular node
DelegateStake(Pubkey),
/// Authorize a voter to send signed votes.
AuthorizeVoter(Pubkey),
Vote(Vote),
/// Clear the credits in the vote account
/// * Transaction::keys[0] - the "vote account"
Expand All @@ -40,6 +42,13 @@ impl VoteInstruction {
vec![(vote_id, true)],
)
}
pub fn new_authorize_voter(vote_id: Pubkey, authorized_voter_id: Pubkey) -> BuilderInstruction {
BuilderInstruction::new(
id(),
&VoteInstruction::AuthorizeVoter(authorized_voter_id),
vec![(vote_id, true)],
)
}
pub fn new_initialize_account(vote_id: Pubkey) -> BuilderInstruction {
BuilderInstruction::new(
id(),
Expand Down
15 changes: 15 additions & 0 deletions programs/vote_api/src/vote_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ impl VoteTransaction {
.sign(&[from_keypair, voter_keypair], recent_blockhash)
}

/// Choose a voter id to accept signed votes from
pub fn new_authorize_voter(
vote_keypair: &Keypair,
recent_blockhash: Hash,
authorized_voter_id: Pubkey,
fee: u64,
) -> Transaction {
TransactionBuilder::new(fee)
.push(VoteInstruction::new_authorize_voter(
vote_keypair.pubkey(),
authorized_voter_id,
))
.sign(&[vote_keypair], recent_blockhash)
}

/// Choose a node id to `delegate` or `assign` this vote account to
pub fn delegate_vote_account<T: KeypairUtil>(
vote_keypair: &T,
Expand Down

0 comments on commit 97f2c96

Please sign in to comment.