2023-08-28 17:58:05 +00:00
|
|
|
import { NostrEvent } from "./lib/nostr-ts/nostr.ts";
|
2023-06-30 14:05:57 +00:00
|
|
|
import { getTags } from "./nostr.ts";
|
|
|
|
|
|
|
|
export class LamportTime {
|
2023-11-25 14:29:50 +00:00
|
|
|
private time = 0;
|
2023-11-18 17:11:07 +00:00
|
|
|
|
2023-11-25 14:29:50 +00:00
|
|
|
fromEvents(events: Iterable<NostrEvent>) {
|
2023-11-18 17:11:07 +00:00
|
|
|
for (const event of events) {
|
|
|
|
const ts = getTags(event).lamport_timestamp;
|
2023-11-25 14:29:50 +00:00
|
|
|
if (ts) {
|
|
|
|
this.set(ts);
|
2023-11-18 17:11:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 14:05:57 +00:00
|
|
|
now() {
|
|
|
|
this.time++;
|
|
|
|
return this.time;
|
|
|
|
}
|
|
|
|
set(t: number) {
|
|
|
|
this.time = Math.max(this.time, t);
|
|
|
|
}
|
|
|
|
}
|