1 /// HashGraph basic support functions
2 module tagion.hashgraphview.EventView;
3 
4 import tagion.hashgraph.Event;
5 import tagion.hibon.HiBONRecord;
6 
7 /// EventView is used to store event has a
8 struct EventView {
9     enum eventsName = "$events";
10     uint id;
11     @label("$m") @optional @(filter.Initialized) uint mother;
12     @label("$f") @optional @(filter.Initialized) uint father;
13     @label("$n") size_t node_id;
14     @label("$a") int altitude;
15     @label("$o") int order;
16     @label("$r") long round;
17     @label("$rec") long round_received;
18     @label("$w") @optional @(filter.Initialized) bool witness;
19     @label("$famous") @optional @(filter.Initialized) bool famous;
20     @label("$received") uint[] round_received_mask;
21     @label("$error") @optional bool error;
22     bool father_less;
23 
24     mixin HiBONRecord!(
25             q{
26             this(const Event event, const size_t relocate_node_id=size_t.max) {
27                 import std.algorithm : each;
28                 id=event.id;
29                 if (event.isGrounded) {
30                     mother=father=uint.max;
31                 }
32                 else {
33                     if (event.mother) {
34                         mother=event.mother.id;
35                     }
36                     if (event.father) {
37                         father=event.father.id;
38                     }
39                 }
40                 error=event.error;
41                 node_id=(relocate_node_id is size_t.max)?event.node_id:relocate_node_id;
42                 altitude=event.altitude;
43                 order=event.order;
44                 witness=event.witness !is null;
45                 round=(event.hasRound)?event.round.number:event.round.number.min;
46                 father_less=event.isFatherLess;
47                 if (witness) {
48                     famous = event.round.famous_mask[event.node_id];
49                 }
50                 if (!event.round_received_mask[].empty) {
51                     event.round_received_mask[].each!((n) => round_received_mask~=cast(uint)(n));
52                 }
53                 round_received=(event.round_received)?event.round_received.number:long.min;
54             }
55         });
56 
57 }