Extras din laborator
Blockchain consists of blocks of data connected through the use of cryptography. It belongs to a network of nodes connected over the public network.
The fundamental units of a blockchain are blocks. A single block can encapsulate several transactions or other valuable data:
Fig. 1. Transactions inside a single block
Generating the hash value of a block is called “mining” the block. The hash of a block typically consists of the following data:
- Primarily, the hash of a block consists of the transactions it encapsulates
- The hash also consists of the timestamp of the block's creation
- It also includes a nonce, an arbitrary number used in cryptography
- Finally, the hash of the current block also includes the hash of the previous block
All nodes in the network participate in verifying a newly mined block.
Fig. 2. Adding a block into Blockchain
A newly mined block is added into the blockchain on the consensus of the nodes. There are several consensus protocols available which we can use for verification. The nodes in the network use the same protocol to detect malicious branch of the chain. Hence, a malicious branch even if introduced will soon be rejected by the majority of the nodes.
Consider the following block implementation:
public class Block {
private String hash;
private String previousHash;
private String data;
private long timeStamp;
private int nonce;
public Block(String data, String previousHash, long timeStamp) { this.data = data;
this.previousHash = previousHash;
this.timeStamp = timeStamp;
this.hash = calculateBlockHash();
}
// standard getters and setters
}
Where:
- Hash of the previous block, an important part to build the chain
- The actual data, any information having value, like a contract
- The timestamp of the creation of this block
- A nonce, which is an arbitrary number used in cryptography
- Finally, the hash of this block, calculated based on other data
Preview document
Conținut arhivă zip
- Blockchain tutorial.doc