From bc6ce703af0d36e55ff614934660ce46a5bc5d98 Mon Sep 17 00:00:00 2001 From: Alessandro Sorniotti Date: Wed, 6 Dec 2017 17:52:00 +0100 Subject: [PATCH] [FAB-6228] add implementation of ChaincodeByName This change set introduces the proper implementation for the ChaincodeByName function exposed by the Support interface for the endorser. Change-Id: If70b5e8171a4cffcbbd941220994f477fe5e4b0c Signed-off-by: Alessandro Sorniotti --- core/peer/peer.go | 11 +++++++++++ core/peer/support.go | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/peer/peer.go b/core/peer/peer.go index fca7d50aaeb..4429b4bf30f 100644 --- a/core/peer/peer.go +++ b/core/peer/peer.go @@ -450,6 +450,17 @@ func GetLedger(cid string) ledger.PeerLedger { return nil } +// GetResourcesConfig returns the resources configuration of the chain with channel ID. Note that this +// call returns nil if chain cid has not been created. +func GetResourcesConfig(cid string) resourcesconfig.Resources { + chains.RLock() + defer chains.RUnlock() + if c, ok := chains.list[cid]; ok { + return c.cs.bundleSource.StableBundle() + } + return nil +} + // GetChannelConfig returns the channel configuration of the chain with channel ID. Note that this // call returns nil if chain cid has not been created. func GetChannelConfig(cid string) channelconfig.Resources { diff --git a/core/peer/support.go b/core/peer/support.go index e8d92dc594e..da366b8406a 100644 --- a/core/peer/support.go +++ b/core/peer/support.go @@ -43,8 +43,12 @@ func (s *supportImpl) GetApplicationConfig(cid string) (channelconfig.Applicatio } func (s *supportImpl) ChaincodeByName(chainname, ccname string) (resourcesconfig.ChaincodeDefinition, bool) { - // FIXME: implement me properly - return nil, false + rc := GetResourcesConfig(chainname) + if rc == nil { + return nil, false + } + + return rc.ChaincodeRegistry().ChaincodeByName(ccname) } type SupportFactoryImpl struct {