Instruction name swap

* Instruction -> GenericInstruction
* Instruction<u8, u8> -> CompiledInstruction
* Instruction<Pubkey, (Pubkey, bool)> -> Instruction
This commit is contained in:
Greg Fitzgerald
2019-03-15 09:47:25 -06:00
parent 66fb1bbb2e
commit 968022a1b0
13 changed files with 97 additions and 94 deletions

View File

@ -3,7 +3,7 @@ use crate::id;
use chrono::prelude::{DateTime, Utc};
use serde_derive::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::transaction_builder::BuilderInstruction;
use solana_sdk::transaction::Instruction;
/// A smart contract.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
@ -28,13 +28,13 @@ pub enum BudgetInstruction {
}
impl BudgetInstruction {
pub fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> BuilderInstruction {
pub fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> Instruction {
let mut keys = vec![];
if let BudgetExpr::Pay(payment) = &expr {
keys.push((payment.to, false));
}
keys.push((*contract, false));
BuilderInstruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
Instruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
}
pub fn new_apply_timestamp(
@ -42,23 +42,19 @@ impl BudgetInstruction {
contract: &Pubkey,
to: &Pubkey,
dt: DateTime<Utc>,
) -> BuilderInstruction {
) -> Instruction {
let mut keys = vec![(*from, true), (*contract, false)];
if from != to {
keys.push((*to, false));
}
BuilderInstruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys)
Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys)
}
pub fn new_apply_signature(
from: &Pubkey,
contract: &Pubkey,
to: &Pubkey,
) -> BuilderInstruction {
pub fn new_apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction {
let mut keys = vec![(*from, true), (*contract, false)];
if from != to {
keys.push((*to, false));
}
BuilderInstruction::new(id(), &BudgetInstruction::ApplySignature, keys)
Instruction::new(id(), &BudgetInstruction::ApplySignature, keys)
}
}

View File

@ -1,7 +1,7 @@
use crate::id;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::transaction_builder::BuilderInstruction;
use solana_sdk::transaction::Instruction;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub enum RewardsInstruction {
@ -9,8 +9,8 @@ pub enum RewardsInstruction {
}
impl RewardsInstruction {
pub fn new_redeem_vote_credits(vote_id: &Pubkey, rewards_id: &Pubkey) -> BuilderInstruction {
BuilderInstruction::new(
pub fn new_redeem_vote_credits(vote_id: &Pubkey, rewards_id: &Pubkey) -> Instruction {
Instruction::new(
id(),
&RewardsInstruction::RedeemVoteCredits,
vec![(*vote_id, true), (*rewards_id, false)],

View File

@ -180,7 +180,7 @@ mod test {
use solana_sdk::account::{create_keyed_accounts, Account};
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::transaction::{Instruction, Transaction};
use solana_sdk::transaction::{CompiledInstruction, Transaction};
use solana_storage_api::{ProofStatus, StorageTransaction};
fn test_transaction(
@ -188,7 +188,7 @@ mod test {
program_accounts: &mut [Account],
) -> Result<(), ProgramError> {
assert_eq!(tx.instructions.len(), 1);
let Instruction {
let CompiledInstruction {
ref accounts,
ref data,
..

View File

@ -5,8 +5,8 @@ use solana_sdk::native_program::ProgramError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_instruction::SystemInstruction;
use solana_sdk::transaction::{InstructionError, TransactionError};
use solana_sdk::transaction_builder::{BuilderInstruction, TransactionBuilder};
use solana_sdk::transaction::{Instruction, InstructionError, TransactionError};
use solana_sdk::transaction_builder::TransactionBuilder;
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
use solana_vote_api::vote_state::VoteState;
use solana_vote_api::vote_transaction::VoteTransaction;
@ -111,7 +111,7 @@ fn test_vote_via_bank_with_no_signature() {
let mallory_id = mallory_keypair.pubkey();
let blockhash = bank.last_blockhash();
let vote_ix = BuilderInstruction::new(
let vote_ix = Instruction::new(
solana_vote_api::id(),
&VoteInstruction::Vote(Vote::new(0)),
vec![(vote_id, false)], // <--- attack!! No signature.

View File

@ -1,7 +1,7 @@
use crate::id;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::transaction_builder::BuilderInstruction;
use solana_sdk::transaction::Instruction;
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Vote {
@ -32,34 +32,31 @@ pub enum VoteInstruction {
}
impl VoteInstruction {
pub fn new_clear_credits(vote_id: &Pubkey) -> BuilderInstruction {
BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(*vote_id, true)])
pub fn new_clear_credits(vote_id: &Pubkey) -> Instruction {
Instruction::new(id(), &VoteInstruction::ClearCredits, vec![(*vote_id, true)])
}
pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> BuilderInstruction {
BuilderInstruction::new(
pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> Instruction {
Instruction::new(
id(),
&VoteInstruction::DelegateStake(*delegate_id),
vec![(*vote_id, true)],
)
}
pub fn new_authorize_voter(
vote_id: &Pubkey,
authorized_voter_id: &Pubkey,
) -> BuilderInstruction {
BuilderInstruction::new(
pub fn new_authorize_voter(vote_id: &Pubkey, authorized_voter_id: &Pubkey) -> Instruction {
Instruction::new(
id(),
&VoteInstruction::AuthorizeVoter(*authorized_voter_id),
vec![(*vote_id, true)],
)
}
pub fn new_initialize_account(vote_id: &Pubkey) -> BuilderInstruction {
BuilderInstruction::new(
pub fn new_initialize_account(vote_id: &Pubkey) -> Instruction {
Instruction::new(
id(),
&VoteInstruction::InitializeAccount,
vec![(*vote_id, false)],
)
}
pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> BuilderInstruction {
BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(*vote_id, true)])
pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> Instruction {
Instruction::new(id(), &VoteInstruction::Vote(vote), vec![(*vote_id, true)])
}
}