|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectme.edwards.des.block.Block
public class Block
Data Structure containing information for a Block. The Block is the main unit
of storage for the system. Blocks are generated and propagated through Nodes
and store a payload of Ballots
.
These Ballots are tied to the Block via a
Merkle Root
, preventing
any Ballot in the payload from being changed. The Block also contains the
hash of the Block before it in the BlockChain
, which
allows for backwards-linking in the BlockChain. The Block contains a
timestamp and target for mining by a Node
.
Every Block is secured using a Proof of Work
, preventing changes after the Block is generated. Any change
(even a single bit) in a Ballot or Block attribute will change the overall
hash
of the Block, which will be invalid unless the
nonce is changed. The nonce can only be changed to a value which makes the
hash valid by re-mining the Block and regenerating a new Proof of Work.
Created on: Nov 1, 2015 at 3:09:17 PM
Field Summary | |
---|---|
private java.util.ArrayList<Ballot> |
ballots
|
private byte[] |
headerBytes
|
static int |
MAXIMUM_TARGET
Maximum Target value for DES |
private java.lang.String |
merkleRootHash
|
private byte[] |
myBytes
|
private java.lang.String |
myHash
|
private int |
nonce
|
private java.lang.String |
prevBlockHash
|
private int |
target
|
private int |
time
|
private boolean |
valid
|
private int |
version
|
private int |
VERSION
|
Constructor Summary | |
---|---|
Block(byte[] binary)
Initializes Block from binary data as a byte array. |
|
Block(java.lang.String prevBlockHash,
int target,
java.util.ArrayList<Ballot> ballots)
Creates new Block using the hash from its parent Block, a target (in short-format), and a list of ballots. |
Method Summary | |
---|---|
private void |
genBytes()
Populates headerBytes with this Block's data. |
void |
genProof()
Generates a Proof of Work for
this block and validates the Block's contents. |
java.util.ArrayList<Ballot> |
getBallots()
Returns a list of the Ballots contained by this Block. |
byte[] |
getBytes()
Returns the Block in binary format as a byte array. |
static double |
getDifficulty(int target)
Returns the difficulty of the specified target. The difficulty is calculated by DIFFICULTY = MAXIMUM_TARGET / SPECIFIED_TARGET This method uses exponent reduction to more accurately calculate the difficulty of a target. |
java.lang.String |
getHash()
Returns the hash of the header for this Block. |
private java.lang.String |
getMerkleRoot(int depth,
int position)
Generates the Merkle Root of the list of Ballots contained in this Block. |
java.lang.String |
getPrevHash()
Returns the hash for this Block's parent. |
int |
getTarget()
Returns the target (in Short-Format) of this Block. |
static int |
getTarget(java.math.BigInteger target)
Returns the specified target in Short-Format. |
static java.math.BigInteger |
getTarget(int target)
Returns the specified target as a BigInteger. |
int |
getTime()
Returns the time when this Block was mined. |
java.lang.String |
toString()
|
boolean |
validate()
Validates this Block's data and resets the valid
flag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAXIMUM_TARGET
private final int VERSION
private int version
private java.lang.String prevBlockHash
private java.lang.String merkleRootHash
private int time
private int target
private int nonce
private java.util.ArrayList<Ballot> ballots
private byte[] headerBytes
private byte[] myBytes
private java.lang.String myHash
private boolean valid
Constructor Detail |
---|
public Block(java.lang.String prevBlockHash, int target, java.util.ArrayList<Ballot> ballots)
prevBlockHash
- 256-bit hash of the previous block in the chaintarget
- Short-Format target for hashesballots
- A list of votes to be included in this blockpublic Block(byte[] binary)
Nodes
and Blocks
to load Blocks.
binary
- Byte array representing this BlockMethod Detail |
---|
public java.lang.String getHash()
public java.lang.String getPrevHash()
getHash()
public void genProof() throws java.lang.InterruptedException
Proof of Work
for
this block and validates the Block's contents. If the block is already
valid, this method will return.
java.lang.InterruptedException
- Thrown if the Thread is interrupted by
Node.stopBlockGeneration().private java.lang.String getMerkleRoot(int depth, int position)
getMerkleRoot(0, 0);
and it will recurse to get the root of the entire list.
depth
- Depth of the Merkle Tree on this recursive stepposition
- Index of the Ballot composing the first child of the Merkle
Tree node returned by this method
private void genBytes()
public byte[] getBytes()
public java.util.ArrayList<Ballot> getBallots()
Ballots
contained by this Block.
public int getTime()
public int getTarget()
public boolean validate()
valid
flag.
HashUtil.validateProof(byte[], int, int)
public java.lang.String toString()
toString
in class java.lang.Object
public static java.math.BigInteger getTarget(int target)
target
- Short-Format target
public static int getTarget(java.math.BigInteger target)
target
- BigInteger target
public static double getDifficulty(int target)
DIFFICULTY = MAXIMUM_TARGET / SPECIFIED_TARGET
target
- Short-Format target
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |