invoke method
Implementation
Future invoke(String method, dynamic params) async {
final rq = {
if (!_omitRpcVersion) 'jsonrpc': '2.0',
'method': method,
if (params != null) 'params': params,
if (!_omitRequestId) 'id': '${_id++}',
};
final request = Request('POST', _endpoint)
..bodyBytes = _jsonUtf8.encode(rq)
..headers['Content-Type'] = 'application/json';
if (_headers != null) {
request.headers.addAll(_headers);
}
final rs = await _client.send(request);
final map = await _jsonUtf8.decoder.bind(rs.stream).single;
if (map is! Map<String, dynamic>) {
throw FormatException('Unknown response format: $map');
}
if (map['error'] != null) {
final value = map['error'];
var error = _rpcExceptionDecoder.tryDecode(value);
if (_errorDecoder != null) {
error ??= _errorDecoder(value);
}
error ??= InternalException('Not recognized error: $error');
throw error as Exception;
} else {
return map['result'];
}
}