restoreStateFromMap method
Restore state from a map representation Override in subclasses to provide custom map restoration
Implementation
@override
Future<InvoiceState> restoreStateFromMap(Map<String, dynamic> map, int sequenceNumber) async {
DateTime? date(Object? v) => v == null ? null : (v is DateTime ? v : DateTime.parse(v as String));
final invoiceId = map['invoiceId'] as String;
if (invoiceId != aggregateId) {
throw StateError('Snapshot at $sequenceNumber belongs to invoice $invoiceId, not $aggregateId');
}
final outputs = map['outputs'] as List?;
return InvoiceState(
invoiceId: invoiceId,
isCreated: map['isCreated'] as bool,
walletId: map['walletId'] as String,
addresses: [for (final a in map['addresses'] as List) a as String],
amount: BigInt.parse(map['amount'] as String),
outputs: outputs == null
? null
: [
for (final o in outputs)
InvoiceOutputSpec.fromMap(Map<String, dynamic>.from(o as Map)),
],
description: map['description'] as String?,
status: InvoiceStatus.values.byName(map['status'] as String),
createdAt: date(map['createdAt'])!,
expiresAt: date(map['expiresAt']),
paidAt: date(map['paidAt']),
paymentTxid: map['paymentTxid'] as String?,
amountReceived:
map['amountReceived'] == null ? null : BigInt.parse(map['amountReceived'] as String),
metadata: Map<String, dynamic>.from(map['metadata'] as Map? ?? const {}),
version: map['version'] as int,
lastModified: date(map['lastModified']),
);
}