sendRequest method
Implementation
Future sendRequest(
String topic,
String method,
Map<String, dynamic> params, {
int? id,
}) async {
final Map<String, dynamic> payload = PairingUtils.formatJsonRpcRequest(
method,
params,
id: id,
);
final JsonRpcRequest request = JsonRpcRequest.fromJson(payload);
final String message = await core.crypto.encode(topic, payload);
final RpcOptions opts =
RPCConstants.PAIRING_RPC_OPTS[method]['req'] as RpcOptions;
await core.history.set(
topic,
request,
);
// print('sent request');
await core.relayClient.publish(topic, message, opts.ttl);
final Completer completer = Completer.sync();
pendingRequests[payload['id']] = completer;
// Get the result from the completer, if it's an error, throw it
final result = await completer.future;
if (result is JsonRpcError) {
throw result;
}
return result;
}