问题
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