-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.java
More file actions
36 lines (31 loc) · 912 Bytes
/
Entity.java
File metadata and controls
36 lines (31 loc) · 912 Bytes
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
package model;
import java.io.Serializable;
import crypto.Sha3256Hasher;
import model.codec.EncodedEntity;
import model.crypto.Hash;
import model.lightchain.Identifier;
import modules.codec.JsonEncoder;
/**
* Entity represents the unit of data model in LightChain. Everything meant to be sent over the network, stored
* in memory, or a database must extend the Entity class.
*/
public abstract class Entity implements Serializable {
/**
* Computes the collision resistant hash value of entity.
*
* @return identifier representation of hash value for entity.
*/
public Identifier id() {
JsonEncoder c = new JsonEncoder();
EncodedEntity e = c.encode(this);
Sha3256Hasher h = new Sha3256Hasher();
Hash hash = h.computeHash(e);
return hash.toIdentifier();
}
/**
* Type of this entity.
*
* @return type of this entity.
*/
public abstract String type();
}