@@ -13,7 +13,7 @@ use semver::Version;
1313use wasmtime:: Trap ;
1414use web3:: types:: H160 ;
1515
16- use graph:: blockchain:: Blockchain ;
16+ use graph:: blockchain:: { BlockTime , Blockchain } ;
1717use graph:: components:: store:: { EnsLookup , GetScope , LoadRelatedRequest } ;
1818use graph:: components:: subgraph:: {
1919 PoICausalityRegion , ProofOfIndexingEvent , SharedProofOfIndexing ,
@@ -218,6 +218,7 @@ impl<C: Blockchain> HostExports<C> {
218218 state : & mut BlockState < C > ,
219219 block : BlockNumber ,
220220 proof_of_indexing : & SharedProofOfIndexing ,
221+ block_time : BlockTime ,
221222 entity_type : String ,
222223 entity_id : String ,
223224 mut data : HashMap < Word , Value > ,
@@ -251,6 +252,10 @@ impl<C: Blockchain> HostExports<C> {
251252 "store_set" ,
252253 ) ?;
253254
255+ if entity_type. object_type ( ) ?. timeseries {
256+ data. insert ( Word :: from ( "timestamp" ) , block_time. into ( ) ) ;
257+ }
258+
254259 // Set the id if there isn't one yet, and make sure that a
255260 // previously set id agrees with the one in the `key`
256261 match data. get ( & store:: ID ) {
@@ -1095,7 +1100,7 @@ pub mod test_support {
10951100 use std:: { borrow:: Cow , collections:: HashMap , sync:: Arc } ;
10961101
10971102 use graph:: {
1098- blockchain:: Blockchain ,
1103+ blockchain:: { BlockTime , Blockchain } ,
10991104 components:: {
11001105 store:: { BlockNumber , GetScope } ,
11011106 subgraph:: SharedProofOfIndexing ,
@@ -1108,11 +1113,17 @@ pub mod test_support {
11081113
11091114 use crate :: MappingContext ;
11101115
1111- pub struct HostExports < C : Blockchain > ( Arc < super :: HostExports < C > > ) ;
1116+ pub struct HostExports < C : Blockchain > {
1117+ host_exports : Arc < super :: HostExports < C > > ,
1118+ block_time : BlockTime ,
1119+ }
11121120
11131121 impl < C : Blockchain > HostExports < C > {
11141122 pub fn new ( ctx : & MappingContext < C > ) -> Self {
1115- HostExports ( ctx. host_exports . clone ( ) )
1123+ HostExports {
1124+ host_exports : ctx. host_exports . clone ( ) ,
1125+ block_time : ctx. timestamp ,
1126+ }
11161127 }
11171128
11181129 pub fn store_set (
@@ -1127,11 +1138,12 @@ pub mod test_support {
11271138 stopwatch : & StopwatchMetrics ,
11281139 gas : & GasCounter ,
11291140 ) -> Result < ( ) , HostExportError > {
1130- self . 0 . store_set (
1141+ self . host_exports . store_set (
11311142 logger,
11321143 state,
11331144 block,
11341145 proof_of_indexing,
1146+ self . block_time ,
11351147 entity_type,
11361148 entity_id,
11371149 data,
@@ -1147,7 +1159,7 @@ pub mod test_support {
11471159 entity_id : String ,
11481160 gas : & GasCounter ,
11491161 ) -> Result < Option < Cow < ' a , Entity > > , anyhow:: Error > {
1150- self . 0
1162+ self . host_exports
11511163 . store_get ( state, entity_type, entity_id, gas, GetScope :: Store )
11521164 }
11531165 }
0 commit comments