casper_types/transaction/
execution_info.rsuse alloc::vec::Vec;
#[cfg(feature = "json-schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{
bytesrepr::{self, FromBytes, ToBytes},
execution::ExecutionResult,
BlockHash,
};
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "json-schema", derive(JsonSchema))]
#[serde(deny_unknown_fields)]
pub struct ExecutionInfo {
pub block_hash: BlockHash,
pub block_height: u64,
pub execution_result: Option<ExecutionResult>,
}
impl FromBytes for ExecutionInfo {
fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> {
let (block_hash, bytes) = FromBytes::from_bytes(bytes)?;
let (block_height, bytes) = FromBytes::from_bytes(bytes)?;
let (execution_result, bytes) = FromBytes::from_bytes(bytes)?;
Ok((
ExecutionInfo {
block_hash,
block_height,
execution_result,
},
bytes,
))
}
}
impl ToBytes for ExecutionInfo {
fn to_bytes(&self) -> Result<Vec<u8>, bytesrepr::Error> {
let mut result = bytesrepr::allocate_buffer(self)?;
self.write_bytes(&mut result)?;
Ok(result)
}
fn write_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), bytesrepr::Error> {
self.block_hash.write_bytes(bytes)?;
self.block_height.write_bytes(bytes)?;
self.execution_result.write_bytes(bytes)?;
Ok(())
}
fn serialized_length(&self) -> usize {
self.block_hash.serialized_length()
+ self.block_height.serialized_length()
+ self.execution_result.serialized_length()
}
}