Hyperledger Fabric 2.x 动态更新智能合约

Posted 陶陶技术笔记

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hyperledger Fabric 2.x 动态更新智能合约相关的知识,希望对你有一定的参考价值。

在上一篇文章中分享了智能合约的安装与使用,如果业务有变更代码需要修改怎么办呢?本文分享如何对已安装的合约进行版本更新。

 

区块链网络安装:《Hyperledger Fabric 2.x 环境搭建》

智能合约安装:《Hyperledger Fabric 2.x 自定义智能合约》

 

执行以下命令,可以看到已安装的合约信息:

重新把最新的合约源代码打包:

再次分别为 peer0.org1peer0.org2 两个机构安装合约:

再次分别为 peer0.org1peer0.org2 两个机构审批合约:

需填入新安装的 Package ID
  • 「sequence」 因为是审批第二个合约,所以需要填 2
  • 「version」 只是标识符,可改可不改
  •  

    执行以下命令,检查节点审批状态:

    执行以下命令,向通道提交合约:

    「version」 改为审批时的值

     

    执行一下命令:

    名字为 mycc 的合约已经更新为 1.1 版本:


     "sequence": 2,
     "version""1.1",
     "endorsement_plugin""escc",
     "validation_plugin""vscc",
     "validation_parameter""EiAvQ2hhbm5lbC9BcHBsaWNhdGlvbi9FbmRvcnNlbWVudA==",
     "collections": ,
     "approvals"
      "Org1MSP"true,
      "Org2MSP"true
     

    文章推荐

    Dubbo想要个网关怎么办?试试整合Spring Cloud Gateway

    Spring Security基于Oauth2的SSO单点登录怎样做?一个注解搞定

    微服务业务监控和行为分析怎么做?试试日志埋点

    Spring Cloud异步场景分布式事务怎样做?试试RocketMQ

    Spring Cloud同步场景分布式事务怎样做?试试Seata

    HyperLedger Fabric中fabric-samples 安装

    官网文档:https://hyperledger-fabric.readthedocs.io/en/release-1.0/samples.html

    版本:v1.0

    1.下载fabric-samples

    选择文件位置,下载fabric-samples

    git clone https://github.com/hyperledger/fabric-samples.git
    cd fabric-samples

    2.下载Platform-specific Binaries

    官方文档指导方式为:

    curl -sSL https://goo.gl/kFFqh5 | bash -s 1.0.6

    但是第二步操作起来,我这边会出现如下错误:

    [email protected]:~/go/src/github.com/hyperledger/fabric-samples$ curl -sSL https://goo.gl/kFFqh5 | bash -s 1.0.6
    curl: (7) Failed to connect to goo.gl port 443: Connection timed out

    所以,我采取了其他方式下载必需的二进制代码:

    进入fabric-samples文件夹下的scripts文件夹,运行其中的bootstrap.sh脚本

    (参考来源:https://github.com/hyperledger/fabric-samples)

    cd scripts
    ./bootstrap.sh 

    3.测试

    运行结束后,进行测试。我们使用first-network 例子。

    cd first-network
    #创建genesis block .
    /byfn.sh -m generate
    #启动网络 .
    /byfn.sh -m up

    运行结果:

    Starting with channel ‘mychannel‘ and CLI timeout of ‘10000‘
    Continue (y/n)?y
    proceeding ...
    Creating network "net_byfn" with the default driver
    Creating peer0.org1.example.com
    Creating peer1.org1.example.com
    Creating peer0.org2.example.com
    Creating orderer.example.com
    Creating peer1.org2.example.com
    Creating cli
    
    
     ____    _____      _      ____    _____
    / ___|  |_   _|    /     |  _   |_   _|
    \___     | |     / _    | |_) |   | |
     ___) |   | |    / ___   |  _ <    | |
    |____/    |_|   /_/   \_ |_| \_   |_|
    
    Channel name : mychannel
    Creating channel...
    
    ................
    2017-05-16 17:08:01.366 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
    2017-05-16 17:08:01.366 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
    2017-05-16 17:08:01.366 UTC [msp/identity] Sign -> DEBU 006 Sign: plaintext: 0AB1070A6708031A0C08F1E3ECC80510...6D7963631A0A0A0571756572790A0161
    2017-05-16 17:08:01.367 UTC [msp/identity] Sign -> DEBU 007 Sign: digest: E61DB37F4E8B0D32C9FE10E3936BA9B8CD278FAA1F3320B08712164248285C54
    Query Result: 90
    2017-05-16 17:08:15.158 UTC [main] main -> INFO 008 Exiting.....
    ===================== Query on PEER3 on channel ‘mychannel‘ is successful =====================
    
    ===================== All GOOD, BYFN execution completed =====================
    
    
     _____   _   _   ____
    | ____| |  | | |  _ |  _|   |  | | | | | |
    | |___  | |  | | |_| |
    |_____| |_| _| |____/

     

    4.结束网络运行

    ./byfn.sh -m down

     





    以上是关于Hyperledger Fabric 2.x 动态更新智能合约的主要内容,如果未能解决你的问题,请参考以下文章

    (c)2006-2024 SYSTEM All Rights Reserved IT常识