MCPcopy
hub / github.com/hyperledger/fabric / DeployedChaincodes

Function DeployedChaincodes

core/cclifecycle/util.go:26–82  ·  view source on GitHub ↗

DeployedChaincodes retrieves the metadata of the given deployed chaincodes

(q Query, filter ChaincodePredicate, loadCollections bool, chaincodes ...string)

Source from the content-addressed store, hash-verified

24
25// DeployedChaincodes retrieves the metadata of the given deployed chaincodes
26func DeployedChaincodes(q Query, filter ChaincodePredicate, loadCollections bool, chaincodes ...string) (chaincode.MetadataSet, error) {
27 defer q.Done()
28
29 var res chaincode.MetadataSet
30 for _, cc := range chaincodes {
31 data, err := q.GetState("lscc", cc)
32 if err != nil {
33 Logger.Error("Failed querying lscc namespace:", err)
34 return nil, errors.WithStack(err)
35 }
36 if len(data) == 0 {
37 Logger.Info("Chaincode", cc, "isn't instantiated")
38 continue
39 }
40 ccInfo, err := extractCCInfo(data)
41 if err != nil {
42 Logger.Error("Failed extracting chaincode info about", cc, "from LSCC returned payload. Error:", err)
43 continue
44 }
45 if ccInfo.Name != cc {
46 Logger.Error("Chaincode", cc, "is listed in LSCC as", ccInfo.Name)
47 continue
48 }
49
50 instCC := chaincode.Metadata{
51 Name: ccInfo.Name,
52 Version: ccInfo.Version,
53 Id: ccInfo.Id,
54 Policy: ccInfo.Policy,
55 }
56
57 if !filter(instCC) {
58 Logger.Debug("Filtered out", instCC)
59 continue
60 }
61
62 if loadCollections {
63 key := privdata.BuildCollectionKVSKey(cc)
64 collectionData, err := q.GetState("lscc", key)
65 if err != nil {
66 Logger.Errorf("Failed querying lscc namespace for %s: %v", key, err)
67 return nil, errors.WithStack(err)
68 }
69 ccp, err := privdata.ParseCollectionConfig(collectionData)
70 if err != nil {
71 Logger.Errorf("failed to parse collection config, error %s", err.Error())
72 return nil, errors.Wrapf(err, "failed to parse collection config")
73 }
74 instCC.CollectionsConfig = ccp
75 Logger.Debug("Retrieved collection config for", cc, "from", key)
76 }
77
78 res = append(res, instCC)
79 }
80 Logger.Debug("Returning", res)
81 return res, nil
82}
83

Callers 1

MetadataMethod · 0.85

Calls 10

BuildCollectionKVSKeyFunction · 0.92
ParseCollectionConfigFunction · 0.92
extractCCInfoFunction · 0.85
DebugMethod · 0.80
DoneMethod · 0.65
GetStateMethod · 0.65
ErrorMethod · 0.65
InfoMethod · 0.65
ErrorfMethod · 0.65
filterStruct · 0.50

Tested by

no test coverage detected