@@ -19,29 +19,22 @@ where
19
19
{
20
20
let response: Output = serde_json:: from_slice ( response_raw)
21
21
. chain_err ( || ErrorKind :: ResponseError ( "Not valid json" ) ) ?;
22
+ ensure ! (
23
+ response. version( ) == Some ( Version :: V2 ) ,
24
+ ErrorKind :: ResponseError ( "Not JSON-RPC 2.0 compatible" )
25
+ ) ;
26
+ ensure ! (
27
+ response. id( ) == & expected_id,
28
+ ErrorKind :: ResponseError ( "Response id not equal to request id" )
29
+ ) ;
22
30
match response {
23
31
Output :: Success ( success) => {
24
- check_response ( success. jsonrpc , success. id , expected_id) ?;
25
32
trace ! ( "Received json result: {}" , success. result) ;
26
33
serde_json:: from_value :: < R > ( success. result )
27
34
. chain_err ( || ErrorKind :: ResponseError ( "Not valid for target type" ) )
28
35
}
29
36
Output :: Failure ( failure) => {
30
- check_response ( failure. jsonrpc , failure. id , expected_id) ?;
31
37
Err ( ErrorKind :: JsonRpcError ( failure. error ) . into ( ) )
32
38
}
33
39
}
34
40
}
35
-
36
- /// Validate if response is a valid JSON-RPC 2.0 response object with the correct Id.
37
- fn check_response ( version : Option < Version > , id : Id , expected_id : Id ) -> Result < ( ) > {
38
- ensure ! (
39
- version == Some ( Version :: V2 ) ,
40
- ErrorKind :: ResponseError ( "Not JSON-RPC 2.0 compatible" )
41
- ) ;
42
- ensure ! (
43
- id == expected_id,
44
- ErrorKind :: ResponseError ( "Response id not equal to request id" )
45
- ) ;
46
- Ok ( ( ) )
47
- }
0 commit comments