2019-03-14 07:55:41 -07:00
|
|
|
use crate::id;
|
|
|
|
use crate::ConfigState;
|
|
|
|
use solana_sdk::pubkey::Pubkey;
|
|
|
|
use solana_sdk::system_instruction::SystemInstruction;
|
2019-03-19 13:03:20 -06:00
|
|
|
use solana_sdk::transaction::{AccountMeta, Instruction};
|
2019-03-14 07:55:41 -07:00
|
|
|
|
|
|
|
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_program_account(
|
|
|
|
from_account_pubkey,
|
|
|
|
config_account_pubkey,
|
|
|
|
lamports,
|
|
|
|
T::max_space(),
|
|
|
|
&id(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Store new data in a configuration account
|
2019-03-18 12:44:41 -07:00
|
|
|
pub fn new_store<T: ConfigState>(
|
|
|
|
from_account_pubkey: &Pubkey,
|
|
|
|
config_account_pubkey: &Pubkey,
|
|
|
|
data: &T,
|
|
|
|
) -> Instruction {
|
2019-03-19 13:03:20 -06:00
|
|
|
let account_metas = vec![
|
2019-03-19 15:25:48 -06:00
|
|
|
AccountMeta::new(*from_account_pubkey, true),
|
|
|
|
AccountMeta::new(*config_account_pubkey, true),
|
2019-03-19 13:03:20 -06:00
|
|
|
];
|
|
|
|
Instruction::new(id(), data, account_metas)
|
2019-03-14 07:55:41 -07:00
|
|
|
}
|
|
|
|
}
|