IBlock
ChangeBlock
, OpenBlock
, ReceiveBlock
, SendBlock
, StateBlock
public abstract class Block extends Object implements IBlock
For a concrete version of this class, use StateBlock
(or SendBlock
, ReceiveBlock
,
ChangeBlock
and OpenBlock
for legacy types).
To convert a JSON string/object to a Block instance, use the parse(JsonObject)
static method or the
BlockDeserializer
class. This class can automatically be serialized and deserialized by Gson, as a
built-in JSON adapter is provided and automatically registered.
Modifier and Type | Field | Description |
---|---|---|
protected static int |
HASH_LENGTH |
Modifier | Constructor | Description |
---|---|---|
protected |
Block(String type) |
|
protected |
Block(String type,
String hash,
String signature,
WorkSolution workSolution) |
|
protected |
Block(BlockType type) |
|
protected |
Block(BlockType type,
String hash,
String signature,
WorkSolution workSolution) |
Modifier and Type | Method | Description |
---|---|---|
protected com.google.gson.JsonObject |
buildJsonObject() |
Build a JsonObject that represents this instance.
|
protected byte[] |
calculateHashBytes() |
|
boolean |
equals(Object o) |
|
protected void |
fillJsonBlanks(com.google.gson.JsonObject json) |
Fill blank or missing parameters with
JsonObject.addProperty(String, String) . |
protected abstract byte[][] |
generateHashables() |
|
String |
getHash() |
Returns the block hash, or attempts to calculate it if the hash value was not present.
|
byte[] |
getHashBytes() |
|
com.google.gson.JsonObject |
getJsonObject() |
|
com.google.gson.JsonObject |
getJsonObject(boolean fillBlanks) |
|
String |
getSignature() |
|
BlockType |
getType() |
|
String |
getTypeString() |
|
WorkSolution |
getWorkSolution() |
|
int |
hashCode() |
|
boolean |
isComplete() |
Returns whether or not this object contains all the necessary fields to be a block.
|
static Block |
parse(com.google.gson.JsonObject json) |
Parses a block from a given
JsonObject instance. |
static Block |
parse(String json) |
Parses a block from a given JSON string.
|
String |
toJsonString() |
|
String |
toJsonString(boolean fillBlanks) |
|
String |
toString() |
protected static final int HASH_LENGTH
protected Block(String type)
type
- the block type, as a stringprotected Block(BlockType type)
type
- the block typeprotected Block(String type, String hash, String signature, WorkSolution workSolution)
type
- the block type, as a stringhash
- the block hash, or null (for performance improvements only)signature
- the block signatureworkSolution
- the work solutionprotected Block(BlockType type, String hash, String signature, WorkSolution workSolution)
type
- the block typehash
- the block hash, or null (for performance improvements only)signature
- the block signatureworkSolution
- the work solutionpublic final String getHash()
public final byte[] getHashBytes()
public final BlockType getType()
public final String getTypeString()
getTypeString
in interface IBlock
public final String getSignature()
getSignature
in interface IBlock
public final WorkSolution getWorkSolution()
getWorkSolution
in interface IBlock
public boolean isComplete()
protected abstract byte[][] generateHashables()
protected final byte[] calculateHashBytes()
public final String toJsonString()
public final String toJsonString(boolean fillBlanks)
fillBlanks
- if true, null properties will be filled with dummy datapublic final com.google.gson.JsonObject getJsonObject()
JsonObject
public final com.google.gson.JsonObject getJsonObject(boolean fillBlanks)
fillBlanks
- if true, null properties will be filled with dummy dataJsonObject
protected void fillJsonBlanks(com.google.gson.JsonObject json)
JsonObject.addProperty(String, String)
.json
- the JSON object to fillprotected com.google.gson.JsonObject buildJsonObject()
public static Block parse(String json)
json
- the json to parse fromBlockDeserializer
public static Block parse(com.google.gson.JsonObject json)
JsonObject
instance.json
- the json to parse fromBlockDeserializer
Copyright © 2020. All rights reserved.