@@ -13,7 +13,7 @@ use semver::Version;
13
13
use wasmtime:: Trap ;
14
14
use web3:: types:: H160 ;
15
15
16
- use graph:: blockchain:: Blockchain ;
16
+ use graph:: blockchain:: { BlockTime , Blockchain } ;
17
17
use graph:: components:: store:: { EnsLookup , GetScope , LoadRelatedRequest } ;
18
18
use graph:: components:: subgraph:: {
19
19
PoICausalityRegion , ProofOfIndexingEvent , SharedProofOfIndexing ,
@@ -218,6 +218,7 @@ impl<C: Blockchain> HostExports<C> {
218
218
state : & mut BlockState < C > ,
219
219
block : BlockNumber ,
220
220
proof_of_indexing : & SharedProofOfIndexing ,
221
+ block_time : BlockTime ,
221
222
entity_type : String ,
222
223
entity_id : String ,
223
224
mut data : HashMap < Word , Value > ,
@@ -251,6 +252,10 @@ impl<C: Blockchain> HostExports<C> {
251
252
"store_set" ,
252
253
) ?;
253
254
255
+ if entity_type. object_type ( ) ?. timeseries {
256
+ data. insert ( Word :: from ( "timestamp" ) , block_time. into ( ) ) ;
257
+ }
258
+
254
259
// Set the id if there isn't one yet, and make sure that a
255
260
// previously set id agrees with the one in the `key`
256
261
match data. get ( & store:: ID ) {
@@ -1095,7 +1100,7 @@ pub mod test_support {
1095
1100
use std:: { borrow:: Cow , collections:: HashMap , sync:: Arc } ;
1096
1101
1097
1102
use graph:: {
1098
- blockchain:: Blockchain ,
1103
+ blockchain:: { BlockTime , Blockchain } ,
1099
1104
components:: {
1100
1105
store:: { BlockNumber , GetScope } ,
1101
1106
subgraph:: SharedProofOfIndexing ,
@@ -1108,11 +1113,17 @@ pub mod test_support {
1108
1113
1109
1114
use crate :: MappingContext ;
1110
1115
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
+ }
1112
1120
1113
1121
impl < C : Blockchain > HostExports < C > {
1114
1122
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
+ }
1116
1127
}
1117
1128
1118
1129
pub fn store_set (
@@ -1127,11 +1138,12 @@ pub mod test_support {
1127
1138
stopwatch : & StopwatchMetrics ,
1128
1139
gas : & GasCounter ,
1129
1140
) -> Result < ( ) , HostExportError > {
1130
- self . 0 . store_set (
1141
+ self . host_exports . store_set (
1131
1142
logger,
1132
1143
state,
1133
1144
block,
1134
1145
proof_of_indexing,
1146
+ self . block_time ,
1135
1147
entity_type,
1136
1148
entity_id,
1137
1149
data,
@@ -1147,7 +1159,7 @@ pub mod test_support {
1147
1159
entity_id : String ,
1148
1160
gas : & GasCounter ,
1149
1161
) -> Result < Option < Cow < ' a , Entity > > , anyhow:: Error > {
1150
- self . 0
1162
+ self . host_exports
1151
1163
. store_get ( state, entity_type, entity_id, gas, GetScope :: Store )
1152
1164
}
1153
1165
}
0 commit comments