Skip to content

Commit

Permalink
Add AbiTrace.flatten_filter func
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Feb 21, 2024
1 parent 71c2c8d commit a61ddd4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use massa_proto_rs::massa::model::v1::{
AddressCategory, ComparisonResult, NativeAmount, NativeTime, Slot,
};
use serde::{de::DeserializeOwned, Serialize};
use std::collections::VecDeque;

Check warning on line 6 in src/types.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `std::collections::VecDeque`

warning: unused import: `std::collections::VecDeque` --> src/types.rs:6:5 | 6 | use std::collections::VecDeque; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use std::{
collections::{BTreeSet, HashMap},
path::PathBuf,
Expand All @@ -18,6 +19,7 @@ pub enum AbiTraceType {
Bool(bool),
U8(u8),
I32(i32),
U32(u32),
I64(i64),
U64(u64),
F64(f64),
Expand Down Expand Up @@ -46,6 +48,14 @@ impl From<i32> for AbiTraceType {
Self::I32(v)
}
}

#[cfg(feature = "execution-trace")]
impl From<u32> for AbiTraceType {
fn from(v: u32) -> Self {
Self::U32(v)
}
}

#[cfg(feature = "execution-trace")]
impl From<i64> for AbiTraceType {
fn from(v: i64) -> Self {
Expand Down Expand Up @@ -134,6 +144,32 @@ pub struct AbiTrace {
pub sub_calls: Option<Vec<AbiTrace>>,
}

#[cfg(feature = "execution-trace")]
impl AbiTrace {
pub fn flatten_filter(&self, abi_names: &Vec<String>) -> Vec<&Self> {
let mut filtered: Vec<&Self> = Default::default();
let mut to_process: VecDeque<&Self> = vec![self].into();

while !to_process.is_empty() {
let t = to_process.pop_front();
if let Some(trace) = t {
if abi_names.iter().find(|t| *(*t) == trace.name).is_some() {
// filtered.extend(&trace)
filtered.push(trace);
}

if let Some(sub_call) = &trace.sub_calls {
for sc in sub_call.iter().rev() {
to_process.push_front(sc);
}
}
}
}

filtered
}
}

/// That's what is returned when a module is executed correctly since the end
#[derive(Debug)]
pub struct Response {
Expand Down

0 comments on commit a61ddd4

Please sign in to comment.