2019-03-22 21:18:51 -06:00
|
|
|
use crate::id;
|
2019-04-03 15:51:05 -07:00
|
|
|
use crate::storage_contract::CheckedProof;
|
2019-03-22 14:30:18 -06:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
|
|
|
use solana_sdk::hash::Hash;
|
2019-03-22 22:02:00 -06:00
|
|
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
2019-03-22 21:18:51 -06:00
|
|
|
use solana_sdk::pubkey::Pubkey;
|
2019-03-22 14:30:18 -06:00
|
|
|
use solana_sdk::signature::Signature;
|
|
|
|
|
2019-04-02 13:08:55 -07:00
|
|
|
// TODO maybe split this into StorageReplicator and StorageValidator
|
2019-03-22 14:30:18 -06:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
|
|
pub enum StorageInstruction {
|
|
|
|
SubmitMiningProof {
|
|
|
|
sha_state: Hash,
|
2019-05-03 16:27:53 -07:00
|
|
|
slot: u64,
|
2019-03-22 14:30:18 -06:00
|
|
|
signature: Signature,
|
|
|
|
},
|
|
|
|
AdvertiseStorageRecentBlockhash {
|
|
|
|
hash: Hash,
|
2019-05-03 16:27:53 -07:00
|
|
|
slot: u64,
|
2019-03-22 14:30:18 -06:00
|
|
|
},
|
|
|
|
ClaimStorageReward {
|
2019-05-03 16:27:53 -07:00
|
|
|
slot: u64,
|
2019-03-22 14:30:18 -06:00
|
|
|
},
|
|
|
|
ProofValidation {
|
2019-05-03 16:27:53 -07:00
|
|
|
slot: u64,
|
2019-04-03 15:51:05 -07:00
|
|
|
proofs: Vec<CheckedProof>,
|
2019-03-22 14:30:18 -06:00
|
|
|
},
|
|
|
|
}
|
2019-03-22 21:18:51 -06:00
|
|
|
|
2019-04-03 09:45:57 -06:00
|
|
|
pub fn mining_proof(
|
|
|
|
from_pubkey: &Pubkey,
|
|
|
|
sha_state: Hash,
|
2019-05-03 16:27:53 -07:00
|
|
|
slot: u64,
|
2019-04-03 09:45:57 -06:00
|
|
|
signature: Signature,
|
|
|
|
) -> Instruction {
|
|
|
|
let storage_instruction = StorageInstruction::SubmitMiningProof {
|
|
|
|
sha_state,
|
2019-05-03 16:27:53 -07:00
|
|
|
slot,
|
2019-04-03 09:45:57 -06:00
|
|
|
signature,
|
|
|
|
};
|
|
|
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
|
|
|
Instruction::new(id(), &storage_instruction, account_metas)
|
|
|
|
}
|
2019-03-22 21:18:51 -06:00
|
|
|
|
2019-04-03 09:45:57 -06:00
|
|
|
pub fn advertise_recent_blockhash(
|
|
|
|
from_pubkey: &Pubkey,
|
|
|
|
storage_hash: Hash,
|
2019-05-03 16:27:53 -07:00
|
|
|
slot: u64,
|
2019-04-03 09:45:57 -06:00
|
|
|
) -> Instruction {
|
|
|
|
let storage_instruction = StorageInstruction::AdvertiseStorageRecentBlockhash {
|
|
|
|
hash: storage_hash,
|
2019-05-03 16:27:53 -07:00
|
|
|
slot,
|
2019-04-03 09:45:57 -06:00
|
|
|
};
|
|
|
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
|
|
|
Instruction::new(id(), &storage_instruction, account_metas)
|
|
|
|
}
|
2019-03-22 21:18:51 -06:00
|
|
|
|
2019-05-03 16:27:53 -07:00
|
|
|
pub fn proof_validation(from_pubkey: &Pubkey, slot: u64, proofs: Vec<CheckedProof>) -> Instruction {
|
2019-04-02 13:08:55 -07:00
|
|
|
let mut account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
2019-04-03 15:51:05 -07:00
|
|
|
proofs.iter().for_each(|checked_proof| {
|
|
|
|
account_metas.push(AccountMeta::new(checked_proof.proof.id, false))
|
|
|
|
});
|
2019-05-03 16:27:53 -07:00
|
|
|
let storage_instruction = StorageInstruction::ProofValidation { slot, proofs };
|
2019-04-03 09:45:57 -06:00
|
|
|
Instruction::new(id(), &storage_instruction, account_metas)
|
|
|
|
}
|
2019-03-22 21:18:51 -06:00
|
|
|
|
2019-05-03 16:27:53 -07:00
|
|
|
pub fn reward_claim(from_pubkey: &Pubkey, slot: u64) -> Instruction {
|
|
|
|
let storage_instruction = StorageInstruction::ClaimStorageReward { slot };
|
2019-04-03 09:45:57 -06:00
|
|
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
|
|
|
Instruction::new(id(), &storage_instruction, account_metas)
|
2019-03-22 21:18:51 -06:00
|
|
|
}
|