send<T> method
Future<JsonRpcSuccessResponse<T> >
send<T>(
- JsonRpcRequest request,
- JsonRpcResponseDecoder<
Map< decode, {String, dynamic> , JsonRpcResponse<T> > - JsonRpcClientConfig? config,
Sends a JSON RPC request to uri and returns its response.
The decode
method is used to convert the JSON response to a JsonRpcResponse.
The config
object can be used to configure the request.
Implementation
Future<JsonRpcSuccessResponse<T>> send<T>(
final JsonRpcRequest request,
final JsonRpcResponseDecoder<Map<String, dynamic>, JsonRpcResponse<T>>
decode, {
final JsonRpcClientConfig? config,
}) async {
final List<int> body = await encoder.convert(request);
final Map<String, dynamic> json =
await handler(body, config: config, id: request.id);
final JsonRpcResponse<T> response = decode(json);
return response is JsonRpcErrorResponse<T>
? Future.error(response.error) // [JsonRpcException]
: Future.value(response as JsonRpcSuccessResponse<T>);
}