Add StorageInstruction constructors
This commit is contained in:
parent
5a65c3f72e
commit
dcf2337e58
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use crate::id;
|
||||
use crate::storage_contract::ProofStatus;
|
||||
use crate::storage_instruction::StorageInstruction;
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::signature::{Keypair, Signature};
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
|
||||
pub struct StorageTransaction {}
|
||||
|
@ -15,12 +14,11 @@ impl StorageTransaction {
|
|||
entry_height: u64,
|
||||
signature: Signature,
|
||||
) -> Transaction {
|
||||
let program = StorageInstruction::SubmitMiningProof {
|
||||
sha_state,
|
||||
entry_height,
|
||||
signature,
|
||||
};
|
||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let storage_instruction =
|
||||
StorageInstruction::new_mining_proof(&from_pubkey, sha_state, entry_height, signature);
|
||||
let instructions = vec![storage_instruction];
|
||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_advertise_recent_blockhash(
|
||||
|
@ -29,11 +27,14 @@ impl StorageTransaction {
|
|||
recent_blockhash: Hash,
|
||||
entry_height: u64,
|
||||
) -> Transaction {
|
||||
let program = StorageInstruction::AdvertiseStorageRecentBlockhash {
|
||||
hash: storage_hash,
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let storage_instruction = StorageInstruction::new_advertise_recent_blockhash(
|
||||
&from_pubkey,
|
||||
storage_hash,
|
||||
entry_height,
|
||||
};
|
||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
);
|
||||
let instructions = vec![storage_instruction];
|
||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_proof_validation(
|
||||
|
@ -42,11 +43,11 @@ impl StorageTransaction {
|
|||
entry_height: u64,
|
||||
proof_mask: Vec<ProofStatus>,
|
||||
) -> Transaction {
|
||||
let program = StorageInstruction::ProofValidation {
|
||||
entry_height,
|
||||
proof_mask,
|
||||
};
|
||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let storage_instruction =
|
||||
StorageInstruction::new_proof_validation(&from_pubkey, entry_height, proof_mask);
|
||||
let instructions = vec![storage_instruction];
|
||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_reward_claim(
|
||||
|
@ -54,7 +55,9 @@ impl StorageTransaction {
|
|||
recent_blockhash: Hash,
|
||||
entry_height: u64,
|
||||
) -> Transaction {
|
||||
let program = StorageInstruction::ClaimStorageReward { entry_height };
|
||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
let from_pubkey = from_keypair.pubkey();
|
||||
let storage_instruction = StorageInstruction::new_reward_claim(&from_pubkey, entry_height);
|
||||
let instructions = vec![storage_instruction];
|
||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue