forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 11
/
router.go
50 lines (41 loc) · 1.6 KB
/
router.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package txvalidator
import (
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric/common/channelconfig"
)
//go:generate mockery -dir . -name Validator -case underscore -output mocks
// Validator defines API to validate transactions in a block
type Validator interface {
// Validate returns an error if validation could not be performed successfully
// In case of successful validation, the block is modified to reflect the validity
// of the transactions it contains
Validate(block *common.Block) error
}
//go:generate mockery -dir . -name CapabilityProvider -case underscore -output mocks
// CapabilityProvider contains functions to retrieve capability information for a channel
type CapabilityProvider interface {
// Capabilities defines the capabilities for the application portion of this channel
Capabilities() channelconfig.ApplicationCapabilities
}
// ValidationRouter dynamically invokes the appropriate validator depending on the
// capabilities that are currently enabled in the channel.
type ValidationRouter struct {
CapabilityProvider
V20Validator Validator
V14Validator Validator
}
// Validate returns an error if validation could not be performed successfully
// In case of successful validation, the block is modified to reflect the validity
// of the transactions it contains
func (v *ValidationRouter) Validate(block *common.Block) error {
switch {
case v.Capabilities().V2_0Validation():
return v.V20Validator.Validate(block)
default:
return v.V14Validator.Validate(block)
}
}