Placeholder storage contract and replicator client (#1286)

* Add hooks for executing the storage contract

* Add store_ledger stage
  Similar to replicate_stage but no voting/banking stuff, just convert
  blobs to entries and write the ledger out

* Add storage_addr to tests and add new NodeInfo constructor
  to reduce duplication...
This commit is contained in:
sakridge
2018-09-21 15:32:15 -07:00
committed by GitHub
parent 3dcee9f79e
commit a9355c33b2
10 changed files with 436 additions and 68 deletions

42
src/storage_program.rs Normal file
View File

@@ -0,0 +1,42 @@
//! storage program
//! Receive mining proofs from miners, validate the answers
//! and give reward for good proofs.
use bank::Account;
use bincode::deserialize;
use signature::Pubkey;
use transaction::Transaction;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum StorageProgram {
SubmitMiningProof { sha_state: [u8; 32] },
}
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
}
pub fn process_transaction(tx: &Transaction, _accounts: &mut [Account]) {
let syscall: StorageProgram = deserialize(&tx.userdata).unwrap();
match syscall {
StorageProgram::SubmitMiningProof { sha_state } => {
info!("Mining proof submitted with state {}", sha_state[0]);
return;
}
}
}
}
#[cfg(test)]
mod test {}