From 97f2c96a7ed50f6e36023a05aa2f05c8d456d3a8 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 6 Mar 2019 14:33:12 -0700 Subject: [PATCH] Add a transaction and instruction --- programs/vote_api/src/vote_instruction.rs | 9 +++++++++ programs/vote_api/src/vote_transaction.rs | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/programs/vote_api/src/vote_instruction.rs b/programs/vote_api/src/vote_instruction.rs index 28a2beebee..18d4cad7fa 100644 --- a/programs/vote_api/src/vote_instruction.rs +++ b/programs/vote_api/src/vote_instruction.rs @@ -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" @@ -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(), diff --git a/programs/vote_api/src/vote_transaction.rs b/programs/vote_api/src/vote_transaction.rs index cf90ce083e..e317124cbe 100644 --- a/programs/vote_api/src/vote_transaction.rs +++ b/programs/vote_api/src/vote_transaction.rs @@ -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( vote_keypair: &T,