UltraDark Core v0.1.0 UltraDark.Blockchain.Block View Source

Link to this section Summary

Functions

The target is a number based off of the block difficulty. The higher the block difficulty, the lower the target. When a block is being mined, the goal is to find a hash that is lower in numerical value than the target. The maximum target (when the difficulty is 0) is 115792089237316195423570985008687907853269984665640564039457584007913129639935, which means any hash is valid

Because the hash is a Base16 string, and not an integer, we must first convert the hash to an integer, and afterwards compare it to the target

When the first node on the UltraDark network spins up, there won’t be any blocks in the chain. In order to create a base from which all nodes can agree, we create a block called a genesis block. This block has the data structure that a block would have, but has hard-coded values. This block never needs to be verified by nodes, as it doesn’t contain any actual data. The block mined after the genesis block must reference the hash of the genesis block as its previous_hash to be valid

Takes the previous block as an argument (This is the way we create every block except the genesis block)

The process of mining consists of hashing the index of the block, the hash of the previous block (thus linking the current and previous block), the timestamp at which the block was generated, the merkle root of the transactions within the block, and a random nonce. We then check to see whether the number represented by the hash is lower than the mining difficulty. If the value of the hash is lower, it is a valid block, and we can broadcast the block to other nodes on the network

Link to this section Functions

Link to this function calculate_block_reward(block_index) View Source
calculate_block_reward(number()) :: number()
Link to this function calculate_target(difficulty) View Source
calculate_target(float()) :: number()

The target is a number based off of the block difficulty. The higher the block difficulty, the lower the target. When a block is being mined, the goal is to find a hash that is lower in numerical value than the target. The maximum target (when the difficulty is 0) is 115792089237316195423570985008687907853269984665640564039457584007913129639935, which means any hash is valid.

Link to this function hash_beat_target?(map) View Source
hash_beat_target?(UltraDark.Blockchain.Block) :: boolean()

Because the hash is a Base16 string, and not an integer, we must first convert the hash to an integer, and afterwards compare it to the target

When the first node on the UltraDark network spins up, there won’t be any blocks in the chain. In order to create a base from which all nodes can agree, we create a block called a genesis block. This block has the data structure that a block would have, but has hard-coded values. This block never needs to be verified by nodes, as it doesn’t contain any actual data. The block mined after the genesis block must reference the hash of the genesis block as its previous_hash to be valid

Link to this function initialize(map) View Source
initialize(UltraDark.Blockchain.Block) :: UltraDark.Blockchain.Block

Takes the previous block as an argument (This is the way we create every block except the genesis block)

Link to this function mine(block) View Source
mine(UltraDark.Blockchain.Block) :: UltraDark.Blockchain.Block

The process of mining consists of hashing the index of the block, the hash of the previous block (thus linking the current and previous block), the timestamp at which the block was generated, the merkle root of the transactions within the block, and a random nonce. We then check to see whether the number represented by the hash is lower than the mining difficulty. If the value of the hash is lower, it is a valid block, and we can broadcast the block to other nodes on the network.

Link to this function total_block_fees(transactions) View Source