Label tuple with AccountMeta
This commit is contained in:
@ -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::Instruction;
|
||||
use solana_sdk::transaction::{AccountMeta, Instruction};
|
||||
|
||||
/// A smart contract.
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
@ -31,9 +31,9 @@ impl BudgetInstruction {
|
||||
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(AccountMeta(payment.to, false));
|
||||
}
|
||||
keys.push((*contract, false));
|
||||
keys.push(AccountMeta(*contract, false));
|
||||
Instruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
|
||||
}
|
||||
|
||||
@ -43,17 +43,17 @@ impl BudgetInstruction {
|
||||
to: &Pubkey,
|
||||
dt: DateTime<Utc>,
|
||||
) -> Instruction {
|
||||
let mut keys = vec![(*from, true), (*contract, false)];
|
||||
let mut keys = vec![AccountMeta(*from, true), AccountMeta(*contract, false)];
|
||||
if from != to {
|
||||
keys.push((*to, false));
|
||||
keys.push(AccountMeta(*to, false));
|
||||
}
|
||||
Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys)
|
||||
}
|
||||
|
||||
pub fn new_apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction {
|
||||
let mut keys = vec![(*from, true), (*contract, false)];
|
||||
let mut keys = vec![AccountMeta(*from, true), AccountMeta(*contract, false)];
|
||||
if from != to {
|
||||
keys.push((*to, false));
|
||||
keys.push(AccountMeta(*to, false));
|
||||
}
|
||||
Instruction::new(id(), &BudgetInstruction::ApplySignature, keys)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use crate::id;
|
||||
use crate::ConfigState;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::Instruction;
|
||||
use solana_sdk::transaction::{AccountMeta, Instruction};
|
||||
|
||||
pub struct ConfigInstruction {}
|
||||
|
||||
@ -28,10 +28,10 @@ impl ConfigInstruction {
|
||||
config_account_pubkey: &Pubkey,
|
||||
data: &T,
|
||||
) -> Instruction {
|
||||
Instruction::new(
|
||||
id(),
|
||||
data,
|
||||
vec![(*from_account_pubkey, true), (*config_account_pubkey, true)],
|
||||
)
|
||||
let account_metas = vec![
|
||||
AccountMeta(*from_account_pubkey, true),
|
||||
AccountMeta(*config_account_pubkey, true),
|
||||
];
|
||||
Instruction::new(id(), data, account_metas)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::id;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::transaction::Instruction;
|
||||
use solana_sdk::transaction::{AccountMeta, Instruction};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub enum RewardsInstruction {
|
||||
@ -10,10 +10,7 @@ pub enum RewardsInstruction {
|
||||
|
||||
impl RewardsInstruction {
|
||||
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)],
|
||||
)
|
||||
let account_metas = vec![AccountMeta(*vote_id, true), AccountMeta(*rewards_id, false)];
|
||||
Instruction::new(id(), &RewardsInstruction::RedeemVoteCredits, account_metas)
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ use solana_sdk::hash::hash;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{Instruction, InstructionError, Transaction, TransactionError};
|
||||
use solana_sdk::transaction::{
|
||||
AccountMeta, Instruction, InstructionError, Transaction, TransactionError,
|
||||
};
|
||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
||||
use solana_vote_api::vote_state::VoteState;
|
||||
use solana_vote_api::vote_transaction::VoteTransaction;
|
||||
@ -112,7 +114,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||
let vote_ix = Instruction::new(
|
||||
solana_vote_api::id(),
|
||||
&VoteInstruction::Vote(Vote::new(0)),
|
||||
vec![(vote_id, false)], // <--- attack!! No signature.
|
||||
vec![AccountMeta(vote_id, false)], // <--- attack!! No signature.
|
||||
);
|
||||
|
||||
// Sneak in an instruction so that the transaction is signed but
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::id;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::transaction::Instruction;
|
||||
use solana_sdk::transaction::{AccountMeta, Instruction};
|
||||
|
||||
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Vote {
|
||||
@ -33,30 +33,31 @@ pub enum VoteInstruction {
|
||||
|
||||
impl VoteInstruction {
|
||||
pub fn new_clear_credits(vote_id: &Pubkey) -> Instruction {
|
||||
Instruction::new(id(), &VoteInstruction::ClearCredits, vec![(*vote_id, true)])
|
||||
let account_metas = vec![AccountMeta(*vote_id, true)];
|
||||
Instruction::new(id(), &VoteInstruction::ClearCredits, account_metas)
|
||||
}
|
||||
pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![AccountMeta(*vote_id, true)];
|
||||
Instruction::new(
|
||||
id(),
|
||||
&VoteInstruction::DelegateStake(*delegate_id),
|
||||
vec![(*vote_id, true)],
|
||||
account_metas,
|
||||
)
|
||||
}
|
||||
pub fn new_authorize_voter(vote_id: &Pubkey, authorized_voter_id: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![AccountMeta(*vote_id, true)];
|
||||
Instruction::new(
|
||||
id(),
|
||||
&VoteInstruction::AuthorizeVoter(*authorized_voter_id),
|
||||
vec![(*vote_id, true)],
|
||||
account_metas,
|
||||
)
|
||||
}
|
||||
pub fn new_initialize_account(vote_id: &Pubkey) -> Instruction {
|
||||
Instruction::new(
|
||||
id(),
|
||||
&VoteInstruction::InitializeAccount,
|
||||
vec![(*vote_id, false)],
|
||||
)
|
||||
let account_metas = vec![AccountMeta(*vote_id, false)];
|
||||
Instruction::new(id(), &VoteInstruction::InitializeAccount, account_metas)
|
||||
}
|
||||
pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> Instruction {
|
||||
Instruction::new(id(), &VoteInstruction::Vote(vote), vec![(*vote_id, true)])
|
||||
let account_metas = vec![AccountMeta(*vote_id, true)];
|
||||
Instruction::new(id(), &VoteInstruction::Vote(vote), account_metas)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user