invoke method

Future invoke(
  1. String method,
  2. dynamic params
)

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 rs = await _client.send(
    Request('POST', _endpoint)
      ..body = json.encode(rq)
      ..headers['Content-Type'] = 'application/json',
  );
  final body = await rs.stream.bytesToString();
  final map = json.decode(body) as Map<String, dynamic>;
  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'];
  }
}