爆款云主机2核4G限时秒杀,88元/年起!
查看详情

活动

天翼云最新优惠活动,涵盖免费试用,产品折扣等,助您降本增效!
热门活动
  • 618智算钜惠季 爆款云主机2核4G限时秒杀,88元/年起!
  • 免费体验DeepSeek,上天翼云息壤 NEW 新老用户均可免费体验2500万Tokens,限时两周
  • 云上钜惠 HOT 爆款云主机全场特惠,更有万元锦鲤券等你来领!
  • 算力套餐 HOT 让算力触手可及
  • 天翼云脑AOne NEW 连接、保护、办公,All-in-One!
  • 中小企业应用上云专场 产品组合下单即享折上9折起,助力企业快速上云
  • 息壤高校钜惠活动 NEW 天翼云息壤杯高校AI大赛,数款产品享受线上订购超值特惠
  • 天翼云电脑专场 HOT 移动办公新选择,爆款4核8G畅享1年3.5折起,快来抢购!
  • 天翼云奖励推广计划 加入成为云推官,推荐新用户注册下单得现金奖励
免费活动
  • 免费试用中心 HOT 多款云产品免费试用,快来开启云上之旅
  • 天翼云用户体验官 NEW 您的洞察,重塑科技边界

智算服务

打造统一的产品能力,实现算网调度、训练推理、技术架构、资源管理一体化智算服务
智算云(DeepSeek专区)
科研助手
  • 算力商城
  • 应用商城
  • 开发机
  • 并行计算
算力互联调度平台
  • 应用市场
  • 算力市场
  • 算力调度推荐
一站式智算服务平台
  • 模型广场
  • 体验中心
  • 服务接入
智算一体机
  • 智算一体机
大模型
  • DeepSeek-R1-昇腾版(671B)
  • DeepSeek-R1-英伟达版(671B)
  • DeepSeek-V3-昇腾版(671B)
  • DeepSeek-R1-Distill-Llama-70B
  • DeepSeek-R1-Distill-Qwen-32B
  • Qwen2-72B-Instruct
  • StableDiffusion-V2.1
  • TeleChat-12B

应用商城

天翼云精选行业优秀合作伙伴及千余款商品,提供一站式云上应用服务
进入甄选商城进入云市场创新解决方案
办公协同
  • WPS云文档
  • 安全邮箱
  • EMM手机管家
  • 智能商业平台
财务管理
  • 工资条
  • 税务风控云
企业应用
  • 翼信息化运维服务
  • 翼视频云归档解决方案
工业能源
  • 智慧工厂_生产流程管理解决方案
  • 智慧工地
建站工具
  • SSL证书
  • 新域名服务
网络工具
  • 翼云加速
灾备迁移
  • 云管家2.0
  • 翼备份
资源管理
  • 全栈混合云敏捷版(软件)
  • 全栈混合云敏捷版(一体机)
行业应用
  • 翼电子教室
  • 翼智慧显示一体化解决方案

合作伙伴

天翼云携手合作伙伴,共创云上生态,合作共赢
天翼云生态合作中心
  • 天翼云生态合作中心
天翼云渠道合作伙伴
  • 天翼云代理渠道合作伙伴
天翼云服务合作伙伴
  • 天翼云集成商交付能力认证
天翼云应用合作伙伴
  • 天翼云云市场合作伙伴
  • 天翼云甄选商城合作伙伴
天翼云技术合作伙伴
  • 天翼云OpenAPI中心
  • 天翼云EasyCoding平台
天翼云培训认证
  • 天翼云学堂
  • 天翼云市场商学院
天翼云合作计划
  • 云汇计划
天翼云东升计划
  • 适配中心
  • 东升计划
  • 适配互认证

开发者

开发者相关功能入口汇聚
技术社区
  • 专栏文章
  • 互动问答
  • 技术视频
资源与工具
  • OpenAPI中心
开放能力
  • EasyCoding敏捷开发平台
培训与认证
  • 天翼云学堂
  • 天翼云认证
魔乐社区
  • 魔乐社区

支持与服务

为您提供全方位支持与服务,全流程技术保障,助您轻松上云,安全无忧
文档与工具
  • 文档中心
  • 新手上云
  • 自助服务
  • OpenAPI中心
定价
  • 价格计算器
  • 定价策略
基础服务
  • 售前咨询
  • 在线支持
  • 在线支持
  • 工单服务
  • 建议与反馈
  • 用户体验官
  • 服务保障
  • 客户公告
  • 会员中心
增值服务
  • 红心服务
  • 首保服务
  • 客户支持计划
  • 专家技术服务
  • 备案管家

了解天翼云

天翼云秉承央企使命,致力于成为数字经济主力军,投身科技强国伟大事业,为用户提供安全、普惠云服务
品牌介绍
  • 关于天翼云
  • 智算云
  • 天翼云4.0
  • 新闻资讯
  • 天翼云APP
基础设施
  • 全球基础设施
  • 信任中心
最佳实践
  • 精选案例
  • 超级探访
  • 云杂志
  • 分析师和白皮书
  • 天翼云·创新直播间
市场活动
  • 2025智能云生态大会
  • 2024智算云生态大会
  • 2023云生态大会
  • 2022云生态大会
  • 天翼云中国行
天翼云
  • 活动
  • 智算服务
  • 产品
  • 解决方案
  • 应用商城
  • 合作伙伴
  • 开发者
  • 支持与服务
  • 了解天翼云
      • 文档
      • 控制中心
      • 备案
      • 管理中心

      Hyperledger Fabric 管理链码 peer lifecycle chaincode 指令使用

      首页 知识中心 其他 文章详情页

      Hyperledger Fabric 管理链码 peer lifecycle chaincode 指令使用

      2024-07-01 01:31:09 阅读次数:429

      fabric,sequence

      Hyperledger Fabric 管理链码 peer lifecycle chaincode 指令使用

      链上代码(Chaincode)简称链码,包括系统链码和用户链码。系统链码(System Chaincode)指的是Fabric Peer中负责系统配置、查询、背书、验证等平台功能的代码逻辑,运行在Peer进程内,将在第14章介绍。用户链码指的是用户编写的用来实现智能合约的应用代码。如无特殊说明,链码一般指的就是用户链码。

      链码被部署在Peer节点上,运行在独立的沙盒(目前为Docker容器)中,并通过gRPC协议与相应的Peer节点进行交互。用户可以通过命令行或SDK调用链码方法,链码被调用时,会按照链码内预定逻辑来计算账本状态的更新集合(读写集合)。

      链码操作命令

      Operate a chaincode: install|instantiate|invoke|package|query|signpackage|upgrade|list.
      
      Usage:
        peer chaincode [command]
      
      Available Commands:
        install     Install a chaincode.
        instantiate Deploy the specified chaincode to the network.
        invoke      Invoke the specified chaincode.
        list        Get the instantiated chaincodes on a channel or installed chaincodes on a peer.
        package     Package a chaincode
        query       Query using the specified chaincode.
        signpackage Sign the specified chaincode package
        upgrade     Upgrade chaincode.
      
      Flags:
            --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
            --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
            --clientauth                          Use mutual TLS when communicating with the orderer endpoint
            --connTimeout duration                Timeout for client to connect (default 3s)
        -h, --help                                help for chaincode
            --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
        -o, --orderer string                      Ordering service endpoint
            --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
            --tls                                 Use TLS when communicating with the orderer endpoint
            --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
            --transient string                    Transient map of arguments in JSON encoding
      
      Use "peer chaincode [command] --help" for more information about a command.
      

      最简单的操作链码的方式是使用命令行。Fabric自2.0版本开始正式启用新的生命周期系统链码(位于core/chaincode/lifecycle)来管理链码(需开启应用能力V2_0),客户端通过新的peer lifecycle chaincode子命令(位于internal/peer/lifecycle)对链码进行打包、安装、批注和提交等生命周期管理,取代1.x中的peer chaincode命令。

      相对1.x版本中的模式,新的链码管理从单个组织升级为通道范畴。例如,链码的背书策略可由通道内多个组织来商定,部署和升级也作为通道层面的操作,这些都提高了链码生命周期的安全性。如果要对链码进行调用或查询,仍可以使用原有的peer chaincode invoke和peer chaincode query命令。

      Hyperledger Fabric 管理链码 peer lifecycle chaincode 指令使用

      Hyperledger Fabric 管理链码 peer lifecycle chaincode 指令使用

      如果要使用1.x版本中的链码生命周期管理(peer chaincodeinstall/instantaite/upgrade/list等命令),需要将通道的应用能力版本设置为兼容的低版本,如V1_4_2。当通道启用了应用能力V2_0后,将无法再部署或升级原有模式下的链码。

      链码生命周期:

      Hyperledger Fabric 管理链码 peer lifecycle chaincode 指令使用

      链码操作支持全局命令选项:

      全局选项 类型 含义
      --cafile string 信任的排序服务的 TLS CA 的证书(PEM编码格式)路径
      --certfile string 与排序服务进行双向 TLS 认证时使用的本地证书文件路径
      --clientauth bool 与排序服务通信时是否启用双向 TLS 认证
      --connTimeout duration 客户端连接超时,默认为 3 秒
      --keyfile string 与排序服务双向 TLS 认证时使用的本地私钥文件路径
      -o,--orderer string Orderer 服务地址
      --ordererTLSHostnameOverride string 验证 Orderer TLS 时覆盖所校验的主机名
      --tls bool 连接到 Orderer 服务时是否启用 TLS
      --transient string 调用链码时传递的临时信息,其他 peer 将无法获取该信息

      打包链码

      package 子命令可以封装链码相关的数据,将其打包为.tar.gz安装包,供安装使用。

      Package a chaincode and write the package to a file.
      
      Usage:
        peer chaincode package [outputfile] [flags]
      
      Flags:
        -s, --cc-package                  create CC deployment spec for owner endorsements instead of raw CC deployment spec
        -c, --ctor string                 Constructor message for the chaincode in JSON format (default "{}")
        -h, --help                        help for package
        -i, --instantiate-policy string   instantiation policy for the chaincode
        -l, --lang string                 Language the chaincode is written in (default "golang")
        -n, --name string                 Name of the chaincode
        -p, --path string                 Path to chaincode
        -S, --sign                        if creating CC deployment spec package for owner endorsements, also sign it with local MSP
        -v, --version string              Version of the chaincode specified in install/instantiate/upgrade commands
      
      Global Flags:
            --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
            --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
            --clientauth                          Use mutual TLS when communicating with the orderer endpoint
            --connTimeout duration                Timeout for client to connect (default 3s)
            --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
        -o, --orderer string                      Ordering service endpoint
            --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
            --tls                                 Use TLS when communicating with the orderer endpoint
            --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
            --transient string                    Transient map of arguments in JSON encoding
      

      其中,生成的打包文件中包括Chaincode-Package-Metadata.json、Code-Package.tar.gz两个文件。Chaincode-Package-Metadata.json内容包括链码路径、类型、标签等信息.Code-Package.tar.gz内容包括链码的源码包结构,如src/examples/chaincode/go/testcc/路径以及内容,但不能包括对目录以外路径的引用。

      注意:自2.0版本起,编译链码的ccenv镜像不再包括shim层。链码需要自行包括/hyperledger/fabric-chaincode-go/shim和其他所需要的依赖包。


      安装链码

      打包后的链码安装包文件,可以使用install命令安装到运行链码的各个Peer。

      Install a chaincode on a peer. This installs a chaincode deployment spec package (if provided) or packages the specified chaincode before subsequently installing it.
      
      Usage:
        peer chaincode install [flags]
      
      Flags:
            --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
        -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
        -h, --help                           help for install
        -l, --lang string                    Language the chaincode is written in (default "golang")
        -n, --name string                    Name of the chaincode
        -p, --path string                    Path to chaincode
            --peerAddresses stringArray      The addresses of the peers to connect to
            --tlsRootCertFiles stringArray   If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag
        -v, --version string                 Version of the chaincode specified in install/instantiate/upgrade commands
      
      Global Flags:
            --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
            --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
            --clientauth                          Use mutual TLS when communicating with the orderer endpoint
            --connTimeout duration                Timeout for client to connect (default 3s)
            --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
        -o, --orderer string                      Ordering service endpoint
            --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
            --tls                                 Use TLS when communicating with the orderer endpoint
            --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
            --transient string                    Transient map of arguments in JSON encoding
      
      参数 类型 含义
      -- connectionProfile string 网络访问信息文件路径,目前仅支持 peer 连接信息
      -- peerAddresses stringArray 请求所发往的 peer 地址列表
      --tlsRootCertFiles stringArray 所连接的 peer 的信任 TLS 根证书

      Peer会尝试编译链码,如果编译成功,则将安装包以二进制的形式储存到指定路径的chaincodes子目录下,并利用元数据标签和安装包生成的SHA256值作为文件名。

      Peer会尝试编译链码,如果编译成功,则将安装包以二进制的形式储存到指定路径的chaincodes子目录下,并利用元数据标签和安装包生成的SHA256值作为文件名。

      注意,安装操作需要是Peer认可的组织管理员身份(证书在Peer的admincerts目录下存在)。


      查询和批准链码

      通道内组织在部署链码前需要足够多的组织管理员对链码定义进行投票批准。链码定义包括链码名称、版本、序列号、背书和验证参数、是否需要初始化、链码包Id,以及可能带有的私密数据集合配置等。操作涉及queryinstalled、getinstalled-package、approveformyorg、checkcommitrea-diness四个链码生命周期子命令。

      queryinstalled子命令可以查询目标Peer上已经安装的链码信息。支持的参数包括:

      ●--connectionProf ile string,网络访问信息文件路径,目前仅支持Peer连接信息。

      ●-O,--output string,结果输出的格式,目前支持格式化为json格式。

      ●--peerAddresses stringArray,请求所发往的Peer地址列表。

      ●--tlsRootCertFiles stringArray,所连接的Peer的信任的TLS根证书。getinstalledpackage子命令可以获取指定的链码安装包(与发送给Peer的安装包内容相同)。支持参数包括:

      ●--connectionProf ile string,网络访问信息文件路径,目前仅支持Peer连接信息。

      ●--output-directory string,将获取到的链码安装包保存到指定路径,默认为当前路径。

      ●--package-id string,所要获取的链码安装包的ID。

      ●--peerAddresses stringArray,请求所发往的Peer地址列表。

      ●--tlsRootCertFiles stringArray,所连接的Peer的信任的TLS根证书。

      approveformyorg子命令允许用户将链码的定义发送给Peer进行背书,通过后发给Orderer进行排序和确认。所有需要执行链码的组织都需要完成此步骤。默认情况下,只有通道内大多数组织(通道内的Channel/Application/LifecycleEndorsement策略指定,默认为通道内大多数成员)都批准了链码定义,对应链码才能在通道内部署运行。支持的参数包括:

      ●--channel-config-policy string,指定链码的背书策略名称,该策略名称需要提前存储在通道策略配置中,默认为Channel/Application/Endorsement策略(默认为通道内大多数成员组织背书)。

      ●-C,--channelID string,执行命令面向的通道名称。

      ●--collections-conf ig string,启用私密数据功能时,指定集合文件的路径。

      ●--connectionProf ile string,网络访问信息文件路径,目前仅支持Peer连接信息。

      ●-E,--endorsement-plugin string,链码所使用的背书插件的名称。

      ●--init-required,是否需要调用Init方法对链码进行初始化。

      ●-n,--name string,链码名称。

      ●--package-id string,链码安装包的名称。

      ●--peerAddresses stringArray,所连接的Peer节点列表。

      ●--sequence int,通道内对链码进行定义的序列号(默认为1),每次更新链码定义则需要递增。

      ●--signature-policy string,指定链码的(基于签名的)背书策略,默认采用Channel/Application/Endorsement指定的策略(默认为通道内大多数成员组织背书),不能与--channel-conf ig-policy同时使用。

      ●--tlsRootCertFiles stringArray,连接Peer启用TLS时,所信任的TLS根证书列表(注意与Peer地址顺序匹配)。

      ●-V,--validation-plugin string,链码所使用的校验系统插件名称。

      ●--waitForEvent,是否等待事件以确认交易在各个Peer提交(默认开启)。

      ●--waitForEventTimeout duration,等待事件的时间(默认为30s)。

      checkcommitreadiness子命令可以获取指定的链码安装包当前的批准状态,调用_lifecycle链码CheckCommitReadiness方法(位于core/chaincode/lifecycle/scc.go)。支持参数与approveformyorg子命令类似。


      提交链码并查询状态

      通道内链码得到足够多的组织批准后,将成为可以合法运行的链码。此时,任意通道内组织可以使用commit子命令发起提交操作。链码定义被成功提交到通道后,通道内成员可以使用链码(如进行调用)。支持的参数包括:

      ●--channel-config-policy string,指定链码的背书策略名称,该策略名称需要提前存储在通道策略配置中,默认为Channel/Application/Endorsement策略(默认为通道内大多数成员组织背书)。

      ●-C,--channelID string,执行命令面向的通道名称。

      ●--collections-conf ig string,启用私密数据功能时,指定集合文件的路径。

      ●--connectionProf ile string,网络访问信息文件路径,目前仅支持Peer连接信息。

      ●-E,--endorsement-plugin string,链码所使用的背书插件的名称。

      ●--init-required,是否需要调用Init方法对链码进行初始化。

      ●-n,--name string,链码名称。

      ●--package-id string,链码安装包的名称。

      ●--peerAddresses stringArray,所连接的Peer节点列表。

      ●--sequence int,通道内对链码进行定义的序列号(默认为1),每次更新链码定义则需要递增。

      ●--signature-policy string,指定链码的(基于签名的)背书策略,默认采用Channel/Application/Endorsement指定的策略(默认为通道内大多数成员组织背书),不能与--channel-conf ig-policy同时使用。

      ●--tlsRootCertFiles stringArray,连接Peer启用TLS时,所信任的TLS根证书列表(注意与Peer地址顺序匹配)。

      ●-V,--validation-plugin string,链码所使用的校验系统插件名称。

      ●--waitForEvent,是否等待事件以确认交易在各个Peer提交(默认开启)。

      ●--waitForEventTimeout duration,等待事件的时间(默认为30s)。

      ●-C,--channelID string,执行命令的通道名称。

      ●--connectionProf ile string,网络访问信息文件路径,目前仅支持Peer连接信息。

      ●-n,--name string,链码名称。

      ●-O,--output string,结果输出的格式,目前支持json格式。

      ●--peerAddresses stringArray,所连接的Peer地址列表。

      ●--tlsRootCertFiles stringArray,连接Peer启用TLS时,所信任的TLS根证书列表(注意与Peer地址顺序匹配)。

      首先使用commit子命令提交已经得到批准的链码定义,然后使用querycommitted子命令查询提交状态


      使用私有数据

      在批准和提交链码定义时,可以通过--collections-conf ig collection.json来指定与私密数据相关的集合配置(Fabric v1.1.0开始支持),可以实现在同一通道内私密数据的调用只有部分成员共享。如果不指定该参数则默认不启用该特性,意味着通道内所有成员都可以看到链码调用结果。

      collections_config.json 配置文件示例 :

      [
       {
         "name": "collection1", // 集合名称
         "policy": "OR('Org1MSP.member')", // 集合成员
         "requiredPeerCount": 0, // 背书之前至少扩散私有数据到的节点数
         "maxPeerCount": 3, // 背书之前尝试扩散最多节点个数, 不能小于 requiredPeerCount
         "blockToLive": 1000000, // 私有数据保存时长 0 意味着永不过期
         "memberOnlyRead": true, // 是否只允许集合成员来读取私有数据
         "memberOnlyWrite": true ,// 是否只允许集合成员来发起对私有数据的写交易
         "endorsementPolicy": "OR('Org1MSP.member')" ,// 指定对私有数据写操作时的背书策略
         "signaturePolicy": "OR('Org1MSP.member')" // 指定使用签名策略
      },
       {
         "name": "collection2",
         "policy": "OR('Org2MSP.member')",
         "requiredPeerCount": 0,
         "maxPeerCount": 3,
         "blockToLive": 1,
         "memberOnlyRead": true
       }
      ]
      
      

      其中,collection.json中定义了collection1和collection2两个集合,其成员分别为Org1、Org2两个组织。当在链码逻辑中指定某个键值属于特定集合时,只有集合内成员能看到明文的读写集合,非集合成员即使在同一通道内也无法获取私密数据。对应policy只支持OR语法,指定哪些组织可以看到私密数据集合。

      requiredPeerCount和maxPeerCount指定了在执行背书过程中尝试扩散数据到其他合法节点的个数,避免因背书节点的突然故障而导致私密数据丢失。背书阶段未获取私密数据的合法节点,在提交阶段会尝试从其他节点来拉取私密数据。


      调用链码

      通过 peer chaincode invoke 命令(实现位于internal/peer/chaincode)可以调用运行中链码定义的方法,所指定的函数名和参数会被传到链码的Invoke()方法进行处理。调用链码操作需要同时与Peer和Orderer打交道。

      Invoke the specified chaincode. It will try to commit the endorsed transaction to the network.
      
      Usage:
        peer chaincode invoke [flags]
      
      Flags:
        -C, --channelID string               The channel on which this command should be executed
            --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
        -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
        -h, --help                           help for invoke
        -I, --isInit                         Is this invocation for init (useful for supporting legacy chaincodes in the new lifecycle)
        -n, --name string                    Name of the chaincode
            --peerAddresses stringArray      The addresses of the peers to connect to
            --tlsRootCertFiles stringArray   If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag
            --waitForEvent                   Whether to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully
            --waitForEventTimeout duration   Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully (default 30s)
      
      Global Flags:
            --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
            --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
            --clientauth                          Use mutual TLS when communicating with the orderer endpoint
            --connTimeout duration                Timeout for client to connect (default 3s)
            --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
        -o, --orderer string                      Ordering service endpoint
            --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
            --tls                                 Use TLS when communicating with the orderer endpoint
            --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
            --transient string                    Transient map of arguments in JSON encoding
      

      注意,invoke是异步操作,invoke成功只能保证交易已经进入Orderer进行排序,但无法保证最终写到账本中(例如交易未通过Committer验证而被拒绝)。需要通过事件监听或主动查询等方式来进行确认交易是否最终写到账本上。


      查询链码

      查询链码可以通过 peer chaincode query 子命令。

      该子命令实际上是invoke操作与Peer打交道的部分,即将签名后的Proposal发给指定的Peer节点的ProcessProposal()gRPC接口。最终将-c指定的命令参数发送给了链码中的Invoke()方法执行。

      query操作与invoke操作的区别在于,query操作用来查询Peer上账本状态(需要链码支持查询逻辑),不生成交易,也不需要与Orderer打交道。同时,query命令默认只返回第一个Peer的查询结果。

      Get endorsed result of chaincode function call and print it. It won't generate transaction.
      
      Usage:
        peer chaincode query [flags]
      
      Flags:
        -C, --channelID string               The channel on which this command should be executed
            --connectionProfile string       Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information
        -c, --ctor string                    Constructor message for the chaincode in JSON format (default "{}")
        -h, --help                           help for query
        -x, --hex                            If true, output the query value byte array in hexadecimal. Incompatible with --raw
        -n, --name string                    Name of the chaincode
            --peerAddresses stringArray      The addresses of the peers to connect to
        -r, --raw                            If true, output the query value as raw bytes, otherwise format as a printable string
            --tlsRootCertFiles stringArray   If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag
      
      Global Flags:
            --cafile string                       Path to file containing PEM-encoded trusted certificate(s) for the ordering endpoint
            --certfile string                     Path to file containing PEM-encoded X509 public key to use for mutual TLS communication with the orderer endpoint
            --clientauth                          Use mutual TLS when communicating with the orderer endpoint
            --connTimeout duration                Timeout for client to connect (default 3s)
            --keyfile string                      Path to file containing PEM-encoded private key to use for mutual TLS communication with the orderer endpoint
        -o, --orderer string                      Ordering service endpoint
            --ordererTLSHostnameOverride string   The hostname override to use when validating the TLS connection to the orderer
            --tls                                 Use TLS when communicating with the orderer endpoint
            --tlsHandshakeTimeShift duration      The amount of time to shift backwards for certificate expiration checks during TLS handshakes with the orderer endpoint
            --transient string                    Transient map of arguments in JSON encoding
      

      升级链码

      链码升级过程需要重复peer lifecycle chaincode相关命令,来执行完整的生命周期,具体步骤如下:

      1)更新旧版本链码的源代码,并重新打包链码包。

      2)将新的链码包再次安装到Peer,获取新的包Id。注意,相对旧版本要递增版本号。

      3)按照策略,通道内足够多组织都要重新对新版本的链码定义进行批准。注意,序列号要递增。

      4)通道内足够多组织批准定义后,可以提交新版本链码定义到通道。

      5)再次调用链码,确保链码已经自动更新为新的版本。

      版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://my.oschina.net/j4love/blog/5458727,作者:DevX,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。

      上一篇:leetcode二叉树-LCP 44. 开幕式焰火

      下一篇:域渗透之AS-REP Roasting

      相关文章

      2025-02-17 09:20:29

      【C/C++】解析简单配置文件|解析从脚本读出的流配置

      【C/C++】解析简单配置文件|解析从脚本读出的流配置

      2025-02-17 09:20:29
      end , sequence , std , string , 配置文件
      2024-12-31 06:01:30

      The controlfile header block returned by the OS has a sequence number that is too old

      The controlfile header block returned by the OS has a sequence number that is too old

      2024-12-31 06:01:30
      header , number , sequence
      2024-06-28 06:18:03

      Hyperledger Fabric 权限策略和访问控制

      访问控制是区块链网络十分重要的功能,负责控制某个身份在某个场景下是否允许采取某个操作(如读写某个资源)。

      2024-06-28 06:18:03
      fabric
      2023-08-04 07:26:46

      Hyperledger Fabric Orderer 配置解析

      Hyperledger Fabric Orderer 配置解析 文中使用的 fabric 版本为 2.4.1 排序节点在Fabric网络中为Peer提供排序服务。与Peer节点类似,排序节点支持从命令行参数、环境变量或配置文件中读取配

      2023-08-04 07:26:46
      fabric , grpc
      2023-08-04 07:26:46

      Hyperledger Fabric Peer 配置解析

      Hyperledger Fabric Peer 配置解析 文中使用的 fabric 版本为 2.4.1 在Fabric网络中,用户可以设定Peer节点、排序节点、CA节点的行为,以及管理通道、组织身份等多种资源,这都涉及网络内配置。

      2023-08-04 07:26:46
      docker , fabric , yaml
      2023-07-24 09:36:47

      sql serve 创建序列

      sql serve 创建序列 Oracle中有sequence的功能,SQL Server类似的功能使用Identity列实现,但是有很大的局限性。在2012中,微软

      2023-07-24 09:36:47
      select , sequence , sql
      2023-07-11 08:47:52

      Codeforces Round #620 (Div. 2)_D. Shortest and Longest LIS(C++_最长上升子序列)

      Codeforces Round #620 (Div. 2)_D. Shortest and Longest LIS(C++_最长上升子序列)

      2023-07-11 08:47:52
      i++ , sequence , test
      2023-05-05 10:11:46

      Hyperledger Fabric 隐私保护

      Hyperledger Fabric 隐私保护 分布式账本可以帮助多个成员进行数据共享和协作,因此,隐私保护(如哪些数据可以被谁读写)就成了十分关键的问题。 目前,Fabric通过多种技术手段在不同层级上分别进行隐私保护,包括如下几种机制:

      2023-05-05 10:11:46
      fabric
      2023-02-23 07:38:36

      前端可视化:Fabric.js HTML5 canvas 工具库

      Fabric.js 是一个功能强大且操作简单的 Javascript HTML5 canvas 工具库。文档:​​

      2023-02-23 07:38:36
      html5 , fabric , github , javascript , 前端
      查看更多
      推荐标签

      作者介绍

      天翼云小翼
      天翼云用户

      文章

      33561

      阅读量

      5229066

      查看更多

      最新文章

      The controlfile header block returned by the OS has a sequence number that is too old

      2024-12-31 06:01:30

      Hyperledger Fabric 权限策略和访问控制

      2024-06-28 06:18:03

      Hyperledger Fabric 隐私保护

      2023-05-05 10:11:46

      查看更多

      热门文章

      Hyperledger Fabric 权限策略和访问控制

      2024-06-28 06:18:03

      Hyperledger Fabric 隐私保护

      2023-05-05 10:11:46

      The controlfile header block returned by the OS has a sequence number that is too old

      2024-12-31 06:01:30

      查看更多

      热门标签

      linux java python javascript 数组 前端 docker Linux vue 函数 shell git 节点 容器 示例
      查看更多

      相关产品

      弹性云主机

      随时自助获取、弹性伸缩的云服务器资源

      天翼云电脑(公众版)

      便捷、安全、高效的云电脑服务

      对象存储

      高品质、低成本的云上存储服务

      云硬盘

      为云上计算资源提供持久性块存储

      查看更多

      随机文章

      The controlfile header block returned by the OS has a sequence number that is too old

      Hyperledger Fabric 权限策略和访问控制

      Hyperledger Fabric 隐私保护

      • 7*24小时售后
      • 无忧退款
      • 免费备案
      • 专家服务
      售前咨询热线
      400-810-9889转1
      关注天翼云
      • 旗舰店
      • 天翼云APP
      • 天翼云微信公众号
      服务与支持
      • 备案中心
      • 售前咨询
      • 智能客服
      • 自助服务
      • 工单管理
      • 客户公告
      • 涉诈举报
      账户管理
      • 管理中心
      • 订单管理
      • 余额管理
      • 发票管理
      • 充值汇款
      • 续费管理
      快速入口
      • 天翼云旗舰店
      • 文档中心
      • 最新活动
      • 免费试用
      • 信任中心
      • 天翼云学堂
      云网生态
      • 甄选商城
      • 渠道合作
      • 云市场合作
      了解天翼云
      • 关于天翼云
      • 天翼云APP
      • 服务案例
      • 新闻资讯
      • 联系我们
      热门产品
      • 云电脑
      • 弹性云主机
      • 云电脑政企版
      • 天翼云手机
      • 云数据库
      • 对象存储
      • 云硬盘
      • Web应用防火墙
      • 服务器安全卫士
      • CDN加速
      热门推荐
      • 云服务备份
      • 边缘安全加速平台
      • 全站加速
      • 安全加速
      • 云服务器
      • 云主机
      • 智能边缘云
      • 应用编排服务
      • 微服务引擎
      • 共享流量包
      更多推荐
      • web应用防火墙
      • 密钥管理
      • 等保咨询
      • 安全专区
      • 应用运维管理
      • 云日志服务
      • 文档数据库服务
      • 云搜索服务
      • 数据湖探索
      • 数据仓库服务
      友情链接
      • 中国电信集团
      • 189邮箱
      • 天翼企业云盘
      • 天翼云盘
      ©2025 天翼云科技有限公司版权所有 增值电信业务经营许可证A2.B1.B2-20090001
      公司地址:北京市东城区青龙胡同甲1号、3号2幢2层205-32室
      • 用户协议
      • 隐私政策
      • 个人信息保护
      • 法律声明
      备案 京公网安备11010802043424号 京ICP备 2021034386号