Hyperledger-Super Ledger study report

Source: Internet
Author: User
Tags curl json git clone hyperledger fabric

Hyperledger-Super Ledger study report

first, what is blockchain.

The fundamentals of the blockchain, the basic components include:

Trade: Changes in the state of the ledger;

Block: Record transactions and status, is a confirmation of the status of the current ledger;

Chains: Logging of state changes.

When a blockchain is used as a state machine, each transaction is an attempt to change the state, and each time a block is generated, the participant confirms the result of the change in status of all the transactions included.

three development projects currently in the blockchain:

Category:

Public chain: Anyone can participate in the use and maintenance, typically such as Bitcoin blockchain, information is completely public.

With the introduction of a licensing mechanism, private and federated chains (consortium) are generated,

Private chain: Centralized manager to restrict, only get the internal minority can use, information is not public.

Alliance chain: between the public chain and the private chain, by a number of organizations to work together to maintain a blockchain, the use of the blockchain must be a privileged management, the relevant information will be protected, typically such as the UnionPay organization.

second, what is Hyperledger.

In December 2015, the Linux Foundation led the founding of the Hyperledger project jointly with 30 initial members.

The emergence of the project, in fact, announced that blockchain technology is not simply an open source technology, has been formally recognized by mainstream organizations and markets, at the same time, Hyperledger first proposed and implemented a complete authority management, innovative consistency algorithm and pluggable framework, The development of blockchain-related technologies and industries will have a far-reaching impact.

There are currently two sub-projects of fabric and Sawtooth Lake.

fabric: Including fabric and FABRIC-API, the target is the blockchain's underlying core platform, supporting new consensus mechanisms such as PBFT, and enabling rights management, initiated by IBM and DAH at the earliest.

sawtooth Lake: including arcade, Core, Dev-tools, validator, mktplace, etc. Is Intel's main contribution and leading blockchain platform, supporting a new consensus mechanism Proof of Elapsed time (poet).

III. installation and deployment of the Hyperledger fabric project.

System: The latest version of Linux, eg.ubuntu16.04 can be, the official website can be under.

① Installing Docker

Ubuntu Advanced version comes with installation package, execute command

# apt-get-y Install Docker.io

#sudo Docker Version//view versions

② installation Docker-compose

First, install Pip

# sudo aptitude install Python-pip

Installing Docker-compose

# sudo pip install Docker-compose

③ Download the relevant Docker image and configure it. Mirror Address Https://hub.docker.com/r/yeasy/hyperledger

Of course, you can also download the official GitHub.

# Docker Pull Yeasy/hyperledger:latest

# Docker Tag Yeasy/hyperledger:latest hyperledger/fabric-baseimage:latest

# Docker Pull Yeasy/hyperledger-peer:latest

# Docker Pull Yeasy/hyperledger-membersrvc:latest

④ using PBFT mode

PBFT is a classic distributed consistency algorithm and is also the most recommended algorithm for Hyperledger, which requires at least 4 nodes.

First, download the compose file.

# git clone https://github.com/yeasy/docker-compose-files

A Docker-compose-files folder is now available in the directory.

(1) using the CLI test

Manually Start Docker-daemon

#service Docker Stop

#sudo Docker Daemon--api-cors-header= "*"-H tcp://0.0.0.0:2375-h unix:///var/run/do

Cker.sock

Enter the Hyperledger project and start the cluster.

# CD Docker-compose-files/hyperledger

# Docker-compose up

This generates four nodes, VP0,VP1,VP2,VP3.

Enter Node Vp0

#docker exec-it vp0 Bash

Deployment of two accounts A, a, 100 and 200 are allocated respectively.

#peer Chaincode deploy-p github.com/hyperledger/fabric/examples/chaincode/go/

Chaincode_example02-c ' {"Function": "Init", "Args": ["a", "+", "B", "200"]} '

Returns Core_chaincode_id_name (a string of addresses),

In the following form:

a5389f7dfb9efae379900a41db1503fea2199fe400272b61ac5fe7bd0c6b97cf10ce3aa8dd00cd7626ce02f18accc7e5f2059dae6eb07868380429583 52b89fb

Check your account balance

#peer chaincode query-n core_chaincode_id_name-c ' {"Function": "Query", "Args": ["a"]} '

should return 100

To trade

Peer Chaincode invoke-n core_chaincode_id_name-c ' {"Function": "Invoke", "Args": ["a", "B", "10"]} '

After the transaction a reduced 10,b increased by 10.

The verification transaction results can be queried again.

(2) Post rest test

Note: Post testing can be done using the postman Google Chrome plugin or various online post tools, where the Curl tool is used for post operations in the Linux window.

Manually Start Docker-daemon

#service Docker Stop

#sudo Docker Daemon--api-cors-header= "*"-H tcp://0.0.0.0:2375-h unix:///var/run/do

Cker.sock

Open the Hyperledger project, launch the PBFT cluster, build the node

#docker-compose-f docker-compose-with-membersrvc.yml up

1, the rest test, login user Jim

#curl-H "Content-type:application/json"-X POST--data ' {"Enrollid": "Jim", "Enrollsecret": "6avzqlwcue9b"} ' Http://lo Calhost:5000/registrar

Shown below

2. Chaincode Deployment

Curl-h "Content-type:application/json"-X POST--data ' {

"Jsonrpc": "2.0",

"Method": "Deploy",

"Params": {

"Type": 1,

"Chaincodeid": {

"Path": "Github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"

},

"Ctormsg": {

"Function": "Init",

"Args": ["a", "+", "B", "2000"]

},

"Securecontext": "Jim"

},

"id": 1

} ' Http://localhost:5000/chaincode

Response as follows

{

"Jsonrpc": "2.0",

"Result": {

"Status": "OK",

"Message": "28bb2b2316171a706bb2810ec35d095f430877bf443f1061ef0f60bbe753ed440700a

5312C16390D3B30199FE9465C3B75D5944358CAAE01CA81EF28128A1BFB "

},

"id": 1

}

3. Chaincode Call

Transfer, Invoke invoke

#curl-H "Content-type:application/json"-X POST--data ' {

"Jsonrpc": "2.0",

"Method": "Invoke",

"Params": {

"Type": 1,

"Chaincodeid": {

"Name": "28bb2b2316171a706bb2810ec35d095f430877bf443f1061ef0f60bbe753ed440700

A5312C16390D3B30199FE9465C3B75D5944358CAAE01CA81EF28128A1BFB "

},

"Ctormsg": {

"Function": "Invoke",

"Args": ["a", "B", "100"]

},

"Securecontext": "Jim"

},

"ID": 3

} ' Http://localhost:5000/chaincode

Response as follows:

{

"Jsonrpc": "2.0",

"Result": {

"Status": "OK",

"Message": "509b7500-96da-4411-8464-e24c61d5477d"

},

"ID": 3

}

3, Chaincode Query

Call Query

Curl-h "Content-type:application/json"-X POST--data ' {

"Jsonrpc": "2.0",

"Method": "Query",

"Params": {

"Type": 1,

"Chaincodeid": {

"Name": " 28bb2b2316171a706bb2810ec35d095f430877bf443f1061ef0f60bbe753ed440700a5312c16390d3b30199fe9465c3b75d5944358caae01ca81ef281 28A1BFB "

},

"Ctormsg": {

"function": "Query",

"Args": ["a"]

},

"Securecontext": "Jim"

},

"ID": 5

} ' Http://localhost:5000/chaincode

Return

4, block information query

Url

GET LOCALHOST:5000/CHAIN/BLOCKS/2

#curl HTTP://LOCALHOST:5000/CHAIN/BLOCKS/2

(3) Python client interaction

Interacting with Hyperledger using a Python client

1. Install Python

#pip Install Hyperledger--upgrade

2. Enter the Python client

#python

>>>from hyperledger.client Import Client

>>>c = Client (base_url= "http://localhost:5000")

>>>c.peer_list ()//Returns the network information composed of the blockchain nodes

Return as follows:

>>> c.block_get (' 2 ')//Get block info

>>>c.chain_list ()//get current blockchain status

>>>

For specific API use see HTTPS://GITHUB.COM/YEASY/HYPERLEDGER-PY/BLOB/MASTER/DOCS/API.MD


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.