solana/programs/config_api/src/config_instruction.rs

27 lines
786 B
Rust
Raw Normal View History

use crate::id;
use crate::ConfigState;
2019-03-23 20:12:27 -07:00
use solana_sdk::instruction::{AccountMeta, Instruction};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::system_instruction;
/// 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>(config_account_pubkey: &Pubkey, data: &T) -> Instruction {
let account_metas = vec![AccountMeta::new(*config_account_pubkey, true)];
Instruction::new(id(), data, account_metas)
}