Punt on the Script abstraction
Low ROI
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
pub mod vote_instruction;
|
||||
pub mod vote_processor;
|
||||
pub mod vote_script;
|
||||
pub mod vote_state;
|
||||
pub mod vote_transaction;
|
||||
|
||||
|
@@ -1,7 +1,10 @@
|
||||
use crate::id;
|
||||
use crate::vote_state::VoteState;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{AccountMeta, Instruction};
|
||||
|
||||
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Vote {
|
||||
@@ -32,6 +35,13 @@ pub enum VoteInstruction {
|
||||
}
|
||||
|
||||
impl VoteInstruction {
|
||||
pub fn new_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
||||
let space = VoteState::max_size() as u64;
|
||||
let create_ix =
|
||||
SystemInstruction::new_program_account(&from_id, staker_id, lamports, space, &id());
|
||||
let init_ix = VoteInstruction::new_initialize_account(staker_id);
|
||||
vec![create_ix, init_ix]
|
||||
}
|
||||
pub fn new_clear_credits(vote_id: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
||||
Instruction::new(id(), &VoteInstruction::ClearCredits, account_metas)
|
||||
|
@@ -46,7 +46,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::id;
|
||||
use crate::vote_instruction::{Vote, VoteInstruction};
|
||||
use crate::vote_script::VoteScript;
|
||||
use crate::vote_state::VoteState;
|
||||
use solana_runtime::bank::{Bank, Result};
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
@@ -69,8 +68,8 @@ mod tests {
|
||||
vote_id: &Pubkey,
|
||||
lamports: u64,
|
||||
) -> Result<()> {
|
||||
let script = VoteScript::new_account(&bank_client.pubkey(), vote_id, lamports);
|
||||
bank_client.process_script(script)
|
||||
let ixs = VoteInstruction::new_account(&bank_client.pubkey(), vote_id, lamports);
|
||||
bank_client.process_instructions(ixs)
|
||||
}
|
||||
|
||||
fn create_vote_account_with_delegate(
|
||||
@@ -79,10 +78,10 @@ mod tests {
|
||||
lamports: u64,
|
||||
) -> Result<()> {
|
||||
let vote_id = bank_client.pubkeys()[1];
|
||||
let mut script = VoteScript::new_account(&bank_client.pubkey(), &vote_id, lamports);
|
||||
let mut ixs = VoteInstruction::new_account(&bank_client.pubkey(), &vote_id, lamports);
|
||||
let delegate_ix = VoteInstruction::new_delegate_stake(&vote_id, delegate_id);
|
||||
script.push(delegate_ix);
|
||||
bank_client.process_script(script)
|
||||
ixs.push(delegate_ix);
|
||||
bank_client.process_instructions(ixs)
|
||||
}
|
||||
|
||||
fn submit_vote(
|
||||
|
@@ -1,21 +0,0 @@
|
||||
//! The `vote_script` module provides functionality for creating vote scripts.
|
||||
|
||||
use crate::id;
|
||||
use crate::vote_instruction::VoteInstruction;
|
||||
use crate::vote_state::VoteState;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::script::Script;
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
|
||||
pub struct VoteScript;
|
||||
|
||||
impl VoteScript {
|
||||
/// Fund or create the staking account with lamports
|
||||
pub fn new_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Script {
|
||||
let space = VoteState::max_size() as u64;
|
||||
let create_ix =
|
||||
SystemInstruction::new_program_account(&from_id, staker_id, lamports, space, &id());
|
||||
let init_ix = VoteInstruction::new_initialize_account(staker_id);
|
||||
Script::new(vec![create_ix, init_ix])
|
||||
}
|
||||
}
|
@@ -1,7 +1,6 @@
|
||||
//! The `vote_transaction` module provides functionality for creating vote transactions.
|
||||
|
||||
use crate::vote_instruction::{Vote, VoteInstruction};
|
||||
use crate::vote_script::VoteScript;
|
||||
use crate::vote_state::VoteState;
|
||||
use crate::{check_id, id};
|
||||
use bincode::deserialize;
|
||||
@@ -38,7 +37,8 @@ impl VoteTransaction {
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let from_id = from_keypair.pubkey();
|
||||
let mut tx = VoteScript::new_account(&from_id, staker_id, lamports).compile();
|
||||
let ixs = VoteInstruction::new_account(&from_id, staker_id, lamports);
|
||||
let mut tx = Transaction::new(ixs);
|
||||
tx.fee = fee;
|
||||
tx.sign(&[from_keypair], recent_blockhash);
|
||||
tx
|
||||
|
Reference in New Issue
Block a user