Hyperledger Fabric系统Chaincode插件 - 缺少样本

时间:2018-01-02 23:10:00

标签: hyperledger-fabric hyperledger

根据位于以下位置的系统链码文档:

https://hyperledger-fabric.readthedocs.io/en/latest/systemchaincode.html

存储库中应该有一个示例:

"每个系统链代码都必须实现Chaincode接口,并导出一个与主包中的签名函数New()shim.Chaincode匹配的构造函数方法。可以在examples / plugin / scc。"

的存储库中找到一个示例

文件夹examples / plugin / scc在github fabric repository ...

上没有出现

有人可以指出我正确的方向吗?感谢

编辑

我发现的唯一样本是

https://github.com/hyperledger/fabric/tree/release/core/scc/samplesyscc

这是文档引用的示例吗?如果是,可以更新您的文档......

1 个答案:

答案 0 :(得分:0)

事实上,实现常规链代码和系统链代码之间没有太大区别。唯一的区别是系统链代码被编译到对等体中并在对等进程内运行,或者可以作为plugging打开。

所以,你找到的例子是你可以用来自己实现系统链码的例子,例如: https://github.com/hyperledger/fabric/blob/release/core/scc/samplesyscc/samplesyscc.go

此外,您可以查看其他系统链代码以获得更一般的想法,例如您可以从QSCC(查询系统链代码)学习。

为了启用系统链代码,您需要确保在core.yaml文件中启用它,例如,这是系统链代码编译成对等代码的样子:

# system chaincodes whitelist. To add system chaincode "myscc" to the
# whitelist, add "myscc: enable" to the list below, and register in
# chaincode/importsysccs.go
system:
    cscc: enable
    lscc: enable
    escc: enable
    vscc: enable
    qscc: enable
    rscc: disable

此外,您需要在importsysccs.go内列出,例如:

var systemChaincodes = []*SystemChaincode{
    {
        Enabled:           true,
        Name:              "cscc",
        Path:              "github.com/hyperledger/fabric/core/scc/cscc",
        InitArgs:          [][]byte{[]byte("")},
        Chaincode:         &cscc.PeerConfiger{},
        InvokableExternal: true, // cscc is invoked to join a channel
    },
    {
        Enabled:           true,
        Name:              "lscc",
        Path:              "github.com/hyperledger/fabric/core/scc/lscc",
        InitArgs:          [][]byte{[]byte("")},
        Chaincode:         lscc.NewLifeCycleSysCC(),
        InvokableExternal: true, // lscc is invoked to deploy new chaincodes
        InvokableCC2CC:    true, // lscc can be invoked by other chaincodes
    },
    {
        Enabled:   true,
        Name:      "escc",
        Path:      "github.com/hyperledger/fabric/core/scc/escc",
        InitArgs:  [][]byte{[]byte("")},
        Chaincode: &escc.EndorserOneValidSignature{},
    },
    {
        Enabled:   true,
        Name:      "vscc",
        Path:      "github.com/hyperledger/fabric/core/scc/vscc",
        InitArgs:  [][]byte{[]byte("")},
        Chaincode: &vscc.ValidatorOneValidSignature{},
    },
    {
        Enabled:           true,
        Name:              "qscc",
        Path:              "github.com/hyperledger/fabric/core/chaincode/qscc",
        InitArgs:          [][]byte{[]byte("")},
        Chaincode:         &qscc.LedgerQuerier{},
        InvokableExternal: true, // qscc can be invoked to retrieve blocks
        InvokableCC2CC:    true, // qscc can be invoked to retrieve blocks also by a cc
    },
    {
        Enabled:           true,
        Name:              "rscc",
        Path:              "github.com/hyperledger/fabric/core/chaincode/rscc",
        InitArgs:          [][]byte{[]byte("")},
        Chaincode:         rscc.NewRscc(),
        InvokableExternal: true,  // rscc can be invoked to update policies
        InvokableCC2CC:    false, // rscc cannot be invoked from a cc
    },
}

作为替代方案,您可以将系统链代码作为插件,要启用它,您需要在core.yaml内设置它:

# System chaincode plugins: in addition to being imported and compiled
# into fabric through core/chaincode/importsysccs.go, system chaincodes
# can also be loaded as shared objects compiled as Go plugins.
# See examples/plugins/scc for an example.
# Like regular system chaincodes, plugins must also be white listed in the
# chaincode.system section above.
systemPlugins:
  # example configuration:
  # - enabled: true
  #   name: myscc
  #   path: /opt/lib/myscc.so
  #   invokableExternal: true
  #   invokableCC2CC: true