-
Notifications
You must be signed in to change notification settings - Fork 88
/
validation_flags.go
64 lines (51 loc) · 1.88 KB
/
validation_flags.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
/*
Notice: This file has been modified for Hyperledger Fabric SDK Go usage.
Please review third_party pinning scripts and patches for more details.
*/
package txflags
import (
"github.com/hyperledger/fabric-protos-go/peer"
)
// ValidationFlags is array of transaction validation codes. It is used when committer validates block.
type ValidationFlags []uint8
// New create new object-array of validation codes with target size.
// Default values: TxValidationCode_NOT_VALIDATED
func New(size int) ValidationFlags {
return newWithValues(size, peer.TxValidationCode_NOT_VALIDATED)
}
// NewWithValues creates new object-array of validation codes with target size
// and the supplied value
func NewWithValues(size int, value peer.TxValidationCode) ValidationFlags {
return newWithValues(size, value)
}
func newWithValues(size int, value peer.TxValidationCode) ValidationFlags {
inst := make(ValidationFlags, size)
for i := range inst {
inst[i] = uint8(value)
}
return inst
}
// SetFlag assigns validation code to specified transaction
func (obj ValidationFlags) SetFlag(txIndex int, flag peer.TxValidationCode) {
obj[txIndex] = uint8(flag)
}
// Flag returns validation code at specified transaction
func (obj ValidationFlags) Flag(txIndex int) peer.TxValidationCode {
return peer.TxValidationCode(obj[txIndex])
}
// IsValid checks if specified transaction is valid
func (obj ValidationFlags) IsValid(txIndex int) bool {
return obj.IsSetTo(txIndex, peer.TxValidationCode_VALID)
}
// IsInvalid checks if specified transaction is invalid
func (obj ValidationFlags) IsInvalid(txIndex int) bool {
return !obj.IsValid(txIndex)
}
// IsSetTo returns true if the specified transaction equals flag; false otherwise.
func (obj ValidationFlags) IsSetTo(txIndex int, flag peer.TxValidationCode) bool {
return obj.Flag(txIndex) == flag
}