GetInfoResponse.deserialize constructor

GetInfoResponse.deserialize(
  1. Map<String, dynamic> input
)

Implementation

factory GetInfoResponse.deserialize(Map<String, dynamic> input) {
  if (!input.containsKey('result')) {
    throw Exception('Invalid input');
  }

  Map<String, dynamic> result = input['result'] as Map<String, dynamic>;
  final methodsList = result["methods"] as List;
  final notificationsList = result["notifications"] as List? ?? [];

  List<String> methods =
      methodsList.map((method) => method.toString()).toList();

  List<String> notifications = notificationsList
      .map((notification) => notification.toString())
      .toList();

  return GetInfoResponse(
      resultType: input['result_type'] as String,
      alias: result['alias'] as String,
      color: result['color'] as String?,
      pubkey: result['pubkey'] as String?,
      network: BitcoinNetwork.fromPlaintext(result['network'] as String?),
      blockHeight: result['block_height'] as int?,
      blockHash: result['block_hash'] as String?,
      methods: methods,
      notifications: notifications);
}