Add a transaction and instruction

This commit is contained in:
Greg Fitzgerald 2019-03-06 14:33:12 -07:00
parent 5979627258
commit 97f2c96a7e
2 changed files with 24 additions and 0 deletions

View File

@ -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(),

View File

@ -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,