github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/handlers/validation/api/validation.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package validation
     8  
     9  import "github.com/hyperledger/fabric-protos-go/common"
    10  
    11  // Argument defines the argument for validation
    12  type Argument interface {
    13  	Dependency
    14  	// Arg returns the bytes of the argument
    15  	Arg() []byte
    16  }
    17  
    18  // Dependency marks a dependency passed to the Init() method
    19  type Dependency interface{}
    20  
    21  // ContextDatum defines additional data that is passed from the validator
    22  // into the Validate() invocation
    23  type ContextDatum interface{}
    24  
    25  // Plugin validates transactions
    26  type Plugin interface {
    27  	// Validate returns nil if the action at the given position inside the transaction
    28  	// at the given position in the given block is valid, or an error if not.
    29  	Validate(block *common.Block, namespace string, txPosition int, actionPosition int, contextData ...ContextDatum) error
    30  
    31  	// Init injects dependencies into the instance of the Plugin
    32  	Init(dependencies ...Dependency) error
    33  }
    34  
    35  // PluginFactory creates a new instance of a Plugin
    36  type PluginFactory interface {
    37  	New() Plugin
    38  }
    39  
    40  // ExecutionFailureError indicates that the validation
    41  // failed because of an execution problem, and thus
    42  // the transaction validation status could not be computed
    43  type ExecutionFailureError struct {
    44  	Reason string
    45  }
    46  
    47  // Error conveys this is an error, and also contains
    48  // the reason for the error
    49  func (e *ExecutionFailureError) Error() string {
    50  	return e.Reason
    51  }