casper_types/transaction/
execution_info.rs1use alloc::vec::Vec;
2
3#[cfg(feature = "json-schema")]
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7use crate::{
8 bytesrepr::{self, FromBytes, ToBytes},
9 execution::ExecutionResult,
10 BlockHash,
11};
12
13#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
16#[cfg_attr(feature = "json-schema", derive(JsonSchema))]
17#[serde(deny_unknown_fields)]
18pub struct ExecutionInfo {
19 pub block_hash: BlockHash,
21 pub block_height: u64,
23 pub execution_result: Option<ExecutionResult>,
25}
26
27impl FromBytes for ExecutionInfo {
28 fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> {
29 let (block_hash, bytes) = FromBytes::from_bytes(bytes)?;
30 let (block_height, bytes) = FromBytes::from_bytes(bytes)?;
31 let (execution_result, bytes) = FromBytes::from_bytes(bytes)?;
32 Ok((
33 ExecutionInfo {
34 block_hash,
35 block_height,
36 execution_result,
37 },
38 bytes,
39 ))
40 }
41}
42
43impl ToBytes for ExecutionInfo {
44 fn to_bytes(&self) -> Result<Vec<u8>, bytesrepr::Error> {
45 let mut result = bytesrepr::allocate_buffer(self)?;
46 self.write_bytes(&mut result)?;
47 Ok(result)
48 }
49
50 fn write_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), bytesrepr::Error> {
51 self.block_hash.write_bytes(bytes)?;
52 self.block_height.write_bytes(bytes)?;
53 self.execution_result.write_bytes(bytes)?;
54 Ok(())
55 }
56
57 fn serialized_length(&self) -> usize {
58 self.block_hash.serialized_length()
59 + self.block_height.serialized_length()
60 + self.execution_result.serialized_length()
61 }
62}