Handle deserialize failure with error
This commit is contained in:
parent
ac8d738045
commit
d546614936
|
@ -423,7 +423,9 @@ impl Bank {
|
|||
return Err(BankError::ProgramRuntimeError);
|
||||
}
|
||||
} else if StorageProgram::check_id(&tx.program_id) {
|
||||
StorageProgram::process_transaction(&tx, accounts)
|
||||
if StorageProgram::process_transaction(&tx, accounts).is_err() {
|
||||
return Err(BankError::ProgramRuntimeError);
|
||||
}
|
||||
} else if TicTacToeProgram::check_id(&tx.program_id) {
|
||||
if TicTacToeProgram::process_transaction(&tx, accounts).is_err() {
|
||||
return Err(BankError::ProgramRuntimeError);
|
||||
|
|
|
@ -12,6 +12,10 @@ pub enum StorageProgram {
|
|||
SubmitMiningProof { sha_state: [u8; 32] },
|
||||
}
|
||||
|
||||
pub enum StorageError {
|
||||
InvalidUserData,
|
||||
}
|
||||
|
||||
pub const STORAGE_PROGRAM_ID: [u8; 32] = [1u8; 32];
|
||||
|
||||
impl StorageProgram {
|
||||
|
@ -27,14 +31,20 @@ impl StorageProgram {
|
|||
account.tokens
|
||||
}
|
||||
|
||||
pub fn process_transaction(tx: &Transaction, _accounts: &mut [Account]) {
|
||||
let syscall: StorageProgram = deserialize(&tx.userdata).unwrap();
|
||||
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;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Err(StorageError::InvalidUserData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue