sendRequest method
Future
sendRequest(
- String topic,
- String method,
- dynamic params, {
- int? id,
- int? ttl,
- EncodeOptions? encodeOptions,
override
Implementation
Future sendRequest(
String topic,
String method,
dynamic params, {
int? id,
int? ttl,
EncodeOptions? encodeOptions,
}) async {
final Map<String, dynamic> payload = JsonRpcUtils.formatJsonRpcRequest(
method,
params,
id: id,
);
// final JsonRpcRequest request = JsonRpcRequest.fromJson(payload);
final String? message = await core.crypto.encode(
topic,
payload,
options: encodeOptions,
);
if (message == null) {
return;
}
RpcOptions opts = MethodConstants.RPC_OPTS[method]!['req']!;
if (ttl != null) {
opts = opts.copyWith(ttl: ttl);
}
// await history.set(
// payload['id'].toString(),
// JsonRpcRecord(
// id: payload['id'],
// topic: topic,
// method: method,
// params: params,
// expiry: WalletConnectUtils.calculateExpiry(
// WalletConnectConstants.ONE_DAY,
// ),
// ),
// );
// print('sent request');
await core.relayClient.publish(
topic: topic,
message: message,
ttl: opts.ttl,
tag: opts.tag,
);
final Completer completer = Completer();
pendingRequests[payload['id']] = completer;
// Get the result from the completer, if it's an error, throw it
try {
final result = await completer.future;
// if (result is JsonRpcError) {
// throw result;
// }
return result;
} catch (e) {
rethrow;
}
}