Config program - useful for storing/updating simple config items on chain
This commit is contained in:
29
programs/config_api/src/config_instruction.rs
Normal file
29
programs/config_api/src/config_instruction.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::id;
|
||||
use crate::ConfigState;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::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_program_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>(config_account_pubkey: &Pubkey, data: &T) -> Instruction {
|
||||
Instruction::new(id(), data, vec![(*config_account_pubkey, true)])
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user