@@ -4,7 +4,7 @@ use crate::cheap_clone::CheapClone;
4
4
use crate :: components:: server:: query:: ServerResponse ;
5
5
use crate :: data:: value:: Object ;
6
6
use crate :: derive:: CacheWeight ;
7
- use crate :: prelude:: { r, CacheWeight , DeploymentHash } ;
7
+ use crate :: prelude:: { r, BlockHash , BlockNumber , CacheWeight , DeploymentHash } ;
8
8
use http_body_util:: Full ;
9
9
use hyper:: header:: {
10
10
ACCESS_CONTROL_ALLOW_HEADERS , ACCESS_CONTROL_ALLOW_METHODS , ACCESS_CONTROL_ALLOW_ORIGIN ,
@@ -48,20 +48,37 @@ where
48
48
ser. end ( )
49
49
}
50
50
51
+ fn serialize_block_hash < S > ( data : & BlockHash , serializer : S ) -> Result < S :: Ok , S :: Error >
52
+ where
53
+ S : Serializer ,
54
+ {
55
+ serializer. serialize_str ( & data. to_string ( ) )
56
+ }
57
+
51
58
pub type Data = Object ;
52
59
53
60
#[ derive( Debug ) ]
54
61
/// A collection of query results that is serialized as a single result.
55
62
pub struct QueryResults {
56
63
results : Vec < Arc < QueryResult > > ,
57
64
pub trace : Trace ,
65
+ pub indexed_block : Option < LatestBlockInfo > ,
66
+ }
67
+
68
+ #[ derive( Debug , Serialize ) ]
69
+ pub struct LatestBlockInfo {
70
+ #[ serde( serialize_with = "serialize_block_hash" ) ]
71
+ pub hash : BlockHash ,
72
+ pub number : BlockNumber ,
73
+ pub timestamp : Option < u64 > ,
58
74
}
59
75
60
76
impl QueryResults {
61
- pub fn empty ( trace : Trace ) -> Self {
77
+ pub fn empty ( trace : Trace , indexed_block : Option < LatestBlockInfo > ) -> Self {
62
78
QueryResults {
63
79
results : Vec :: new ( ) ,
64
80
trace,
81
+ indexed_block,
65
82
}
66
83
}
67
84
@@ -155,6 +172,7 @@ impl From<Data> for QueryResults {
155
172
QueryResults {
156
173
results : vec ! [ Arc :: new( x. into( ) ) ] ,
157
174
trace : Trace :: None ,
175
+ indexed_block : None ,
158
176
}
159
177
}
160
178
}
@@ -164,6 +182,7 @@ impl From<QueryResult> for QueryResults {
164
182
QueryResults {
165
183
results : vec ! [ Arc :: new( x) ] ,
166
184
trace : Trace :: None ,
185
+ indexed_block : None ,
167
186
}
168
187
}
169
188
}
@@ -173,6 +192,7 @@ impl From<Arc<QueryResult>> for QueryResults {
173
192
QueryResults {
174
193
results : vec ! [ x] ,
175
194
trace : Trace :: None ,
195
+ indexed_block : None ,
176
196
}
177
197
}
178
198
}
@@ -182,6 +202,7 @@ impl From<QueryExecutionError> for QueryResults {
182
202
QueryResults {
183
203
results : vec ! [ Arc :: new( x. into( ) ) ] ,
184
204
trace : Trace :: None ,
205
+ indexed_block : None ,
185
206
}
186
207
}
187
208
}
@@ -191,6 +212,7 @@ impl From<Vec<QueryExecutionError>> for QueryResults {
191
212
QueryResults {
192
213
results : vec ! [ Arc :: new( x. into( ) ) ] ,
193
214
trace : Trace :: None ,
215
+ indexed_block : None ,
194
216
}
195
217
}
196
218
}
@@ -205,14 +227,16 @@ impl QueryResults {
205
227
pub fn as_http_response ( & self ) -> ServerResponse {
206
228
let json = serde_json:: to_string ( & self ) . unwrap ( ) ;
207
229
let attestable = self . results . iter ( ) . all ( |r| r. is_attestable ( ) ) ;
230
+ let indexed_block = serde_json:: to_string ( & self . indexed_block ) . unwrap ( ) ;
208
231
Response :: builder ( )
209
232
. status ( 200 )
210
233
. header ( ACCESS_CONTROL_ALLOW_ORIGIN , "*" )
211
234
. header ( CONTENT_TYPE , "application/json" )
212
235
. header ( ACCESS_CONTROL_ALLOW_HEADERS , "Content-Type, User-Agent" )
213
236
. header ( ACCESS_CONTROL_ALLOW_METHODS , "GET, OPTIONS, POST" )
214
237
. header ( CONTENT_TYPE , "application/json" )
215
- . header ( "Graph-Attestable" , attestable. to_string ( ) )
238
+ . header ( "graph-attestable" , attestable. to_string ( ) )
239
+ . header ( "graph-indexed" , indexed_block)
216
240
. body ( Full :: from ( json) )
217
241
. unwrap ( )
218
242
}
@@ -386,8 +410,7 @@ fn multiple_data_items() {
386
410
let obj1 = make_obj ( "key1" , "value1" ) ;
387
411
let obj2 = make_obj ( "key2" , "value2" ) ;
388
412
389
- let trace = Trace :: None ;
390
- let mut res = QueryResults :: empty ( trace) ;
413
+ let mut res = QueryResults :: empty ( Trace :: None , None ) ;
391
414
res. append ( obj1, CacheStatus :: default ( ) ) ;
392
415
res. append ( obj2, CacheStatus :: default ( ) ) ;
393
416
0 commit comments