|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.bitcoin.core.Message
com.google.bitcoin.core.Block
public class Block
A block is the foundation of the BitCoin system. It records a set of Transaction
s together with
some data that links it into a place in the global block chain, and proves that a difficult calculation was done
over its contents. See the BitCoin technical paper for more detail on blocks.
To get a block, you can either build one from the raw bytes you can get from another implementation,
or request one specifically using Peer.getBlock(byte[])
, or grab one from a downloaded BlockChain
.
Field Summary | |
---|---|
static int |
HEADER_SIZE
How many bytes are required to represent a block header. |
Fields inherited from class com.google.bitcoin.core.Message |
---|
bytes, cursor, MAX_SIZE, offset, params, protocolVersion |
Constructor Summary | |
---|---|
Block(NetworkParameters params,
byte[] payloadBytes)
Constructs a block object from the BitCoin wire format. |
Method Summary | |
---|---|
Block |
cloneAsHeader()
Returns a copy of the block, but without any transactions. |
boolean |
equals(Object o)
|
long |
getDifficultyTarget()
Returns the difficulty of the proof of work that this block should meet encoded in compact form. |
BigInteger |
getDifficultyTargetAsInteger()
Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. |
byte[] |
getHash()
Returns the hash of the block (which for a valid, solved block should be below the target). |
String |
getHashAsString()
Returns the hash of the block (which for a valid, solved block should be below the target) in the form seen on the block explorer. |
byte[] |
getMerkleRoot()
Returns the merkle root in big endian form, calculating it from transactions if necessary. |
long |
getNonce()
Returns the nonce, an arbitrary value that exists only to make the hash of the block header fall below the difficulty target. |
byte[] |
getPrevBlockHash()
Returns the hash of the previous block in the chain, as defined by the block header. |
long |
getTime()
Returns the time at which the block was solved and broadcast, according to the clock of the solving node. |
long |
getVersion()
Returns the version of the block data structure as defined by the BitCoin protocol. |
BigInteger |
getWork()
Returns the work represented by this block. |
int |
hashCode()
|
String |
toString()
Returns a multi-line string containing a description of the contents of the block. |
void |
verify()
Checks the block data to ensure it follows the rules laid out in the network parameters. |
Methods inherited from class com.google.bitcoin.core.Message |
---|
bitcoinSerialize |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int HEADER_SIZE
Constructor Detail |
---|
public Block(NetworkParameters params, byte[] payloadBytes) throws ProtocolException
ProtocolException
Method Detail |
---|
public String getHashAsString()
public byte[] getHash()
public BigInteger getWork() throws VerificationException
Work is defined as the number of tries needed to solve a block in the average case. Consider a difficulty target that covers 5% of all possible hash values. Then the work of the block will be 20. As the target gets lower, the amount of work goes up.
VerificationException
public Block cloneAsHeader()
public String toString()
toString
in class Object
public BigInteger getDifficultyTargetAsInteger() throws VerificationException
VerificationException
public void verify() throws VerificationException
VerificationException
public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public byte[] getMerkleRoot()
public long getVersion()
public byte[] getPrevBlockHash()
public long getTime()
public long getDifficultyTarget()
BlockChain
verifies that this is not too easy by looking at the length of the chain when the block is
added. To find the actual value the hash should be compared against, use getDifficultyTargetBI.
public long getNonce()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |