use crate::id; use crate::storage_contract::ProofStatus; use serde_derive::{Deserialize, Serialize}; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::Signature; use solana_sdk::transaction::{AccountMeta, Instruction}; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum StorageInstruction { SubmitMiningProof { sha_state: Hash, entry_height: u64, signature: Signature, }, AdvertiseStorageRecentBlockhash { hash: Hash, entry_height: u64, }, ClaimStorageReward { entry_height: u64, }, ProofValidation { entry_height: u64, proof_mask: Vec, }, } impl StorageInstruction { pub fn new_mining_proof( from_pubkey: &Pubkey, sha_state: Hash, entry_height: u64, signature: Signature, ) -> Instruction { let storage_instruction = StorageInstruction::SubmitMiningProof { sha_state, entry_height, signature, }; let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; Instruction::new(id(), &storage_instruction, account_metas) } pub fn new_advertise_recent_blockhash( from_pubkey: &Pubkey, storage_hash: Hash, entry_height: u64, ) -> Instruction { let storage_instruction = StorageInstruction::AdvertiseStorageRecentBlockhash { hash: storage_hash, entry_height, }; let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; Instruction::new(id(), &storage_instruction, account_metas) } pub fn new_proof_validation( from_pubkey: &Pubkey, entry_height: u64, proof_mask: Vec, ) -> Instruction { let storage_instruction = StorageInstruction::ProofValidation { entry_height, proof_mask, }; let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; Instruction::new(id(), &storage_instruction, account_metas) } pub fn new_reward_claim(from_pubkey: &Pubkey, entry_height: u64) -> Instruction { let storage_instruction = StorageInstruction::ClaimStorageReward { entry_height }; let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; Instruction::new(id(), &storage_instruction, account_metas) } }