Event.deserialize constructor
Deserializes an event from a wire-format representation.
input
should be a list containing either two or three elements. If it contains two elements,
the second element should be a map representing the event. If it contains three elements,
the second element should be a string representing the subscriptionId
, and the third element
should be a map representing the event.
Implementation
factory Event.deserialize(List input, {bool verify = true}) {
var json = <String, dynamic>{};
String? subscriptionId;
if (input.length == 2) {
json = input[1] as Map<String, dynamic>;
} else if (input.length == 3) {
json = input[2] as Map<String, dynamic>;
subscriptionId = input[1] as String;
} else {
throw Exception('invalid input');
}
final tags = (json['tags'] as List<dynamic>)
.map((e) => (e as List<dynamic>).map((e) => e as String).toList())
.toList();
return Event(
id: json['id'] as String,
pubkey: json['pubkey'] as String,
created_at: json['created_at'] as int,
kind: json['kind'] as int,
tags: tags,
content: json['content'] as String,
sig: json['sig'] as String,
subscriptionId: subscriptionId,
verify: verify,
);
}