Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp support to substreams #5641

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chain/substreams/proto/codec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ message Value {
string string = 4;
bytes bytes = 5;
bool bool = 6;

//reserved 7 to 9; // For future types
int64 timestamp = 7;
//reserved 8 to 9; // For future types

Array array = 10;
}
Expand Down
15 changes: 13 additions & 2 deletions chain/substreams/src/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use graph::blockchain::block_stream::{
SubstreamsError,
};
use graph::blockchain::BlockTime;
use graph::data::store::scalar::Bytes;
use graph::data::store::scalar::{Bytes, Timestamp};
use graph::data::store::IdType;
use graph::data::value::Word;
use graph::data_source::CausalityRegion;
Expand Down Expand Up @@ -264,6 +264,10 @@ fn decode_value(value: &crate::codec::value::Typed) -> anyhow::Result<Value> {

Typed::Bool(new_value) => Ok(Value::Bool(*new_value)),

Typed::Timestamp(new_value) => Timestamp::from_microseconds_since_epoch(*new_value)
.map(Value::Timestamp)
.map_err(|err| anyhow::Error::from(err)),

Typed::Array(arr) => arr
.value
.iter()
Expand All @@ -282,7 +286,7 @@ mod test {
use crate::codec::{Array, Value};
use base64::prelude::*;
use graph::{
data::store::scalar::Bytes,
data::store::scalar::{Bytes, Timestamp},
prelude::{BigDecimal, BigInt, Value as GraphValue},
};

Expand Down Expand Up @@ -374,6 +378,13 @@ mod test {
},
expected_value: GraphValue::Bool(true),
},
Case {
name: "timestamp value".to_string(),
value: Value {
typed: Some(Typed::Timestamp(1234565789)),
},
expected_value: GraphValue::Timestamp(Timestamp::from_microseconds_since_epoch(1234565789).unwrap()),
},
Case {
name: "string array".to_string(),
value: Value {
Expand Down
5 changes: 4 additions & 1 deletion chain/substreams/src/protobuf/substreams.entity.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub mod entity_change {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Value {
#[prost(oneof = "value::Typed", tags = "1, 2, 3, 4, 5, 6, 10")]
#[prost(oneof = "value::Typed", tags = "1, 2, 3, 4, 5, 6, 7, 10")]
pub typed: ::core::option::Option<value::Typed>,
}
/// Nested message and enum types in `Value`.
Expand All @@ -88,6 +88,9 @@ pub mod value {
Bytes(::prost::alloc::vec::Vec<u8>),
#[prost(bool, tag = "6")]
Bool(bool),
/// reserved 8 to 9; // For future types
#[prost(int64, tag = "7")]
Timestamp(i64),
#[prost(message, tag = "10")]
Array(super::Array),
}
Expand Down
Loading