|
21 | 21 |
|
22 | 22 | use {
|
23 | 23 | crate::{
|
24 |
| - error::CarbonResult, filter::Filter, metrics::MetricsCollection, processor::Processor, |
25 |
| - transaction::TransactionMetadata, |
| 24 | + deserialize::CarbonDeserialize, error::CarbonResult, filter::Filter, |
| 25 | + metrics::MetricsCollection, processor::Processor, transaction::TransactionMetadata, |
26 | 26 | },
|
27 | 27 | async_trait::async_trait,
|
28 | 28 | serde::{Deserialize, Serialize},
|
@@ -70,14 +70,31 @@ enum LogType {
|
70 | 70 | }
|
71 | 71 |
|
72 | 72 | impl InstructionMetadata {
|
| 73 | + /// Decodes the log events `T` thrown by this instruction. |
| 74 | + /// |
| 75 | + /// # Parameters |
| 76 | + /// |
| 77 | + /// - `T`: The event type to decode the logs into. |
| 78 | + /// |
| 79 | + /// # Returns |
| 80 | + /// |
| 81 | + /// All successfull events of the type `T` decoded from the logs of the instruction. |
| 82 | + pub fn decode_log_events<T: CarbonDeserialize>(&self) -> Vec<T> { |
| 83 | + self.extract_event_log_data() |
| 84 | + .into_iter() |
| 85 | + .map(|log| <T as CarbonDeserialize>::deserialize(&mut &log[8..])) |
| 86 | + .flatten() |
| 87 | + .collect() |
| 88 | + } |
| 89 | + |
73 | 90 | /// Extracts the `data` from log messages associated with this instruction.
|
74 | 91 | ///
|
75 | 92 | /// This method filters the transaction's log messages to return only those
|
76 | 93 | /// that correspond to the current instruction, based on its stack height and
|
77 | 94 | /// absolute path within the instruction stack.
|
78 | 95 | ///
|
79 | 96 | /// Returns `Vec<Vec<u8>>` containing the `data` bytes (base64 encoded) from log messages.
|
80 |
| - pub fn extract_event_log_data(&self) -> Vec<Vec<u8>> { |
| 97 | + fn extract_event_log_data(&self) -> Vec<Vec<u8>> { |
81 | 98 | let logs = match &self.transaction_metadata.meta.log_messages {
|
82 | 99 | Some(logs) => logs,
|
83 | 100 | None => return Vec::new(),
|
|
0 commit comments