forked from Echo-Mirror-Butler/echomirror-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_models.dart
More file actions
91 lines (77 loc) · 2.56 KB
/
Copy pathsync_models.dart
File metadata and controls
91 lines (77 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// ── Sync cursor ───────────────────────────────────────────────────────────────
class SyncCursor {
final int ledgerSequence;
final String pagingToken;
final DateTime lastSyncedAt;
final int totalProcessed;
const SyncCursor({
required this.ledgerSequence,
required this.pagingToken,
required this.lastSyncedAt,
required this.totalProcessed,
});
factory SyncCursor.genesis() => SyncCursor(
ledgerSequence: 0,
pagingToken: 'now',
lastSyncedAt: DateTime.now(),
totalProcessed: 0,
);
Map<String, dynamic> toJson() => {
'ledger_sequence': ledgerSequence,
'paging_token': pagingToken,
'last_synced_at': lastSyncedAt.toIso8601String(),
'total_processed': totalProcessed,
};
factory SyncCursor.fromJson(Map<String, dynamic> json) => SyncCursor(
ledgerSequence: json['ledger_sequence'] as int,
pagingToken: json['paging_token'] as String,
lastSyncedAt: DateTime.parse(json['last_synced_at'] as String),
totalProcessed: json['total_processed'] as int,
);
}
// ── Sync events ───────────────────────────────────────────────────────────────
abstract class SyncEventBase {
const SyncEventBase();
}
class TransactionSyncEvent extends SyncEventBase {
final String txId;
final String from;
final String to;
final String asset;
final String amount;
final String? memo;
final int ledgerSequence;
final String pagingToken;
const TransactionSyncEvent({
required this.txId,
required this.from,
required this.to,
required this.asset,
required this.amount,
this.memo,
required this.ledgerSequence,
required this.pagingToken,
});
}
class LedgerSyncEvent extends SyncEventBase {
final int ledgerSequence;
final String txHash;
final String pagingToken;
const LedgerSyncEvent({
required this.ledgerSequence,
required this.txHash,
required this.pagingToken,
});
}
class ErrorSyncEvent extends SyncEventBase {
final String message;
const ErrorSyncEvent({required this.message});
}
class SyncStartedEvent extends SyncEventBase {
final int fromLedger;
const SyncStartedEvent({required this.fromLedger});
}
class SyncCompletedEvent extends SyncEventBase {
final int totalProcessed;
const SyncCompletedEvent({required this.totalProcessed});
}