Hyperledger Fabric System Chaincode Plugin - missing sample

笑着哭i 提交于 2019-12-11 14:27:42

问题


according to the system chaincode documentation located at:

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

there should be a sample at the repository:

"Every system chaincode must implement the Chaincode Interface and export a constructor method that matches the signature func New() shim.Chaincode in the main package. An example can be found in the repository at examples/plugin/scc."

yet the folder examples/plugin/scc is not present anywhere on github fabric repository ...

can someone please point me in the right direction? thanks

EDIT

the only sample i found is

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

is this the sample the documentation is refering to? if yes, maybe update your documentation ...


回答1:


As a matter of fact there is no big difference between implementing a regular chaincode and the system chaincode. The only difference is that system chaincode is compiled into the peer and run inside peer process or could be turned on as a plugging.

So, yes example you have found is the one you can use to implement system chaincode on your own, e.g. https://github.com/hyperledger/fabric/blob/release/core/scc/samplesyscc/samplesyscc.go.

Moreover you can take a look on other system chaincode to get more general idea, for example you can learn from QSCC (Query System ChainCode).

In order to enable system chaincode you need to make sure to enable it inside core.yaml file for example this is how it looks like for system chaincode compiled into peer code:

# 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

in addition you need to list inside importsysccs.go, e.g.:

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

as alternative you can have your system chaincode as plugin, to enable it you need to setup it within 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


来源:https://stackoverflow.com/questions/48069094/hyperledger-fabric-system-chaincode-plugin-missing-sample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!