use super::pubkey::Pubkey;
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
pub struct Instruction {
pub program_id: Pubkey,
pub accounts: Vec<AccountMeta>,
pub data: Vec<u8>,
}
#[derive(Debug, Clone, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
pub struct AccountMeta {
pub pubkey: Pubkey,
pub is_signer: bool,
pub is_writable: bool,
}
impl AccountMeta {
pub fn new_readonly(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: false,
is_writable: false,
}
}
pub fn new_signer(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: true,
is_writable: false,
}
}
pub fn new_writable(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: false,
is_writable: true,
}
}
pub fn new_signer_writable(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: true,
is_writable: true,
}
}
}
#[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
pub struct CompiledInstruction {
pub program_id_index: u8,
pub accounts: Vec<u8>,
pub data: Vec<u8>,
}