C# Class BitSharper.Block

Inheritance: Message
Mostrar archivo Open project: TangibleCryptography/BitSharper Class Usage Examples

Private Properties

Property Type Description
AddCoinbaseTransaction void
AddTransaction void
Block System
BuildMerkleTree IList
CalculateHash Sha256Hash
CalculateMerkleRoot Sha256Hash
CheckMerkleRoot void
CheckProofOfWork bool
CheckTimestamp void
CheckTransactions void
CreateNextBlock Block
Solve void
WriteHeader void

Public Methods

Method Description
BitcoinSerializeToStream ( Stream stream ) : void
Block ( NetworkParameters @params, byte payloadBytes ) : System

Constructs a block object from the BitCoin wire format.

CloneAsHeader ( ) : Block

Returns a copy of the block, but without any transactions.

CreateNextBlock ( Address to ) : Block
Equals ( object o ) : bool
GetDifficultyTargetAsInteger ( ) : BigInteger

Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the target is represented using a compact form. If this form decodes to a value that is out of bounds, an exception is thrown.

GetHashCode ( ) : int
GetWork ( ) : BigInteger

Returns the work represented by this block.

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.

ToString ( ) : string

Returns a multi-line string containing a description of the contents of the block. Use for debugging purposes only.

Verify ( ) : void

Verifies both the header and that the transactions hash to the merkle root.

VerifyHeader ( ) : void

Checks the block data to ensure it follows the rules laid out in the network parameters. Specifically, throws an exception if the proof of work is invalid, if the timestamp is too far from what it should be. This is not everything that is required for a block to be valid, only what is checkable independent of the chain and without a transaction index.

VerifyTransactions ( ) : void

Checks the block contents

Protected Methods

Method Description
Parse ( ) : void

Private Methods

Method Description
AddCoinbaseTransaction ( byte pubKeyTo ) : void

Adds a coinbase transaction to the block. This exists for unit tests.

AddTransaction ( Transaction t ) : void

Adds a transaction to this block.

Block ( NetworkParameters @params ) : System

Special case constructor, used for the genesis node, cloneAsHeader and unit tests.

BuildMerkleTree ( ) : IList
CalculateHash ( ) : Sha256Hash

Calculates the block hash by serializing the block and hashing the resulting bytes.

CalculateMerkleRoot ( ) : Sha256Hash
CheckMerkleRoot ( ) : void
CheckProofOfWork ( bool throwException ) : bool

Returns true if the hash of the block is OK (lower than difficulty target).

CheckTimestamp ( ) : void
CheckTransactions ( ) : void
CreateNextBlock ( Address to, uint time ) : Block

Returns a solved block that builds on top of this one. This exists for unit tests.

Solve ( ) : void

Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but solve() is far too slow to do real mining with. It exists only for unit testing purposes and is not a part of the public API.

This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change extraNonce.

WriteHeader ( Stream stream ) : void

Method Details

BitcoinSerializeToStream() public method

public BitcoinSerializeToStream ( Stream stream ) : void
stream Stream
return void

Block() public method

Constructs a block object from the BitCoin wire format.
public Block ( NetworkParameters @params, byte payloadBytes ) : System
@params NetworkParameters
payloadBytes byte
return System

CloneAsHeader() public method

Returns a copy of the block, but without any transactions.
public CloneAsHeader ( ) : Block
return Block

CreateNextBlock() public method

public CreateNextBlock ( Address to ) : Block
to Address
return Block

Equals() public method

public Equals ( object o ) : bool
o object
return bool

GetDifficultyTargetAsInteger() public method

Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the target is represented using a compact form. If this form decodes to a value that is out of bounds, an exception is thrown.
public GetDifficultyTargetAsInteger ( ) : BigInteger
return Org.BouncyCastle.Math.BigInteger

GetHashCode() public method

public GetHashCode ( ) : int
return int

GetWork() public method

Returns the work represented by this block.
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.
public GetWork ( ) : BigInteger
return Org.BouncyCastle.Math.BigInteger

Parse() protected method

protected Parse ( ) : void
return void

ToString() public method

Returns a multi-line string containing a description of the contents of the block. Use for debugging purposes only.
public ToString ( ) : string
return string

Verify() public method

Verifies both the header and that the transactions hash to the merkle root.
public Verify ( ) : void
return void

VerifyHeader() public method

Checks the block data to ensure it follows the rules laid out in the network parameters. Specifically, throws an exception if the proof of work is invalid, if the timestamp is too far from what it should be. This is not everything that is required for a block to be valid, only what is checkable independent of the chain and without a transaction index.
public VerifyHeader ( ) : void
return void

VerifyTransactions() public method

Checks the block contents
public VerifyTransactions ( ) : void
return void