|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectme.edwards.des.block.BlockChain
public class BlockChain
Data structure to maintain Blocks
in the BlockChain. Blocks can
be randomly appended to the BlockChain using
append(Block) and will be put into the correct order
to form a continuous tree of Blocks backwards-linked through the
previous hash
fields. The BlockChain maintains a
queue of orphan Blocks to ensure that Blocks received by the Node
out-of-order in the tree can be appended to the BlockChain correctly. The
BlockChain also maintains a list of all the Blocks acting as leaves on the
top of the tree, but will always choose the longest continuous chain of
Blocks as the main chain.
The branching abilities of the BlockChain provide the mechanism of the
network to "vote" on valid Blocks and come to a consensus of what the "real"
BlockChain is. Blocks that are generated and deemed valid are added to the
BlockChain while invalid Blocks will never be added to the BlockChain. When
two valid Blocks with the same parent are added to the BlockChain, a branch
is created, which may cause a split in the network. Further explanation
provided with append(Block).
Created on: Nov 2, 2015 at 2:23:14 PM
Nested Class Summary | |
---|---|
class |
BlockChain.Node
Represents a tree node in the BlockChain Created on: Dec 21, 2015 at 5:20:30 PM |
Field Summary | |
---|---|
static int |
BLOCK_GOAL
The goal time for ten Blocks to be mined, in minutes. |
static int |
MAXIMUM_BLOCK_SIZE
The maximum size, in bytes, that a Block may be |
private java.util.ArrayList<Block> |
queue
|
private BlockChain.Node |
top
|
private java.util.ArrayList<BlockChain.Node> |
topList
|
Constructor Summary | |
---|---|
BlockChain(Block genesis)
Creates new BlockChain with the first Block (the Genesis
Block). |
|
BlockChain(int size,
byte[][] binary)
Initializes BlockChain from binary data as a byte array. |
Method Summary | |
---|---|
void |
append(Block block)
Queues the specified Block to be added to this BlockChain. |
boolean |
contains(java.lang.String hash)
Returns true if the specified hash belongs to a Block in
this BlockChain. |
Block |
get(java.lang.String hash)
Returns the Block in this BlockChain with the specified
hash. |
byte[][] |
getBytes()
Returns the BlockChain in binary format as a chunk array. |
int |
getCurrentTarget()
Returns the current target of the BlockChain. |
long |
getMedianTime(java.lang.String hash)
Returns the Median Time of the last 10 (or available) Blocks. |
BlockChain.Node |
getNode(java.lang.String hash)
Returns the node in this BlockChain containing the Block
with the specified hash. |
int |
getSize()
Returns the number of Blocks in the longest branch in this
BlockChain |
Block |
getTop()
Returns the Block on the top of the longest branch in this
BlockChain. |
boolean |
hasBallot(java.lang.String hash,
java.lang.String uuid)
Returns True if the specified Ballot is contained in the longest branch of this BlockChain. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAXIMUM_BLOCK_SIZE
public static final int BLOCK_GOAL
private BlockChain.Node top
private java.util.ArrayList<Block> queue
private java.util.ArrayList<BlockChain.Node> topList
Constructor Detail |
---|
public BlockChain(Block genesis)
Block
(the Genesis
Block). This constructor is only used when the Node is starting a new
BlockChain, otherwise the BlockChain is downloaded from a peer Node or
loaded from file.
genesis
- First Block in the new BlockChainpublic BlockChain(int size, byte[][] binary)
size
- Number of chunks in which this BlockChain was savedbinary
- Loaded array of chunks (byte arrays containing Blocks
) representing this BlockChainMethod Detail |
---|
public byte[][] getBytes()
Blocks
)
representing this BlockChainpublic Block getTop()
Block
on the top of the longest branch in this
BlockChain.
public int getSize()
Blocks
in the longest branch in this
BlockChain
public void append(Block block)
Block
to be added to this BlockChain.
This method accepts orphan Blocks (a Block whose parent is not contained
in the BlockChain), child Blocks of the main chain, and child Blocks of
branch chains. The algorithm for appending Blocks allows for branching of
the BlockChain, and resolution of Blocks to form a consensus between
Nodes.
block
- Block to be added to this BlockChainpublic boolean contains(java.lang.String hash)
Block
in
this BlockChain.
hash
- Block's 32-digit hexadecimal hash
public Block get(java.lang.String hash)
Block
in this BlockChain with the specified
hash.
hash
- Block's 32-digit hexadecimal hash
public BlockChain.Node getNode(java.lang.String hash)
node
in this BlockChain containing the Block
with the specified hash.
hash
- Block's 32-digit hexadecimal hash
public long getMedianTime(java.lang.String hash)
hash
- Hash of the Block at which to begin
public boolean hasBallot(java.lang.String hash, java.lang.String uuid)
hash
- Parent hash of the Block containing this ballot.uuid
- UUID of the Ballot
public int getCurrentTarget()
goal difference
.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |