github.com/Hnampk/fabric@v2.1.1+incompatible/core/ledger/kvledger/txmgmt/txmgr/txmgr.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 txmgr
    18  
    19  import (
    20  	"github.com/hyperledger/fabric-protos-go/common"
    21  	"github.com/hyperledger/fabric-protos-go/peer"
    22  	"github.com/hyperledger/fabric/core/ledger"
    23  	"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
    24  )
    25  
    26  // TxMgr - an interface that a transaction manager should implement
    27  type TxMgr interface {
    28  	NewQueryExecutor(txid string) (ledger.QueryExecutor, error)
    29  	NewTxSimulator(txid string) (ledger.TxSimulator, error)
    30  	ValidateAndPrepare(blockAndPvtdata *ledger.BlockAndPvtData, doMVCCValidation bool) ([]*TxStatInfo, []byte, error)
    31  	RemoveStaleAndCommitPvtDataOfOldBlocks(blocksPvtData map[uint64][]*ledger.TxPvtData) error
    32  	GetLastSavepoint() (*version.Height, error)
    33  	ShouldRecover(lastAvailableBlock uint64) (bool, uint64, error)
    34  	CommitLostBlock(blockAndPvtdata *ledger.BlockAndPvtData) error
    35  	Commit() error
    36  	Rollback()
    37  	Shutdown()
    38  	Name() string
    39  }
    40  
    41  // TxStatInfo encapsulates information about a transaction
    42  type TxStatInfo struct {
    43  	ValidationCode peer.TxValidationCode
    44  	TxType         common.HeaderType
    45  	ChaincodeID    *peer.ChaincodeID
    46  	NumCollections int
    47  }
    48  
    49  // ErrUnsupportedTransaction is expected to be thrown if a unsupported query is performed in an update transaction
    50  type ErrUnsupportedTransaction struct {
    51  	Msg string
    52  }
    53  
    54  func (e *ErrUnsupportedTransaction) Error() string {
    55  	return e.Msg
    56  }
    57  
    58  // ErrPvtdataNotAvailable is to be thrown when an application seeks a private data item
    59  // during simulation and the simulator is not capable of returning the version of the
    60  // private data item consistent with the snapshot exposed to the simulation
    61  type ErrPvtdataNotAvailable struct {
    62  	Msg string
    63  }
    64  
    65  func (e *ErrPvtdataNotAvailable) Error() string {
    66  	return e.Msg
    67  }
    68  
    69  //go:generate counterfeiter -o mock/tx_mgr.go -fake-name TxMgr . TxMgr