Blockchain circle

One stop hot information platform

About us:

Blockchain circle provides the latest information about blockchain, digital currency, digital wallet, exchange, metauniverse, bitcoin, Ethereum, contract, financial management and so on, and always pays attention to the latest market...

Niubi a complete set of Java based blockchain system (with complete source code)

Time : 01/11/2021 Author : d6oxmi Click : + -
        In recent years, the concept of blockchain has become more and more popular. In particular, after blockchain technology was included in the national infrastructure construction list, major enterprises began to recruit people to study blockchain technology. From the perspective of blockchain positions on major recruitment websites, the salary is very good, and the monthly salary is 30K to 80K. This is also an opportunity for our programmers. It shows that it is urgent to learn blockchain technology. Personally, I have been working on the development of blockchain systems since 2016. Recently, many friends around me have asked me to tell them about the development of blockchain technology. In view of this, I just created a simple java blockchain system and wrote a detailed development tutorial and posted it to my blog. I hope it can help my little friends who love blockchain technology to learn the basics.
 
        This set of blockchain system code is very simple and clear, which is very easy for novices to understand. It aims to tell you that the blockchain technology is not so sophisticated and complex. In addition to the springboot framework, the system is basically pure native development. Even the P2P network is realized by using java sockets. From the technical point of view, the blockchain is a data structure in which the blocks containing transaction information are linked in chronological order from the back to the front. From the application level, the blockchain is a distributed shared ledger and database, which is characterized by decentralization, non tampering, full tracking, collective maintenance, openness and transparency.
 
        Based on these characteristics, the blockchain technology can develop a system with the characteristics of trust system to realize collaborative trust and concerted action among multiple agents. The block is the smallest component unit in the blockchain. It is mainly composed of a block header containing metadata and a block body storing one or more transaction information. Each block records the hash of the current block and the hash of the previous block. Through the association of the two hash values, all blocks are connected in a chain structure to form a complete blockchain. The first block in the blockchain is called the genesis block without associating with the previous block. Taking the BTC network as an example, each block mainly contains the following information fields.
 
        The transaction set in the block records some specific information. The BTC network mainly records transaction information. In other blockchain networks, corresponding business data such as audit information, copyright information, bill information, etc. can be saved according to business logic. This is also the reason why blockchain is often used as a shared ledger. For example, the blockchain can be regarded as a notebook for bookkeeping. A block is equivalent to a page of paper on which all accounting information in a certain period of time is recorded. It is a complete account book arranged in the order of page numbers from the first page to the last page. The actual blockchain system is composed of multiple blockchain nodes. Each node runs the same copy of the blockchain backbone network, and each node interacts with each other through the P2P network and finally forms a complete blockchain network system.
 
        P2P network has reliability, decentralization and openness. Each node interacts with each other and cooperates with each other to provide services while also using services provided by other nodes in the network. When a certain blockchain node generates a new block, it will broadcast to other nodes. When other nodes receive the block information through the network, they will verify the block information. When a certain number of nodes pass the verification, each node will update the block to its own existing blockchain, and finally make the information of each node in the whole blockchain network consistent. This is also the decentralization of the blockchain The embodiment of trustworthiness.
 
        Public blockchains) means that any individual or group in the world can send transactions and the transactions can obtain effective confirmation of the blockchain. Anyone can participate in the use and maintenance of the blockchain information. Public blockchain is the earliest blockchain. Virtual digital currencies such as BTC and Ethereum are based on public blockchain. However, at present, the actual application value of the public chain is not great and there is no particularly suitable application scenario. The industry blockchain (Consortium blockchains) specifies multiple preselected nodes within a certain group as bookkeepers. The generation of each block is determined by all preselected nodes. The preselected nodes participate in the consensus process. Other access nodes can participate in the transaction but have permission to restrict the protection of information, such as UnionPay.
 
        At present, alliance chain is the main research object of each blockchain technology team. Because alliance chain has most of the characteristics of blockchain technology and has more advantages in authority management, data security and supervision, it is the blockchain technology solution that enterprises give priority to. There are also some mainstream alliance chain technology frameworks in the market that make it easier to develop and maintain the alliance chain. Some large domestic software manufacturers also have their own enterprise blockchain technology solutions, such as ant financial service blockchain platform, Tencent trustsql platform, Neusoft sacaechotrust blockchain application platform, and JD blockchain anti-counterfeiting and tracing platform. As the soul of the blockchain system, the consensus mechanism is the foundation of the trust system of the blockchain system.
 
        The blockchain system is a multi node distributed ledger system. When there is new information to be recorded, which node is responsible for bookkeeping and which node is responsible for verifying how the bookkeeping results make each node reach a final agreement. The consensus mechanism needs to copy and record the bookkeeping results by all nodes in the network in the same order. The so-called "consensus mechanism" is to complete the verification and confirmation of a transaction in a very short time through the voting of special nodes. If several nodes with unrelated interests can reach a consensus on a transaction, we can think that the whole network can reach a consensus on it. More generally speaking, if a Chinese Weibo big V, an American virtual currency player, an African student and a European traveler do not know each other, but they all agree that you are a good person, then you can basically conclude that you are not bad.
 
        At present, the mainstream consensus algorithms include pow, POS, dpos, pbft, etc. each algorithm has its own advantages and disadvantages in actual use. Different consensus mechanisms and algorithms will be adopted in the time zone block chain project applied to different scenarios. Decentralization is the form of social relations and content generation formed in the development of the Internet. It is a new network content production process relative to "centralization". In a blockchain system with many nodes distributed, each node has a high degree of autonomy. Any node may become a phased center but does not have a mandatory central control function. The influence between nodes will form an association relationship through the network.
 
        This open, flat and equal system phenomenon or structure is called decentralization. The decentralized system has the characteristics of high fault tolerance and strong attack resistance. Once the center of the centralized system has a problem, the whole system will collapse. However, the problem of any node in the blockchain system will not have a great impact on the whole blockchain network. In addition, disintermediation does not mean that supervision is not accepted. The "disintermediation" refers to the central controller and the intermediary rather than the supervisor. The monitoring node can easily access any blockchain network. And because of the open and transparent nature of the blockchain, the regulatory authority can more conveniently monitor the transaction data of the whole system.
 
        Technically speaking, a smart contract is a piece of program code deployed on the blockchain. When the conditions set by the program are met, it will run on the blockchain and get the corresponding results. This situation is somewhat similar to the small program blockchain of wechat, which provides virtual machines and scripting languages. Users develop programs with certain business logic according to the syntax of the scripting language and deploy them on the blockchain. When the execution conditions are met, the smart contract will be interpreted and run by the blockchain virtual machine. The typical application is the smart contract of the Ethereum platform. In this platform, users can realize the contract they want through a few lines of code, and realize the contract that can not be tampered with and runs automatically without human supervision. There is no need to find an intermediary for buying and selling houses, and no need to find a notary for borrowing money & hellip& hellip; People can initiate contracts according to their own needs at any time. Its implementation does not depend on the trust of any person or organization. It is completely based on the Ethereum blockchain platform itself.
 
        Most people are used to calling it "non tamperable", but from the technical level, I personally think it is more appropriate to call it "irreversible". Since it is a computer system, adding, deleting, modifying and checking are basic functional attributes, but the deletion and modification operations of the blockchain system are relatively special. The blockchain is a chain structure in which the hash values of each block are connected in series. The hash value of the block sha256 ("the hash value of the previous block in the current block content") changes in the content of any block will cause changes in the hash value, and changes in the hash value will also cause changes in the hash value of the sub blocks, thereby causing changes in the entire blockchain. Therefore, it is almost impossible for anyone to modify the data of a block unless he modifies all the hash values of the whole blockchain from the creation block to the latest block, and after the modification, he has to broadcast to all other nodes in the network to let all other nodes accept the modification.
 
        However, according to the current computing power of the computer, it is very difficult to modify all of the blockchain from the head to the tail in a short time, and even if the modification is completed, other nodes will not accept the modification because there is no condition for all nodes to reach a consensus on their own. The blockchain 1.0 product is defined as bitcoin zhongbencong. It is an electronic cash system that is completely realized through point-to-point technology. It enables online payment to be directly initiated by one party and paid to the other without any financial institutions. Unlike all currencies, bitcoin does not depend on a specific currency institution to issue it. It generates bitcoin economy through a large number of calculations according to a specific algorithm. It uses a distributed database composed of many nodes in the P2P network to confirm and record all transaction behaviors and uses cryptographic design to ensure the security of all aspects of currency circulation.
 
        After that, people sorted out the blockchain technology system according to the bitcoin network technology to solve the problem of trust, and the principle of bitcoin network has also become a classic textbook for beginners of blockchain technology. Ethereum, the representative of blockchain 2.0 products, is an open-source blockchain platform for decentralized application DAPP. It has the characteristics of most blockchain technologies. However, unlike other blockchains, Ethereum is programmable and developers can use it to build different applications through its special cryptocurrency, Ethereum, or "eth" Providing a decentralized Ethereum virtual machine to handle point-to-point contracts is some script program code.
 
        If the bitcoin network is regarded as a distributed database and Ethereum goes further, it can be regarded as a distributed computer. The blockchain is the ROM contract of the computer and the program. The miners in Ethereum are responsible for computing and play the role of CPU. The concept of Ethereum was first proposed by the programmer vitalik buterin from 2013 to 2014, inspired by bitcoin, to the effect that "the next generation of cryptocurrency and decentralized application platform". Although Ethereum, as a platform, can develop new applications on it, it is unrealistic for the platform to learn, develop and test the blockchain technology and can also be used in actual production because the operation of Ethereum and the BTC network adopt the token mechanism and the platform performance is insufficient and network congestion often occurs.
 
        So far, fabric has been supported by Alibaba, AWS, azure, Baidu, Google, Huawei, IBM, Oracle, Tencent and other Internet giants. Many enterprise blockchain platforms use fabric as the underlying framework, such as Oracle. However, since IBM's definition of blockchain emphasizes the two elements of blockchain distribution and immutability, which weaken the consensus mechanism and adopts Kafka and zookeeper's "sorting service" to achieve consensus, some people in the industry also call the super ledger a "pseudo blockchain". Even so, it can not resist the love of enterprises for the super ledger. At present, fabric2.0 has been officially released.
 
        At present, there are not many business scenarios in the actual application of the public chain. Most of them are based on the theme of mining or online pet breeding games. Moreover, due to the anonymity of digital currency, some lawless elements use it to launder money Illegal activities such as dark network trading are targeted by various countries and are strictly prohibited by China's policies and regulations. Therefore, for technicians, the public chain can be used as the object of research and learning, and other aspects have not much practical significance for the time being. At present, the research direction of most blockchain enterprises is mainly focused on the alliance chain and private chain of enterprises. The national level is also vigorously supporting the development of blockchain technology, especially the research and development of the underlying core technology of blockchain. It advocates to take blockchain as an important breakthrough point for independent innovation of core technology, clarify the main direction of attack, increase investment, strive to overcome a number of key core technologies, and accelerate the development of blockchain technology and industrial innovation.
 
        However, most of the mainstream blockchain platforms in the market are dominated by foreign companies. The development of the underlying core technologies of domestic blockchain still needs the efforts of technicians. At present, the mainstream blockchain technology architecture is mainly divided into five layers. The data layer is the lowest layer. It mainly realizes data storage, account information, transaction information and other modules. The data storage is mainly based on the Merkle tree through the block and chain structure. The account and transaction are based on a variety of cryptographic algorithms and technologies such as digital signature, hash function and asymmetric encryption technology to ensure the security of data in the blockchain. The network layer mainly realizes the connection and communication of network nodes, also known as point-to-point technology. Each blockchain node communicates through the network.
 
        The consensus layer enables all nodes in the network to reach an agreement on the authenticity and correctness of all block data in the network through the consensus algorithm to prevent Byzantine attacks, 51 attacks and other blockchain consensus algorithm attacks. The incentive layer is mainly to realize the issuance and distribution of blockchain tokens. The mechanism is a public chain and we will not analyze it. The application layer generally takes the blockchain system as a platform to implement some decentralized applications on the platform or the smart contract platform provides virtual machines to run these applications. Next, we will develop a small blockchain system based on the Java language to realize some functions of the data layer, network layer and consensus layer. We will use simple code to intuitively abstract concepts so as to deepen our understanding of the basic theory of the above blockchain technology.
 
        Blockchain is the digital summary information obtained by the hash value of the data structure concatenated by the blocks in the order of before and after the hash of the blocks. Those who do not know the hash function can first learn about the Sha algorithm to ensure the information security of the blocks and the effectiveness of the whole blockchain. Therefore, in the second step, we added a method to calculate the hash value of the block, which is implemented by Java using the sha256 algorithm. Step 4: after having the blockchain structure, we need to add a method to add blocks to the blockchain. At the same time, we need to verify the validity of the new block every time we add a block, such as whether the hash value is correct, and whether the hash attribute value of the previous block in the new block is the same as the hash value of the previous block.
 
        After the implementation of the above key codes, we have built a very simple blockchain model, including a basic blockchain model and a blockchain model, and can generate new blocks and add them to the blockchain. Next, we will test. First, after the system is started, check the data in the blockchain to see the data in the current system
 
        
Previous:Tencent's first blockchain game,The first blockchain game is here! The original QQ dance team will launch in July
Next:No more

Related articles:



© 2005-2032 | Blockchain Circle & & All Rights Reserved    Sitemap1 Sitemap2 If there is infringement, please contact us at: