├── images ├── I2P1.png ├── P2F1.png ├── P2F2.png ├── P2F3.png ├── P2F4.png ├── P2F5.png ├── P2F6.png ├── P2F7.png └── P2T1.png ├── Docker容器与容器云.md ├── Chaincode ├── .idea │ ├── misc.xml │ ├── modules.xml │ ├── Chaincode.iml │ └── workspace.xml └── test1.go ├── First App in Fabric.md ├── A First Look at Identity Management Schemes on the Blockchain.md ├── README.md ├── Chaincode Instructions.md ├── Fabric v1.1 Installation.md ├── Architecture of the Hyperledger Blockchain Fabric.md ├── Fabric v0.6 Installation.md └── A Distributed Operating System for Permissioned Blockchains.md /images/I2P1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/I2P1.png -------------------------------------------------------------------------------- /images/P2F1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F1.png -------------------------------------------------------------------------------- /images/P2F2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F2.png -------------------------------------------------------------------------------- /images/P2F3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F3.png -------------------------------------------------------------------------------- /images/P2F4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F4.png -------------------------------------------------------------------------------- /images/P2F5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F5.png -------------------------------------------------------------------------------- /images/P2F6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F6.png -------------------------------------------------------------------------------- /images/P2F7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2F7.png -------------------------------------------------------------------------------- /images/P2T1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dearkano/Blockchain/HEAD/images/P2T1.png -------------------------------------------------------------------------------- /Docker容器与容器云.md: -------------------------------------------------------------------------------- 1 | 第二版(浙大) 2 | 3 | 百度云链接:https://pan.baidu.com/s/17cu_RvwXlNL1c2y3oxkAWw 4 | 5 | 密码:pze8 -------------------------------------------------------------------------------- /Chaincode/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /First App in Fabric.md: -------------------------------------------------------------------------------- 1 | ## 第一个App 2 | http://hyperledger-fabric.readthedocs.io/en/release-1.1/write_first_app.html 3 | 4 | 根据教程走 5 | 6 | 需要注意的是 7 | * npm install 很慢很慢 看起来和卡住一样 等着即可 8 | * 如果之前跑过byfn.sh 一定要清理干净 docker也是一样 -------------------------------------------------------------------------------- /Chaincode/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chaincode/.idea/Chaincode.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /A First Look at Identity Management Schemes on the Blockchain.md: -------------------------------------------------------------------------------- 1 | # A First Look at Identity Management Schemes on the Blockchain 2 | 3 | 原文:https://arxiv.org/ftp/arxiv/papers/1801/1801.03294.pdf 4 | 5 | 作者 : Paul Dunphy and Fabien A. P. Petitcolas 6 | Innovation Centre, VASCO Data Security {paul.dunphy,fabien.petitcolas}@vasco.com 7 | 8 | 翻译 :Vayne Tian 9 | 10 | 1/10/2018 11 | 12 | ### 摘要 13 | 14 | 以区块链数据结构为基础的分布式账本技术(DLT)的出现,带来了新的识别身份手段的需求,这将颠覆传统的提供和使用数字身份的技术。这些身份管理(IdM)的新技术希望提高去中心化程度、透明度和涉及身份信息的交易中的用户控制。然而,面对多年来设计IdM遇到的重重困难,基于DLT的IdM能实现它们的远大目标吗?我们将会介绍基于DLT的IdM的展望,并使用对表征了那些成功的IdM特性的重要框架的分析来评估三个有代表性的建议:uPort,ShoCard,Sovrin。 15 | 16 | ### 关键字 17 | 18 | 分布式账本技术,身份和访问管理 19 | 20 | ## 简介 21 | 22 | 24年前, Peter Steiner 提出了著名的“在互联网上,没人知道你是一只狗”的论断,这句话如今仍然揭示着在互联网上身份验证存在的挑战。无论是七十年代公钥加密算法的发明者对公共目录的愿景,还是八十年代分级认证技术的宏大体系,我们都还有很长的路要走。 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 记录在学习Hyperledger Fabric和Blockchain过程中遇到的问题和一些资源,以及一些论文的翻译。 2 | 3 | ### TIMELINE 4 | 5 | * 3/19/2018 6 | 7 | * **CREATE** Repository 8 | 9 | * 3/20/2018 10 | * **COMMIT** Instruction : *Fabric v0.6 Installation* 11 | 12 | * 3/31/2018 13 | * **COMMIT** Translation : *Architecture of the Hyperledger Blockchain Fabric* 14 | 15 | * 4/2/2018 16 | * **COMMIT** Translation : *Hyperledger Fabric:A Distributed Operating System for Permissioned Blockchains* 17 | 18 | * 4/4/2018 19 | * **UPLOAD** Book : *Docker容器与容器云* 20 | 21 | * 4/6/2018 22 | * **UPLOAD** Translation : *A First Look at Identity Management Schemes on the Blockchain* 23 | 24 | * 4/12/2018 25 | * **COMMIT** Code : *Fabric Chaincode Test* 26 | 27 | * 4/12/2018 28 | * **COMMIT** Instruction : *Fabric v1.1 Instruction* -------------------------------------------------------------------------------- /Chaincode/test1.go: -------------------------------------------------------------------------------- 1 | package Chaincode 2 | import ( 3 | "github.com/hyperledger/fabric/core/chaincode/shim" 4 | pb "github.com/hyperledger/fabric/protos/peer" 5 | "fmt" 6 | ) 7 | 8 | type SimpleChaincode struct { 9 | } 10 | 11 | func main() { 12 | err := shim.Start(new(SimpleChaincode)) 13 | if err != nil { 14 | fmt.Printf("Error starting Simple chaincode: %s", err) 15 | } 16 | } 17 | func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { 18 | return shim.Success(nil) 19 | } 20 | 21 | 22 | func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { 23 | function, args := stub.GetFunctionAndParameters() 24 | fmt.Println("invoke is running " + function) 25 | if function == "test1" {//自定义函数名称 26 | return t.test1(stub, args)//定义调用的函数 27 | } 28 | return shim.Error("Received unknown function invocation") 29 | } 30 | func (t *SimpleChaincode) test1(stub shim.ChaincodeStubInterface, args []string) pb.Response{ 31 | return shim.Success([]byte("Called test1")) 32 | } -------------------------------------------------------------------------------- /Chaincode Instructions.md: -------------------------------------------------------------------------------- 1 | ## go chaincode 部署的常用命令 2 | ### fabric v0.6 pbft 3 | 4 | * 启动网络 5 | 6 | docker-compose -f 4-peers.yml up 7 | 8 | * 查看容器 9 | 10 | Docker ps 11 | 12 | * 进入容器 13 | 14 | docker exec -it pbft_vp0_1 bash 15 | 16 | * 部署chaincode 17 | 18 | * 官方example02 19 | 20 | peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "2000"]}' 21 | 22 | * 自己的test1.go 23 | 24 | peer chaincode deploy -p test1.go -c '{"Function":"init", "Args": []}' 25 | 26 | * 查询 27 | 28 | peer chaincode query -n "ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539" -c '{"Function": "query", "Args": ["a"]}' 29 | 30 | 31 | * 调用 32 | 33 | peer chaincode invoke -n "ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539" -c '{"Function": "invoke", "Args": ["a", "b", "10"]}' 34 | 35 | * 打印日志 36 | 37 | docker logs -f pbft_vp0_1 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Fabric v1.1 Installation.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Blockchain_fabric 4 | Study hyperledger fabric 5 | ### Author:VayneTian 4/12/2018 6 | ## Hyperledger Fabric v1.1 安装与测试 7 | ## Prerequisites 8 | ### 操作系统 9 | 本文使用Ubuntu 16.04 10 | 11 | * `apt install git` 12 | * `curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -` 13 | * `apt install -y nodejs` 14 | * `apt install docker` 15 | * `apt install docker-compose` 16 | * `git clone https://github.com/hyperledger/fabric.git` 17 | * `git clone -b master https://github.com/hyperledger/fabric-samples.git` 18 | * `cd fabric/scripts` 19 | * `./bootstrap.sh` 20 | * https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/ 21 | * 下载对应系统的v1.0.0二进制 并解压到fabric-samples下面 22 | * `cd fabric-samples/first-netword` 23 | * `./byfn.sh -m generate` 24 | * `./byfn.sh -m up` 25 | 26 | 27 | ## 下载测试代码 28 | `git clone -b master https://github.com/hyperledger/fabric-samples.git` 29 | 30 | ## 下载fabric源码 31 | 这段代码会下载fabric的文件并且使用脚本去拉取dockerhub上的镜像并全部标记latest 32 | 33 | * 如果你可以翻墙 一步ok 34 | 35 | `curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0` 36 | 37 | * 不能的话 38 | 39 | `git clone https://github.com/hyperledger/fabric.git` 40 | 41 | 打开script文件夹命令行 42 | 43 | `sh bootstrap.sh` 44 | 45 | ## 下载fabric二进制文件 46 | 47 | https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/ 48 | 49 | 在源码下新建aberic文件夹 解压进去 50 | 这里注意 对应自己的系统去下载 51 | 52 | 然后将bin文件夹放在fabirc-samples下面 53 | 54 | ## 一些坑 55 | 56 | * 第一次up遇到这个bug 57 | 58 | After 5 attempts, PEER1 has failed to Join the Channel 59 | 60 | 是环境遗留问题 去./byfn.sh down mychannel一下再开 61 | 62 | 63 | * 如果提示port被占用,停止容器并删除 64 | 65 | docker stop $(docker ps -a -q) 66 | 67 | docker rm $(docker ps -a -q) 68 | 69 | 70 | 71 | 72 | * 如果是在阿里云机器上部署fabric ,在e2e_cli 启动网络时,遇到以下错误 73 | 74 | FAILED to execute End-2-End Scenario 75 | 76 | 用户则需要修改 /etc/resolv.conf 配置,将 options timeout:2 attempts:3 rotate single-request-reopen 这一行内容注释掉 77 | 78 | https://www.cnblogs.com/chenfool/p/8353425.html 79 | 80 | 这篇博客的debug内容还不错 其他一概推荐官方教程 81 | 82 | http://hyperledger-fabric.readthedocs.io/en/release-1.1/build_network.html 83 | 84 | 85 | 86 | ## 环境变量 87 | 88 | 89 | export CHANNEL_NAME=mychannel 90 | 91 | 92 | CORE_PEER_MSPCONFIGPATH=./crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp 93 | 94 | CORE_PEER_ADDRESS=peer0.org1.example.com:7051 95 | 96 | CORE_PEER_LOCALMSPID="Org1MSP" 97 | 98 | CORE_PEER_TLS_ROOTCERT_FILE=./crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt 99 | 100 | peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile ./crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 101 | 102 | -------------------------------------------------------------------------------- /Architecture of the Hyperledger Blockchain Fabric.md: -------------------------------------------------------------------------------- 1 | # Hyperledger Fabric架构 2 | 原文:Architecture of the Hyperledger Blockchain Fabric 3 | 作者:Christian Cachin 4 | IBM Research - Zurich CH-8803 R¨uschlikon, Switzerland 5 | 翻译:Vayne Tian 6 | 这篇文章是读完论文后翻译过来的,也算是给自己加深印象,有翻译的不好的地方多多见谅。 7 | 原文地址:https://pdfs.semanticscholar.org/f852/c5f3fe649f8a17ded391df0796677a59927f.pdf 8 | 9 | # 总览 10 | 区块链可以被看作是状态机的复本。任何时间点对整个链进行快照,就可以将结果视为一种世界状态,而客户进行的操作——智能合约的调用的实质就是改变世界状态并产生一些输出。区块链通过分布式的网络节点,模拟了一种可信计算的服务系统。这个系统相当于或者产生了一笔资产,而所有的节点都持有它的股份。这些节点不需要信任对方,但有一个共同的目标,就是将这个服务持续运行下去。在一个没有准入机制的区块链里,比如加密货币比特币底层的架构,任何人都可以去操作一个节点,并且通过基于CPU运算(原文如此)的工作量证明参与其中。但从另一方面来说,如果一个区块链拥有准入机制,那么它就可以通过验证和协议来控制什么节点可以参与进来,这些节点通常拥有一致性并建立起联盟。 11 | 12 | # Hyperledger 13 | 超级账本是一个致力于建立企业级的开源分布式账本框架和代码库的合作项目。它的目标是通过实现一个分布式账本的跨行业开放式标准来发展区块链技术,这将改变全世界商业交易的方式。2016年初,Linux基金会成立了HyperLedger项目,目前已经有超过50名成员。(200+,2018) 14 | 15 | # Hyperledger Fabric 16 | HyperLedger Fabric是一种分布式账本平台的实现,它利用成熟的经过验证的技术和模块化的架构,来运行智能合约并允许实现各式可插拔的函数。它是 HyperLedger多个同时孵化中的子项目之一。2016年6月,Hyperledger Fabric v0.5开发版公布。(v1.1为现在的开发版 2018) 17 | 18 | HyperLedger Fabric的分布式账本协议是在peers上运行的。Fabric区分两种peer,一种是validating peer,作为网络上负责运行共识,验证交易和维持账本。另一种non-validating peer的作用则是作为代理服务器,连接其他的客户到validating peer,本质上就是发布交易。一个non-validating peer可能只是验证交易而并不会去执行交易。 19 | 20 | # Fabric v0.5的一些主要特性 21 | 22 | 1.拥有准入机制的区块链,交易发生后在极短时间内达成共识并产生最终结果 23 | 2.可以运行任意的智能合约(这里叫做chaincode 链码) 使用go语言实现 24 | 用户定义的链码被封装在docker容器中,系统级的链码则会同样以peer的形式运行 25 | 3.可插拔共识算法,使用实用拜占庭同错算法(PBFT),可用SIEVE的原型来部署非确定性链码,对于单peer可以使用NOOPS(一种协议存根)作为开发服务 26 | 4.通过证书颁发机构(CAs)发布TLS证书,注册证书和交易证书来保证安全性 27 | 5.利用RocksDb支持键值对存储接口实现持久状态 28 | 6.拥有支持预定义和自定义事件的框架 29 | 7.拥有nodejs接口实现的客户端SDK 30 | 8.支持REST APIs和CLIs 31 | 在v0.5-dev版本中,只实现了最低限度对non-validating peer的支持。 32 | 33 | 34 | # HyperLedger Fabric架构 35 | 36 | 这些validating peers将会通过拜占庭容错的共识算法运行一个状态机副本来接收三种交易信息 37 | 38 | 部署交易:将一个用go语言编写的链码(智能合约)当作参数,链码将会在peers上安装并准备执行。 39 | 40 | 执行交易:调用一段早先被部署在peers上的链码执行交易。参数与具体调用的链码类型有关。链码执行交易,将会在世界状态上进行读写,并指出这个交易是否成功。 41 | 42 | 查询交易:通过直接读取peer的状态返回一些条目,这个操作不会保证线性一致性。 43 | 44 | 每个链码可以定义在世界状态中自己的固有条目。区块链上的哈希链是基于已经执行的交易以及交易产生的状态计算出来的。 45 | 46 | 交易只有在重复执行链码并保证满足拜占庭容错的假设时才有效,举例来说,n个validating peer中有最多f<(1/3)*n个节点可能撒谎并产生任意行为,但其他的peer一定会正确运行。当在使用拜占庭容错算法上运行时,链码必须保证其确定性,否则peers的状态可能会产生分叉。一个可以分离出可能会导致分叉的非确定性交易的解决方案已经被证实,并且在实现在SIEVE协议中。 47 | 48 | Validating peers之间通过拜占庭容错算法建立的关系是静态的,并且在初始化阶段需要人为干预。对于动态变更节点的共识算法的支持将在未来版本中发布。 49 | 50 | 由于HyperLedger Fabric实现了拥有准入机制的账本,它得以包含了可以认证和授权的安全架构。支持通过公钥认证来注册和授权交易,通过带内加密保证链码的保密性。 51 | 52 | 更准确地说,为了连接到网络,每个peer需要通过成员服务中的注册证书颁发机构(CA)获取注册认证。它允许这个peer连接到网络并获取在交易时所需要的交易证书。交易证书颁发机构会发布交易证书并且支持对那些提交交易的节点进行匿名认证,从这个意义上讲,多个发布给同一个peer的交易证书(对于注册证书而言也是一样)不会互相产生联系。 53 | 54 | 对于所有拥有注册证书的peer,链码和状态的保密性是通过使用区块链专有的密钥对交易和状态进行对称加密实现的。在将来的版本中,将会扩展加密功能来为交易和状态提供更好的保密性。 55 | 56 | 57 | # 对HyperLedger Fabric的一些讨论 58 | 当前对于区块链的共识算法有非常激烈的争论,不仅仅是在学术界,对于一些金融科技的创业公司也是一样。例如tendermint,kadena。Fabric的设计使用了模块化的概念,对准了已经成熟的分布式计算中的共识系统。这将保证Fabric的区块链相关的特性将会独立地在不同的共识算法上发展,实用拜占庭容错(PBFT)由于它的知名,成为了在Fabric上首个实现的共识算法,这是在20年来对于系统级别的拜占庭容错研究经验上发展而来的,它和一些知名的共识算法有紧密的联系,比如Poxos和Viewstamped replication,这些算法都已经在许多环境中被实现或是写进了教科书中。 59 | 60 | # 小结 61 | 62 | 与极客推崇的完全去中心化的系统不同,HyperLedger Fabric是拥有准入机制的多中心化的基于商业用途的区块链平台。它开源,依据规范,并能运行用户定义的智能合约。它拥有很强的安全性以及身份特征,并且使用了模块化的框架与可插拔的分布式共识。 63 | 在Hyperledger项目的管理下,Fabric正在飞速进化和发展。 64 | -------------------------------------------------------------------------------- /Fabric v0.6 Installation.md: -------------------------------------------------------------------------------- 1 | # Blockchain_fabric 2 | Study hyperledger fabric 3 | ### Author:VayneTian 3/19/2018 4 | ## Hyperledger Fabric v0.6 安装与测试 5 | ## Prerequisites 6 | ### 操作系统 7 | 本文使用Ubuntu 16.04 8 | ### 安装python 9 | `sudo apt-get install python` 10 | ### 安装golang 11 | `sudo apt-get install golang` 12 | ### 安装nodejs 13 | `sudo apt-get install nodejs` 14 | ### 安装curl 15 | `sudo apt-get install curl` 16 | ### 安装git 17 | `sudo apt-get install git` 18 | 19 | 最后记得update 20 | `sudo apt-get update` 21 | ### 安装docker与docker-compose 22 | 由于国内网络原因使用镜像
23 | https://www.cnblogs.com/tianhei/p/7802064.html
24 | 或
25 | https://www.cnblogs.com/studyzy/p/7492637.html
26 | ## Fabric 27 | ### 拉取Fabric v0.6镜像 28 | 29 | ```sh 30 | $ sudo docker pull yeasy/hyperledger-fabric-base:0.6-dp \ 31 | && sudo docker pull yeasy/hyperledger-fabric-peer:0.6-dp \ 32 | && sudo docker pull yeasy/hyperledger-fabric-membersrvc:0.6-dp \ 33 | && sudo docker pull yeasy/blockchain-explorer:latest \ 34 | && sudo docker tag yeasy/hyperledger-fabric-peer:0.6-dp hyperledger/fabric-peer \ 35 | && sudo docker tag yeasy/hyperledger-fabric-base:0.6-dp hyperledger/fabric-baseimage \ 36 | && sudo docker tag yeasy/hyperledger-fabric-membersrvc:0.6-dp hyperledger/fabric-membersrvc 37 | ``` 38 | 注意多拉几次,全部拉成功,可能网络原因会连接失败 39 | 40 | 使用默认镜像(官方dockhub)进行拉取时,往往会遇到速度极慢或handshake timeout的情况
41 | 解决方案:换用国内仓库daocloud.如果你未遇到拉取过慢的情况,请跳过下面的内容
42 | ``echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io\"" | sudo tee -a /etc/default/docker 43 | ``
44 | ``sudo service docker stop``
45 | 修改 /etc/defaut/docker 文件,增加参数实行强制普通模式避免新版docker使用第三方仓库报错:
46 | ``DOCKER_OPTS="--insecure-registry http://dl.dockerpool.com:5000"``
47 | 再重启服务:
48 | ``sudo service docker restart``
49 | 50 | ### clone demo 51 | `git clone https://github.com/yeasy/docker-compose-files` 52 | 53 | ### 启动peer 54 | `cd docker-compose-files/hyperledger_fabric/v0.6.0/pbft/`
55 | `docker-compose -f 4-peers.yml up`
56 | 可以看到终端中已经成功运行了peer网络 57 | 58 | ### 部署chaincode 59 | 在当前地址打开另一个终端
60 | `docker exec -it pbft_vp0_1 bash`
61 | 可以看到命令行发生了变化,变成了
62 | `root@vp0:/go/src/github.com/hyperledger/fabric#`
63 | 部署一个example
64 | `peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'`
65 | 这个示例是初始化两个账户a和b,a有余额100元,b有余额200元
66 | 我们可以看到部署成功并返回了ChainCode的ID
67 | 我这里是
68 | ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539 69 | ### 查询chaincode 70 | 下面我们把这个ID放入一个变量中:
71 | `CC_ID="ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539"`
72 | 下面我们来查询一下a账户的余额:
73 | `peer chaincode query -n ${CC_ID} -c '{"Function": "query", "Args": ["a"]}'`
74 | Query Result: 100
75 | 可以看到余额是100元
76 | ### 调用chaincode 77 | 接下来,我们让a给b转账10元,运行命令:
78 | `peer chaincode invoke -n ${CC_ID} -c '{"Function": "invoke", "Args": ["a", "b", "10"]}'` 79 | 现在已经转账完毕,我们再来查询一下a账户的余额:
80 | `peer chaincode query -n ${CC_ID} -c '{"Function": "query", "Args": ["a"]}'` 81 | Query Result: 90
82 | 可以看到少了十元
83 | 84 | ### 使用REST在windows调用 85 | 首先安装chrome插件DHC
86 | 提供一个链接
87 | https://pan.baidu.com/s/1mSdtfURbKauk2WYYPn_YmA
88 | 解压以后把_metadata重命名metadata然后用chrome添加即可
89 | (下面是使用虚拟机的内容)
90 | 在ifconfig里找到虚拟机的IP,我这里地址是192.168.198.128:7050/chaincode,然后在DHC里发送http请求即可完成调用
91 | 一个示例
92 | body部分:
93 | ```sh 94 | { 95 | "jsonrpc": "2.0", 96 | "method": "deploy", 97 | "params": { 98 | "type": 1, 99 | "chaincodeID":{ 100 | "path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" 101 | }, 102 | "ctorMsg": { 103 | "function":"init", 104 | "args":["a", "1000", "b", "2000"] 105 | } 106 | }, 107 | "id": 1 108 | } 109 | ``` 110 | header部分:
111 | `Content-Type:text/javascript`
112 | 成功会返回code200,建议使用vmware,vbox可能出现主机ping不到客户机的情况。
113 |
114 | (下面是使用两台主机的内容)
115 | 在ifconfig里找到对应IP,注意以太网和无线局域网的IP是不同的,注意根据自己当前所使用网络类型区别(一般很容易分辨)
116 | 有必要强调的是,如果您使用浙大校园网(有线or无线),请务必使用通过上述命令查得的私有IP(10开头),而非其他第三方应用检测的公网IP
117 | 由于暂未知(可能是交换机限制)的原因,公网IP不仅ping不通,以其为目标的post请求也会失败
118 | 强烈建议您在进行post尝试前先运行ping命令进行检测,以避免不必要的麻烦
119 | 之后的操作(包括端口号和下级目录名)同虚拟机配置
120 |
121 | 122 | -------------------------------------------------------------------------------- /Chaincode/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 35 | 36 | 37 | 42 | 43 | 44 | 45 | 46 | true 47 | DEFINITION_ORDER 48 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |