serialized method

String serialized({
  1. String? subscriptionId,
})

Serialize the request to send it to the remote relays websockets.

Implementation

String serialized({String? subscriptionId}) {
  this.subscriptionId = subscriptionId ??
      this.subscriptionId ??
      Nostr.instance.utilsService.consistent64HexChars(
        filters
            .map((e) => e.toMap().toString())
            .reduce((value, element) => value + element),
      );

  //! The old way of doing it is commented below
  // final decodedFilters =
  //     jsonEncode(filters.map((item) => item.toMap()).toList());
  // final header = jsonEncode([NostrConstants.request, subscriptionId]);
  // final result =
  //     '${header.substring(0, header.length - 1)},${decodedFilters.substring(1, decodedFilters.length)}';

  final encodedReq = jsonEncode([
    NostrConstants.request,
    subscriptionId,
    ...filters.map((e) => e.toMap()),
  ]);

  return encodedReq;
}