Files
solana/src/storage_program.rs

53 lines
1.2 KiB
Rust
Raw Normal View History

//! storage program
//! Receive mining proofs from miners, validate the answers
//! and give reward for good proofs.
use account::Account;
use bincode::deserialize;
2018-09-26 17:55:36 -06:00
use pubkey::Pubkey;
use transaction::Transaction;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageProgram {
SubmitMiningProof { sha_state: [u8; 32] },
}
2018-09-26 13:50:30 -07:00
pub enum StorageError {
InvalidUserData,
}
pub const STORAGE_PROGRAM_ID: [u8; 32] = [1u8; 32];
impl StorageProgram {
pub fn check_id(program_id: &Pubkey) -> bool {
program_id.as_ref() == STORAGE_PROGRAM_ID
}
pub fn id() -> Pubkey {
Pubkey::new(&STORAGE_PROGRAM_ID)
}
pub fn get_balance(account: &Account) -> i64 {
account.tokens
}
2018-09-26 13:50:30 -07:00
pub fn process_transaction(
tx: &Transaction,
_accounts: &mut [Account],
) -> Result<(), StorageError> {
if let Ok(syscall) = deserialize(&tx.userdata) {
match syscall {
StorageProgram::SubmitMiningProof { sha_state } => {
info!("Mining proof submitted with state {}", sha_state[0]);
return Ok(());
}
}
2018-09-26 13:50:30 -07:00
} else {
return Err(StorageError::InvalidUserData);
}
}
}
#[cfg(test)]
mod test {}