File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -377,3 +377,34 @@ impl HttpResponse for GetSortitionHandler {
377
377
Ok ( HttpResponsePayload :: try_from_json ( sortition_info) ?)
378
378
}
379
379
}
380
+
381
+ impl StacksHttpRequest {
382
+ /// Make a new getinfo request to this endpoint
383
+ pub fn new_get_sortition (
384
+ host : PeerHost ,
385
+ sort_key : & str ,
386
+ sort_value : & str ,
387
+ ) -> StacksHttpRequest {
388
+ StacksHttpRequest :: new_for_peer (
389
+ host,
390
+ "GET" . into ( ) ,
391
+ format ! ( "/v3/sortitions/{}/{}" , sort_key, sort_value) ,
392
+ HttpRequestContents :: new ( ) ,
393
+ )
394
+ . expect ( "FATAL: failed to construct request from infallible data" )
395
+ }
396
+
397
+ pub fn new_get_sortition_consensus ( host : PeerHost , ch : & ConsensusHash ) -> StacksHttpRequest {
398
+ Self :: new_get_sortition ( host, "consensus" , & format ! ( "{}" , ch) )
399
+ }
400
+ }
401
+
402
+ impl StacksHttpResponse {
403
+ pub fn decode_sortition_info ( self ) -> Result < Vec < SortitionInfo > , NetError > {
404
+ let contents = self . get_http_payload_ok ( ) ?;
405
+ let response_json: serde_json:: Value = contents. try_into ( ) ?;
406
+ let response: Vec < SortitionInfo > = serde_json:: from_value ( response_json)
407
+ . map_err ( |_e| Error :: DecodeError ( format ! ( "Failed to decode JSON: {:?}" , & _e) ) ) ?;
408
+ Ok ( response)
409
+ }
410
+ }
You can’t perform that action at this time.
0 commit comments