@@ -17,6 +17,7 @@ import (
1717 "github.com/hyperledger/fabric/core/handlers/auth"
1818 "github.com/hyperledger/fabric/core/handlers/decoration"
1919 endorsement2 "github.com/hyperledger/fabric/core/handlers/endorsement/api"
20+ "github.com/hyperledger/fabric/core/handlers/validation/api"
2021)
2122
2223var logger = flogging .MustGetLogger ("core/handlers" )
@@ -40,16 +41,18 @@ const (
4041 // passed to the chaincode
4142 Decoration
4243 Endorsement
44+ Validation
4345
44- authPluginFactory = "NewFilter"
45- decoratorPluginFactory = "NewDecorator"
46- endorsementPluginFactory = "NewPluginFactory"
46+ authPluginFactory = "NewFilter"
47+ decoratorPluginFactory = "NewDecorator"
48+ pluginFactory = "NewPluginFactory"
4749)
4850
4951type registry struct {
5052 filters []auth.Filter
5153 decorators []decoration.Decorator
5254 endorsers map [string ]endorsement2.PluginFactory
55+ validators map [string ]validation.PluginFactory
5356}
5457
5558var once sync.Once
@@ -61,6 +64,7 @@ type Config struct {
6164 AuthFilters []* HandlerConfig `mapstructure:"authFilters" yaml:"authFilters"`
6265 Decorators []* HandlerConfig `mapstructure:"decorators" yaml:"decorators"`
6366 Endorsers PluginMapping `mapstructure:"endorsers" yaml:"endorsers"`
67+ Validators PluginMapping `mapstructure:"validators" yaml:"validators"`
6468}
6569
6670type PluginMapping map [string ]* HandlerConfig
@@ -75,7 +79,10 @@ type HandlerConfig struct {
7579// of the registry
7680func InitRegistry (c Config ) Registry {
7781 once .Do (func () {
78- reg = registry {endorsers : make (map [string ]endorsement2.PluginFactory )}
82+ reg = registry {
83+ endorsers : make (map [string ]endorsement2.PluginFactory ),
84+ validators : make (map [string ]validation.PluginFactory ),
85+ }
7986 reg .loadHandlers (c )
8087 })
8188 return & reg
@@ -93,6 +100,10 @@ func (r *registry) loadHandlers(c Config) {
93100 for chaincodeID , config := range c .Endorsers {
94101 r .evaluateModeAndLoad (config , Endorsement , chaincodeID )
95102 }
103+
104+ for chaincodeID , config := range c .Validators {
105+ r .evaluateModeAndLoad (config , Validation , chaincodeID )
106+ }
96107}
97108
98109// evaluateModeAndLoad if a library path is provided, load the shared object
@@ -124,6 +135,11 @@ func (r *registry) loadCompiled(handlerFactory string, handlerType HandlerType,
124135 logger .Panicf ("expected 1 argument in extraArgs" )
125136 }
126137 r .endorsers [extraArgs [0 ]] = inst .(endorsement2.PluginFactory )
138+ } else if handlerType == Validation {
139+ if len (extraArgs ) != 1 {
140+ logger .Panicf ("expected 1 argument in extraArgs" )
141+ }
142+ r .validators [extraArgs [0 ]] = inst .(validation.PluginFactory )
127143 }
128144}
129145
@@ -143,6 +159,8 @@ func (r *registry) loadPlugin(pluginPath string, handlerType HandlerType, extraA
143159 r .initDecoratorPlugin (p )
144160 } else if handlerType == Endorsement {
145161 r .initEndorsementPlugin (p , extraArgs ... )
162+ } else if handlerType == Validation {
163+ r .initValidationPlugin (p , extraArgs ... )
146164 }
147165}
148166
@@ -183,14 +201,14 @@ func (r *registry) initEndorsementPlugin(p *plugin.Plugin, extraArgs ...string)
183201 if len (extraArgs ) != 1 {
184202 logger .Panicf ("expected 1 argument in extraArgs" )
185203 }
186- factorySymbol , err := p .Lookup (endorsementPluginFactory )
204+ factorySymbol , err := p .Lookup (pluginFactory )
187205 if err != nil {
188- panicWithLookupError (endorsementPluginFactory , err )
206+ panicWithLookupError (pluginFactory , err )
189207 }
190208
191209 constructor , ok := factorySymbol .(func () endorsement2.PluginFactory )
192210 if ! ok {
193- panicWithDefinitionError (endorsementPluginFactory )
211+ panicWithDefinitionError (pluginFactory )
194212 }
195213 factory := constructor ()
196214 if factory == nil {
@@ -199,6 +217,26 @@ func (r *registry) initEndorsementPlugin(p *plugin.Plugin, extraArgs ...string)
199217 r .endorsers [extraArgs [0 ]] = factory
200218}
201219
220+ func (r * registry ) initValidationPlugin (p * plugin.Plugin , extraArgs ... string ) {
221+ if len (extraArgs ) != 1 {
222+ logger .Panicf ("expected 1 argument in extraArgs" )
223+ }
224+ factorySymbol , err := p .Lookup (pluginFactory )
225+ if err != nil {
226+ panicWithLookupError (pluginFactory , err )
227+ }
228+
229+ constructor , ok := factorySymbol .(func () validation.PluginFactory )
230+ if ! ok {
231+ panicWithDefinitionError (pluginFactory )
232+ }
233+ factory := constructor ()
234+ if factory == nil {
235+ logger .Panicf ("factory instance returned nil" )
236+ }
237+ r .validators [extraArgs [0 ]] = factory
238+ }
239+
202240// panicWithLookupError panics when a handler constructor lookup fails
203241func panicWithLookupError (factory string , err error ) {
204242 logger .Panicf (fmt .Sprintf ("Plugin must contain constructor with name %s. Error from lookup: %s" ,
@@ -221,6 +259,8 @@ func (r *registry) Lookup(handlerType HandlerType) interface{} {
221259 return r .decorators
222260 } else if handlerType == Endorsement {
223261 return r .endorsers
262+ } else if handlerType == Validation {
263+ return r .validators
224264 }
225265
226266 return nil
0 commit comments