github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/hyperledger/fabric/core/ledger/util/txvalidationflags.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 /* 7 Notice: This file has been modified for Hyperledger Fabric SDK Go usage. 8 Please review third_party pinning scripts and patches for more details. 9 */ 10 11 package util 12 13 import ( 14 "github.com/hyperledger/fabric-protos-go/peer" 15 ) 16 17 // TxValidationFlags is array of transaction validation codes. It is used when committer validates block. 18 type TxValidationFlags []uint8 19 20 // NewTxValidationFlags Create new object-array of validation codes with target size. 21 // Default values: TxValidationCode_NOT_VALIDATED 22 func NewTxValidationFlags(size int) TxValidationFlags { 23 return newTxValidationFlagsSetValue(size, peer.TxValidationCode_NOT_VALIDATED) 24 } 25 26 func newTxValidationFlagsSetValue(size int, value peer.TxValidationCode) TxValidationFlags { 27 inst := make(TxValidationFlags, size) 28 for i := range inst { 29 inst[i] = uint8(value) 30 } 31 32 return inst 33 } 34 35 // Flag returns validation code at specified transaction 36 func (obj TxValidationFlags) Flag(txIndex int) peer.TxValidationCode { 37 return peer.TxValidationCode(obj[txIndex]) 38 } 39 40 // IsValid checks if specified transaction is valid 41 func (obj TxValidationFlags) IsValid(txIndex int) bool { 42 return obj.IsSetTo(txIndex, peer.TxValidationCode_VALID) 43 } 44 45 // IsInvalid checks if specified transaction is invalid 46 func (obj TxValidationFlags) IsInvalid(txIndex int) bool { 47 return !obj.IsValid(txIndex) 48 } 49 50 // IsSetTo returns true if the specified transaction equals flag; false otherwise. 51 func (obj TxValidationFlags) IsSetTo(txIndex int, flag peer.TxValidationCode) bool { 52 return obj.Flag(txIndex) == flag 53 }