github.com/darrenli6/fabric-sdk-example@v0.0.0-20220109053535-94b13b56df8c/core/ledger/util/txvalidationflags.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  		 http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package util
    18  
    19  import (
    20  	"github.com/hyperledger/fabric/protos/peer"
    21  )
    22  
    23  // TxValidationFlags is array of transaction validation codes. It is used when commiter validates block.
    24  type TxValidationFlags []uint8
    25  
    26  // NewTxValidationFlags Create new object-array of validation codes with target size. Default values: valid.
    27  func NewTxValidationFlags(size int) TxValidationFlags {
    28  	inst := make(TxValidationFlags, size)
    29  	return inst
    30  }
    31  
    32  // SetFlag assigns validation code to specified transaction
    33  func (obj TxValidationFlags) SetFlag(txIndex int, flag peer.TxValidationCode) {
    34  	obj[txIndex] = uint8(flag)
    35  }
    36  
    37  // Flag returns validation code at specified transaction
    38  func (obj TxValidationFlags) Flag(txIndex int) peer.TxValidationCode {
    39  	return peer.TxValidationCode(obj[txIndex])
    40  }
    41  
    42  // IsValid checks if specified transaction is valid
    43  func (obj TxValidationFlags) IsValid(txIndex int) bool {
    44  	return obj.IsSetTo(txIndex, peer.TxValidationCode_VALID)
    45  }
    46  
    47  // IsInvalid checks if specified transaction is invalid
    48  func (obj TxValidationFlags) IsInvalid(txIndex int) bool {
    49  	return !obj.IsValid(txIndex)
    50  }
    51  
    52  // IsSetTo returns true if the specified transaction equals flag; false otherwise.
    53  func (obj TxValidationFlags) IsSetTo(txIndex int, flag peer.TxValidationCode) bool {
    54  	return obj.Flag(txIndex) == flag
    55  }