Add StorageInstruction constructors

This commit is contained in:
Greg Fitzgerald
2019-03-22 21:18:51 -06:00
committed by Grimes
parent 5a65c3f72e
commit dcf2337e58
2 changed files with 74 additions and 19 deletions

View File

@@ -1,7 +1,10 @@
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 {
@@ -22,3 +25,52 @@ pub enum StorageInstruction {
proof_mask: Vec<ProofStatus>,
},
}
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<ProofStatus>,
) -> 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)
}
}