【问题标题】:How to install chaincode using fabric sdk (fabric-client)?如何使用fabric sdk(fabric-client)安装链码?
【发布时间】:2019-10-09 08:45:01
【问题描述】:

基于此处列出的包定义https://fabric-sdk-node.github.io/master/tutorial-chaincode-lifecycle.html

const package_request = {
     chaincodeType: 'golang',
     goPath: '/gopath',
     chaincodePath: '/path/to/code',
     metadataPath: '/path/to/metadata'
}

我应该将位于笔记本电脑中的链码 go (golang) 代码的字节数组放在哪里?也不确定chaincodePathmetadataPath 是干什么用的?它们是结构系统中的路径吗?

基本上,我不知道如何将我的 golang 源代码(链码)加载到安装链码的请求中。

【问题讨论】:

  • 你发现了吗?

标签: hyperledger-fabric hyperledger-fabric-sdk-js hyperledger-fabric-sdk-go


【解决方案1】:

chaincodePath 是包含实际链码文件的目录(比如chainCode.go),metadataPath 是可能包含元数据文件的目录,例如如果您的链代码需要,索引文件。

【讨论】:

    【解决方案2】:

    对于fabric-go-sdk,您可以参考chainHeroExample。检查main.gosetup.go 文件。

    下面是main.go文件的sn-p。

    func main() {
        // Definition of the Fabric SDK properties
        fSetup := blockchain.FabricSetup{
            // Network parameters
            OrdererID: "orderer.firstproject.com",
    
            // Channel parameters
            ChannelID:     "mychannel",
            ChannelConfig: "/c/Projects/Go/src/github.com/hyperledger/firstproject/firstproject-network/artifacts/channel.tx",
    
            // Chaincode parameters
            ChainCodeID:     "firstproject",
            ChaincodeGoPath: "/c/Projects/Go",
            ChaincodePath:   "github.com/hyperledger/firstproject/chaincode/",
            OrgAdmin:        "Admin",
            OrgName:         "org1",
            ConfigFile:      "config.yaml",
    
            // User parameters
            UserName: "User1",
        }
    
        // Initialization of the Fabric SDK from the previously set properties
        err := fSetup.Initialize()
        if err != nil {
            fmt.Printf("Unable to initialize the Fabric SDK: %v\n", err)
            return
        }
        // Close SDK
        defer fSetup.CloseSDK()
    
        // Install and instantiate the chaincode
        err = fSetup.InstallAndInstantiateCC()
        if err != nil {
            fmt.Printf("Unable to install and instantiate the chaincode: %v\n", err)
            return
        }
    
        // Query the chaincode
        response, err := fSetup.QueryHello()
        if err != nil {
            fmt.Printf("Unable to query hello on the chaincode: %v\n", err)
        } else {
            fmt.Printf("Response from the query hello: %s\n", response)
        }
    

    【讨论】:

      【解决方案3】:

      要安装链码,您必须使用以下方法:

      installCCReq := resmgmt.InstallCCRequest{
                      Name: ccName,
                      Path: ccPath, 
                      Version: ccVersion,
                      Package: ccPkg}
      

      这是完整的example,这是完整的documentation

      【讨论】:

        猜你喜欢
        • 2018-11-20
        • 2018-01-19
        • 2020-10-12
        • 1970-01-01
        • 2020-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-26
        相关资源
        最近更新 更多