如何使用Fabric SDK(Fabric-Client)安装Chaincode?

时间:2019-05-22 19:48:30

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

根据此处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'
}

我应该把笔记本电脑上链代码的字节数组放到哪里(golang)代码?还不确定chaincodePathmetadataPath是做什么用的?他们在结构系统中走了吗?

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

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

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

下面是main.go文件的摘要。

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)
    }

答案 2 :(得分:0)

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

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

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