1 /// \EpochChainBlock.d 2 module tagion.epochain.EpochChainBlock; 3 4 import tagion.basic.Types : Buffer, FileExtension; 5 import tagion.crypto.SecureInterfaceNet : HashNet; 6 import tagion.crypto.Types : Fingerprint; 7 import tagion.hashchain.HashChainBlock : HashChainBlock; 8 import tagion.hibon.Document; 9 import tagion.hibon.HiBONJSON : JSONString; 10 import tagion.hibon.HiBONRecord : HiBONRecord, exclude, label, recordType; 11 12 /** @brief File contains class EpochChainBlock 13 */ 14 15 /** 16 * \class EpochChainBlock 17 * Class represents epoch block from recorder chain 18 */ 19 20 @recordType("EpochBlock") 21 @safe class EpochChainBlock : HashChainBlock { 22 /** Fingerprint of this block */ 23 @exclude Fingerprint fingerprint; 24 /** Bullseye of DART database */ 25 @label("eye") Fingerprint bullseye; 26 /** Fingerprint of the previous block */ 27 @label("previous") Fingerprint previous; 28 /** List of the transactions */ 29 @label("transactions_list") Document transactions_list; 30 31 mixin JSONString; 32 33 /** Ctor creates block from recorder, previous hash and bullseye. 34 * @param transactions - Document with list of transactions 35 * @param previous - fingerprint of the previous block 36 * @param bullseye - bullseye of database 37 * @param net - hash net 38 */ 39 mixin HiBONRecord!( 40 q{ 41 private this( 42 Document transactions, 43 Fingerprint previous, 44 Fingerprint bullseye, 45 const(HashNet) net) 46 { 47 this.transactions_list = transactions; 48 this.previous = previous; 49 this.bullseye = bullseye; 50 51 this.fingerprint = net.calcHash(toDoc); 52 } 53 54 private this( 55 const(Document) doc, 56 const(HashNet) net) 57 { 58 this(doc); 59 this.fingerprint = net.calcHash(toDoc); 60 } 61 }); 62 63 Fingerprint getHash() const { 64 return this.fingerprint; 65 } 66 67 Fingerprint getPrevious() const { 68 return this.previous; 69 } 70 } 71 72 unittest { 73 import std.range : empty; 74 import tagion.crypto.SecureNet : StdHashNet; 75 76 /// EpochChainBlock_check_getters 77 { 78 import tagion.crypto.SecureNet : StdHashNet; 79 80 auto hasher = new StdHashNet; 81 Fingerprint bullseye = [1, 2, 3, 4]; 82 Fingerprint prev; 83 auto doc = Document(); 84 auto item_one = new EpochChainBlock(doc, prev, bullseye, hasher); 85 86 assert(item_one.bullseye == bullseye); 87 assert(item_one.getPrevious.empty); 88 assert(hasher.calcHash(item_one.toDoc) == item_one.getHash()); 89 } 90 91 }