Remove Instruction wrapper structs and name functions after enum fields

This commit is contained in:
Greg Fitzgerald
2019-04-03 09:45:57 -06:00
committed by Grimes
parent 867f6f107b
commit 35298e01a8
53 changed files with 835 additions and 922 deletions

View File

@@ -2,36 +2,32 @@ use crate::id;
use crate::ConfigState;
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::system_instruction::SystemInstruction;
use solana_sdk::system_instruction;
pub struct ConfigInstruction {}
impl ConfigInstruction {
/// Create a new, empty configuration account
pub fn new_account<T: ConfigState>(
from_account_pubkey: &Pubkey,
config_account_pubkey: &Pubkey,
lamports: u64,
) -> Instruction {
SystemInstruction::new_account(
from_account_pubkey,
config_account_pubkey,
lamports,
T::max_space(),
&id(),
)
}
/// Store new data in a configuration account
pub fn new_store<T: ConfigState>(
from_account_pubkey: &Pubkey,
config_account_pubkey: &Pubkey,
data: &T,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_account_pubkey, true),
AccountMeta::new(*config_account_pubkey, true),
];
Instruction::new(id(), data, account_metas)
}
/// Create a new, empty configuration account
pub fn create_account<T: ConfigState>(
from_account_pubkey: &Pubkey,
config_account_pubkey: &Pubkey,
lamports: u64,
) -> Instruction {
system_instruction::create_account(
from_account_pubkey,
config_account_pubkey,
lamports,
T::max_space(),
&id(),
)
}
/// Store new data in a configuration account
pub fn store<T: ConfigState>(
from_account_pubkey: &Pubkey,
config_account_pubkey: &Pubkey,
data: &T,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_account_pubkey, true),
AccountMeta::new(*config_account_pubkey, true),
];
Instruction::new(id(), data, account_metas)
}