@@ -17,6 +17,7 @@ import (
17
17
"github.com/hyperledger/fabric/core/handlers/auth"
18
18
"github.com/hyperledger/fabric/core/handlers/decoration"
19
19
endorsement2 "github.com/hyperledger/fabric/core/handlers/endorsement/api"
20
+ "github.com/hyperledger/fabric/core/handlers/validation/api"
20
21
)
21
22
22
23
var logger = flogging .MustGetLogger ("core/handlers" )
@@ -40,16 +41,18 @@ const (
40
41
// passed to the chaincode
41
42
Decoration
42
43
Endorsement
44
+ Validation
43
45
44
- authPluginFactory = "NewFilter"
45
- decoratorPluginFactory = "NewDecorator"
46
- endorsementPluginFactory = "NewPluginFactory"
46
+ authPluginFactory = "NewFilter"
47
+ decoratorPluginFactory = "NewDecorator"
48
+ pluginFactory = "NewPluginFactory"
47
49
)
48
50
49
51
type registry struct {
50
52
filters []auth.Filter
51
53
decorators []decoration.Decorator
52
54
endorsers map [string ]endorsement2.PluginFactory
55
+ validators map [string ]validation.PluginFactory
53
56
}
54
57
55
58
var once sync.Once
@@ -61,6 +64,7 @@ type Config struct {
61
64
AuthFilters []* HandlerConfig `mapstructure:"authFilters" yaml:"authFilters"`
62
65
Decorators []* HandlerConfig `mapstructure:"decorators" yaml:"decorators"`
63
66
Endorsers PluginMapping `mapstructure:"endorsers" yaml:"endorsers"`
67
+ Validators PluginMapping `mapstructure:"validators" yaml:"validators"`
64
68
}
65
69
66
70
type PluginMapping map [string ]* HandlerConfig
@@ -75,7 +79,10 @@ type HandlerConfig struct {
75
79
// of the registry
76
80
func InitRegistry (c Config ) Registry {
77
81
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
+ }
79
86
reg .loadHandlers (c )
80
87
})
81
88
return & reg
@@ -93,6 +100,10 @@ func (r *registry) loadHandlers(c Config) {
93
100
for chaincodeID , config := range c .Endorsers {
94
101
r .evaluateModeAndLoad (config , Endorsement , chaincodeID )
95
102
}
103
+
104
+ for chaincodeID , config := range c .Validators {
105
+ r .evaluateModeAndLoad (config , Validation , chaincodeID )
106
+ }
96
107
}
97
108
98
109
// evaluateModeAndLoad if a library path is provided, load the shared object
@@ -124,6 +135,11 @@ func (r *registry) loadCompiled(handlerFactory string, handlerType HandlerType,
124
135
logger .Panicf ("expected 1 argument in extraArgs" )
125
136
}
126
137
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 )
127
143
}
128
144
}
129
145
@@ -143,6 +159,8 @@ func (r *registry) loadPlugin(pluginPath string, handlerType HandlerType, extraA
143
159
r .initDecoratorPlugin (p )
144
160
} else if handlerType == Endorsement {
145
161
r .initEndorsementPlugin (p , extraArgs ... )
162
+ } else if handlerType == Validation {
163
+ r .initValidationPlugin (p , extraArgs ... )
146
164
}
147
165
}
148
166
@@ -183,14 +201,14 @@ func (r *registry) initEndorsementPlugin(p *plugin.Plugin, extraArgs ...string)
183
201
if len (extraArgs ) != 1 {
184
202
logger .Panicf ("expected 1 argument in extraArgs" )
185
203
}
186
- factorySymbol , err := p .Lookup (endorsementPluginFactory )
204
+ factorySymbol , err := p .Lookup (pluginFactory )
187
205
if err != nil {
188
- panicWithLookupError (endorsementPluginFactory , err )
206
+ panicWithLookupError (pluginFactory , err )
189
207
}
190
208
191
209
constructor , ok := factorySymbol .(func () endorsement2.PluginFactory )
192
210
if ! ok {
193
- panicWithDefinitionError (endorsementPluginFactory )
211
+ panicWithDefinitionError (pluginFactory )
194
212
}
195
213
factory := constructor ()
196
214
if factory == nil {
@@ -199,6 +217,26 @@ func (r *registry) initEndorsementPlugin(p *plugin.Plugin, extraArgs ...string)
199
217
r .endorsers [extraArgs [0 ]] = factory
200
218
}
201
219
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
+
202
240
// panicWithLookupError panics when a handler constructor lookup fails
203
241
func panicWithLookupError (factory string , err error ) {
204
242
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{} {
221
259
return r .decorators
222
260
} else if handlerType == Endorsement {
223
261
return r .endorsers
262
+ } else if handlerType == Validation {
263
+ return r .validators
224
264
}
225
265
226
266
return nil
0 commit comments