fromJsonStorage static method

RelaySet fromJsonStorage(
  1. Map<String, Object?> json
)

Implementation

static RelaySet fromJsonStorage(Map<String, Object?> json) {
  // Reconstruct relaysMap
  final relaysMapJson = json['relaysMap'] as Map<String, dynamic>? ?? {};
  final relaysMap = <String, List<PubkeyMapping>>{};

  relaysMapJson.forEach((key, value) {
    final mappings = (value as List)
        .map((mapping) => PubkeyMappingExtension.fromJsonStorage(mapping))
        .toList();
    relaysMap[key] = mappings;
  });

  // Reconstruct notCoveredPubkeys
  final notCoveredJson = json['notCoveredPubkeys'] as List? ?? [];
  final notCoveredPubkeys = notCoveredJson
      .map((item) => NotCoveredPubKey(
            item['pubKey'] as String,
            item['coverage'] as int,
          ))
      .toList();

  return RelaySet(
    name: json['name'] as String,
    pubKey: json['pubKey'] as String,
    relayMinCountPerPubkey: json['relayMinCountPerPubkey'] as int? ?? 0,
    direction: RelayDirection.values[json['direction'] as int? ?? 0],
    relaysMap: relaysMap,
    notCoveredPubkeys: notCoveredPubkeys,
    fallbackToBootstrapRelays:
        json['fallbackToBootstrapRelays'] as bool? ?? true,
  );
}