github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/baseapp/baseapp_checktx.go (about)

     1  package baseapp
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"sync/atomic"
     7  
     8  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     9  	sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors"
    10  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
    11  	"github.com/fibonacci-chain/fbc/libs/tendermint/global"
    12  )
    13  
    14  // CheckTx implements the ABCI interface and executes a tx in CheckTx mode. In
    15  // CheckTx mode, messages are not executed. This means messages are only validated
    16  // and only the AnteHandler is executed. State is persisted to the BaseApp's
    17  // internal CheckTx state if the AnteHandler passes. Otherwise, the ResponseCheckTx
    18  // will contain releveant error information. Regardless of tx execution outcome,
    19  // the ResponseCheckTx will contain relevant gas execution context.
    20  func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
    21  	tx, err := app.txDecoder(req.Tx, global.GetGlobalHeight())
    22  	if err != nil {
    23  		return sdkerrors.ResponseCheckTx(err, 0, 0, app.trace)
    24  	}
    25  
    26  	var mode runTxMode
    27  
    28  	switch {
    29  	case req.Type == abci.CheckTxType_New:
    30  		mode = runTxModeCheck
    31  		atomic.AddInt64(&app.checkTxNum, 1)
    32  	case req.Type == abci.CheckTxType_Recheck:
    33  		mode = runTxModeReCheck
    34  
    35  	case req.Type == abci.CheckTxType_WrappedCheck:
    36  		mode = runTxModeWrappedCheck
    37  		atomic.AddInt64(&app.wrappedCheckTxNum, 1)
    38  
    39  	default:
    40  		panic(fmt.Sprintf("unknown RequestCheckTx type: %s", req.Type))
    41  	}
    42  
    43  	if abci.GetDisableCheckTx() {
    44  		var ctx sdk.Context
    45  		ctx = app.getContextForTx(mode, req.Tx)
    46  		exTxInfo := app.GetTxInfo(ctx, tx)
    47  		data, _ := json.Marshal(exTxInfo)
    48  
    49  		return abci.ResponseCheckTx{
    50  			Tx:          tx,
    51  			SenderNonce: exTxInfo.SenderNonce,
    52  			Data:        data,
    53  		}
    54  	}
    55  
    56  	info, err := app.runTx(mode, req.Tx, tx, LatestSimulateTxHeight, req.From)
    57  	if err != nil {
    58  		return sdkerrors.ResponseCheckTx(err, info.gInfo.GasWanted, info.gInfo.GasUsed, app.trace)
    59  	}
    60  
    61  	return abci.ResponseCheckTx{
    62  		Tx:          tx,
    63  		SenderNonce: info.accountNonce,
    64  		GasWanted:   int64(info.gInfo.GasWanted), // TODO: Should type accept unsigned ints?
    65  		GasUsed:     int64(info.gInfo.GasUsed),   // TODO: Should type accept unsigned ints?
    66  		Log:         info.result.Log,
    67  		Data:        info.result.Data,
    68  		Events:      info.result.Events.ToABCIEvents(),
    69  	}
    70  }