The blockchain was originally a unique way of storing data in cryptocurrencies such as Bitcoin. It is a self-referencing data structure used to store a large amount of transaction information. Each record is linked from the back to the front, and is transparent and transparent. It is impossible to tamper with and is easy to trace. In fact, this feature also directly reflects the characteristics of the entire bitcoin, so the use of blockchain to summarize the technical implementation behind the cryptocurrency is very intuitive and appropriate. Blockchain is a technology. The cryptocurrency is a kind of product (including tokens and blockchain products without tokens) that it develops and cannot be equated or confused. Compared with cryptocurrency, the name of the blockchain abandons the concept of tokens, which is more visual, technical, and depoliticized. It is more suitable as a technology to study and promote.
Blockchain infrastructure modelIn general, a blockchain system consists of a data layer, a network layer, a consensus layer, an incentive layer, a contract layer, and an application layer. The data layer encapsulates the underlying data block and related data encryption and time stamping technologies; the network layer includes a distributed networking mechanism, a data propagation mechanism, and a data verification mechanism; and the consensus layer encapsulates various types of consensus of network nodes. Algorithm; the incentive layer integrates economic factors into the blockchain technology system, mainly including the issuance mechanism and distribution mechanism of economic incentives; the contract layer mainly encapsulates various scripts, algorithms and smart contracts, and is a blockchain programmable feature. The foundation; the application layer encapsulates various application scenarios and cases of the blockchain. In this model, time-stamp-based chain block structure, distributed node consensus mechanism, consensus-based economic incentives and flexible programmable smart contracts are the most representative innovations of blockchain technology.
Blockchain code implementationThe hee node of the hash tree is called the Merkle root. The Merkle tree can check whether any data element is contained in the tree with only the log2(N) time complexity:
Package test;
Import java.security.MessageDigest;
Import java.uTIl.ArrayList;
Import java.uTIl.List;
Public class MerkleTrees {
// transacTIon List
List "String" txList;
// Merkle Root
String root;
/**
* constructor
* @param txList transacTIon List Transaction List
*/
Public MerkleTrees(List "String" txList) {
this.txList = txList;
Root = "";
}
/**
* execute merkle_tree and set root.
*/
Public void merkle_tree() {
List "String" tempTxList = new ArrayList "String" ();
For (int i = 0; i " this.txList.size(); i++) {
tempTxList.add(this.txList.get(i));
}
List "String" newTxList = getNewTxList(tempTxList);
While (newTxList.size() != 1) {
newTxList = getNewTxList(newTxList);
}
This.root = newTxList.get(0);
}
/**
* return Node Hash List.
* @param tempTxList
* @return
*/
Private List "String" getNewTxList(List "String" tempTxList) {
List "String" newTxList = new ArrayList "String" ();
Int index = 0;
While (index " tempTxList.size()) {
// left
String left = tempTxList.get(index);
Index++;
// right
String right = "";
If (index != tempTxList.size()) {
Right = tempTxList.get(index);
}
// sha2 hex value
String sha2HexValue = getSHA2HexValue(left + right);
newTxList.add(sha2HexValue);
Index++;
}
Return newTxList;
}
/**
* Return hex string
* @param str
* @return
*/
Public String getSHA2HexValue(String str) {
Byte[] cipher_byte;
Try{
MessageDigest md = MessageDigest.getInstance("SHA-256");
Md.update(str.getBytes());
Cipher_byte = md.digest();
StringBuilder sb = new StringBuilder(2 * cipher_byte.length);
For(byte b: cipher_byte) {
Sb.append(String.format("%02x", b&0xff) );
}
Return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
Return "";
}
/**
* Get Root
* @return
*/
Public String getRoot() {
Return this.root;
}
}
We are professional audio manufacturing company that makes a variety of speaker with bluetooth, including bluetooth portable speaker, bluetooth speakers outdoor, small speaker bluetooth, light bluetooth speakers, waterproof speakers etc.
With full turnkey service from product design to delivery, and every step in between.
From sophisticated custom audio systems to 'off-the-shelf' speaker drivers, iTopnoo has been saving our customers time, effort, and money.
To constantly offer clients more innovative products and better services is our consistent pursuit.
Best Portable Speakers,customizable bluetooth speaker, Custom jbl speakers, speaker wholesalers
TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.mic11.com