1 module tagion.Keywords;
2 
3 private import tagion.basic.basic : EnumText;
4 
5 // Keyword list for the HiBON packages
6 protected static immutable _keywords = [
7     "pubkey",
8     "signature", // signature of the block
9     //    "altitude",
10     "order",
11     // "tidewave",
12     // "wavefront",  // Wave front is the list of events hashs
13     // "ebody",      // Event body
14     // "event",      // Event including the eventbody
15 
16     // HashGraph
17     "message",
18     "mother",
19     "father",
20     "daughter",
21     "son",
22     "payload",
23     "channel",
24     "witness",
25     // "witness_mask",
26     "round_mask",
27     "round_seen",
28     "round_received",
29     "coin",
30     "decided",
31     "decided_count",
32     // "total",
33     // "decided_mask",
34     "famous",
35     "famous_votes",
36     "round",
37     "number",
38     "remove",
39     "forked",
40     "strongly_seeing",
41     "strong_votes",
42     "strong_mask",
43     "iterations",
44     //    "altenative",
45     "looked_at_mask",
46     "looked_at_count",
47     "seeing_completed",
48     "completed",
49     "epoch",
50     "list",
51     "time",
52     "events", // List of event
53     "type", // Package type
54     //    "block",     // block
55 
56     "rim",
57     "buckets",
58     "tab",
59     "transaction_id",
60     "output",
61     "signatures",
62     //    "signatur",
63     "transaction_object",
64     "transaction_scripting_object",
65     "payers",
66     "payees",
67     "input_bills",
68     "output_bills",
69     "bill",
70     "bill_number",
71     "bill_body",
72     "bill_type",
73     "value",
74     "ownerkey",
75 
76     // FixMe should be change to "result" and "error" to fit the HiRPC
77     "result_code",
78     "error_code",
79 
80     // Scripting
81     "code",
82     "source",
83 
84     // DART
85     // "indices",
86     "fingerprint",
87     // "fingerprints",
88     "archives",
89     "branches",
90     "read",
91     "rims",
92     "keys",
93 
94     // HiRPC (Similar to JSON-RPC 2.0)
95     // "rev",
96     "method",
97     "params",
98     "error", // error_code
99     "result",
100     "id",
101     "data",
102     "hirpc"
103 ];
104 
105 // Generated the Keywords and enum string list
106 mixin(EnumText!("Keywords", _keywords));
107 
108 /++
109  Check if the CTE string $(LREF word) belongs to $(LREF K) string enum
110 +/
111 template isValid(K, string word) if (is(K == enum)) {
112     enum code = "K." ~ word;
113     enum isValid = __traits(compiles, mixin(code));
114 }
115 
116 static unittest {
117     import std.traits : EnumMembers;
118 
119     enum allkeys = EnumMembers!Keywords;
120     enum kmin = allkeys[0];
121     enum kmax = allkeys[$ - 1];
122     enum kmid = allkeys[$ / 2];
123     static assert(isValid!(Keywords, kmin));
124     static assert(isValid!(Keywords, kmax));
125     static assert(isValid!(Keywords, kmid));
126     static assert(!isValid!(Keywords, "xxx"));
127 }