diff --git a/Cargo.lock b/Cargo.lock index 7f7f9ff..b978fc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,7 @@ dependencies = [ [[package]] name = "substreams-entity-change" -version = "1.3.0" +version = "1.3.1" dependencies = [ "base64", "prost", diff --git a/substreams-entity-change/src/tables.rs b/substreams-entity-change/src/tables.rs index f0ed458..4761321 100644 --- a/substreams-entity-change/src/tables.rs +++ b/substreams-entity-change/src/tables.rs @@ -323,6 +323,26 @@ impl ToValue for &Vec { } } +impl ToValue for &Vec> { + fn to_value(self) -> Value { + Value { + typed: Some(Typed::Array(Array { + value: self.iter().map(ToValue::to_value).collect(), + })), + } + } +} + +impl ToValue for Vec> { + fn to_value(self) -> Value { + Value { + typed: Some(Typed::Array(Array { + value: self.into_iter().map(ToValue::to_value).collect(), + })), + } + } +} + impl ToValue for Vec { fn to_value(self) -> Value { Value { @@ -442,3 +462,40 @@ macro_rules! impl_to_int32_value { impl_to_int32_value!(i8); impl_to_int32_value!(i16); impl_to_int32_value!(i32); + +#[cfg(test)] +mod test { + use crate::pb::entity::{EntityChange, EntityChanges, entity_change::Operation, Field, Value, value::Typed, Array}; + + use super::Tables; + + #[test] + fn test_vec_vec_u8() { + let mut tables = Tables::new(); + tables.create_row("table", "1").set("field", &vec![vec![1, 2, 3]]); + + let changes = tables.to_entity_changes(); + assert_eq!(changes.entity_changes.len(), 1); + assert_eq!(changes.entity_changes[0], EntityChange { + entity: "table".to_string(), + id: "1".to_string(), + ordinal: 0, + operation: Operation::Create as i32, + fields: vec![ + Field { + name: "field".to_string(), + new_value: Some(Value { + typed: Some(Typed::Array(Array { + value: vec![ + Value { + typed: Some(Typed::Bytes("AQID".to_string())), + } + ], + })), + }), + old_value: None, + } + ], + }); + } +} \ No newline at end of file