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 crate::storage_contract::ProofStatus;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::signature::Signature;
|
||||||
|
use solana_sdk::transaction::{AccountMeta, Instruction};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub enum StorageInstruction {
|
pub enum StorageInstruction {
|
||||||
|
@ -22,3 +25,52 @@ pub enum StorageInstruction {
|
||||||
proof_mask: Vec<ProofStatus>,
|
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_contract::ProofStatus;
|
||||||
use crate::storage_instruction::StorageInstruction;
|
use crate::storage_instruction::StorageInstruction;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
|
||||||
pub struct StorageTransaction {}
|
pub struct StorageTransaction {}
|
||||||
|
@ -15,12 +14,11 @@ impl StorageTransaction {
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let program = StorageInstruction::SubmitMiningProof {
|
let from_pubkey = from_keypair.pubkey();
|
||||||
sha_state,
|
let storage_instruction =
|
||||||
entry_height,
|
StorageInstruction::new_mining_proof(&from_pubkey, sha_state, entry_height, signature);
|
||||||
signature,
|
let instructions = vec![storage_instruction];
|
||||||
};
|
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
||||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_advertise_recent_blockhash(
|
pub fn new_advertise_recent_blockhash(
|
||||||
|
@ -29,11 +27,14 @@ impl StorageTransaction {
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let program = StorageInstruction::AdvertiseStorageRecentBlockhash {
|
let from_pubkey = from_keypair.pubkey();
|
||||||
hash: storage_hash,
|
let storage_instruction = StorageInstruction::new_advertise_recent_blockhash(
|
||||||
|
&from_pubkey,
|
||||||
|
storage_hash,
|
||||||
entry_height,
|
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(
|
pub fn new_proof_validation(
|
||||||
|
@ -42,11 +43,11 @@ impl StorageTransaction {
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
proof_mask: Vec<ProofStatus>,
|
proof_mask: Vec<ProofStatus>,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let program = StorageInstruction::ProofValidation {
|
let from_pubkey = from_keypair.pubkey();
|
||||||
entry_height,
|
let storage_instruction =
|
||||||
proof_mask,
|
StorageInstruction::new_proof_validation(&from_pubkey, entry_height, proof_mask);
|
||||||
};
|
let instructions = vec![storage_instruction];
|
||||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_reward_claim(
|
pub fn new_reward_claim(
|
||||||
|
@ -54,7 +55,9 @@ impl StorageTransaction {
|
||||||
recent_blockhash: Hash,
|
recent_blockhash: Hash,
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let program = StorageInstruction::ClaimStorageReward { entry_height };
|
let from_pubkey = from_keypair.pubkey();
|
||||||
Transaction::new_signed(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
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