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

     1  package types
     2  
     3  import (
     4  	"github.com/ethereum/go-ethereum/common"
     5  
     6  	abci "github.com/fibonacci-chain/fbc/libs/tendermint/abci/types"
     7  )
     8  
     9  // Handler defines the core of the state transition function of an application.
    10  type Handler func(ctx Context, msg Msg) (*Result, error)
    11  
    12  // AnteHandler authenticates transactions, before their internal messages are handled.
    13  // If newCtx.IsZero(), ctx is used instead.
    14  type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, err error)
    15  
    16  type PreDeliverTxHandler func(ctx Context, tx Tx, onlyVerifySig bool)
    17  
    18  type GasRefundHandler func(ctx Context, tx Tx) (fee Coins, err error)
    19  
    20  type AccNonceHandler func(ctx Context, address AccAddress) (nonce uint64)
    21  
    22  type EvmSysContractAddressHandler func(ctx Context, addr AccAddress) bool
    23  
    24  type UpdateFeeCollectorAccHandler func(ctx Context, balance Coins, txFeesplit []*FeeSplitInfo) error
    25  
    26  type LogFix func(tx []Tx, logIndex []int, hasEnterEvmTx []bool, errs []error, resp []abci.ResponseDeliverTx) (logs [][]byte)
    27  type UpdateFeeSplitHandler func(txHash common.Hash, addr AccAddress, fee Coins, isDelete bool)
    28  type GetTxFeeAndFromHandler func(ctx Context, tx Tx) (Coins, bool, string, string, error)
    29  type GetTxFeeHandler func(tx Tx) Coins
    30  type CustomizeOnStop func(ctx Context) error
    31  
    32  type MptCommitHandler func(ctx Context)
    33  
    34  type EvmWatcherCollector func(...IWatcher)
    35  
    36  // AnteDecorator wraps the next AnteHandler to perform custom pre- and post-processing.
    37  type AnteDecorator interface {
    38  	AnteHandle(ctx Context, tx Tx, simulate bool, next AnteHandler) (newCtx Context, err error)
    39  }
    40  
    41  // ChainDecorator chains AnteDecorators together with each AnteDecorator
    42  // wrapping over the decorators further along chain and returns a single AnteHandler.
    43  //
    44  // NOTE: The first element is outermost decorator, while the last element is innermost
    45  // decorator. Decorator ordering is critical since some decorators will expect
    46  // certain checks and updates to be performed (e.g. the Context) before the decorator
    47  // is run. These expectations should be documented clearly in a CONTRACT docline
    48  // in the decorator's godoc.
    49  //
    50  // NOTE: Any application that uses GasMeter to limit transaction processing cost
    51  // MUST set GasMeter with the FIRST AnteDecorator. Failing to do so will cause
    52  // transactions to be processed with an infinite gasmeter and open a DOS attack vector.
    53  // Use `ante.SetUpContextDecorator` or a custom Decorator with similar functionality.
    54  // Returns nil when no AnteDecorator are supplied.
    55  func ChainAnteDecorators(chain ...AnteDecorator) AnteHandler {
    56  	if len(chain) == 0 {
    57  		return nil
    58  	}
    59  
    60  	// handle non-terminated decorators chain
    61  	if (chain[len(chain)-1] != Terminator{}) {
    62  		chain = append(chain, Terminator{})
    63  	}
    64  
    65  	next := ChainAnteDecorators(chain[1:]...)
    66  
    67  	return func(ctx Context, tx Tx, simulate bool) (Context, error) {
    68  		return chain[0].AnteHandle(ctx, tx, simulate, next)
    69  	}
    70  }
    71  
    72  // Terminator AnteDecorator will get added to the chain to simplify decorator code
    73  // Don't need to check if next == nil further up the chain
    74  //
    75  //	                      ______
    76  //	                   <((((((\\\
    77  //	                   /      . }\
    78  //	                   ;--..--._|}
    79  //	(\                 '--/\--'  )
    80  //	 \\                | '-'  :'|
    81  //	  \\               . -==- .-|
    82  //	   \\               \.__.'   \--._
    83  //	   [\\          __.--|       //  _/'--.
    84  //	   \ \\       .'-._ ('-----'/ __/      \
    85  //	    \ \\     /   __>|      | '--.       |
    86  //	     \ \\   |   \   |     /    /       /
    87  //	      \ '\ /     \  |     |  _/       /
    88  //	       \  \       \ |     | /        /
    89  //	 snd    \  \      \        /
    90  type Terminator struct{}
    91  
    92  const AnteTerminatorTag = "ante-terminator"
    93  
    94  // Simply return provided Context and nil error
    95  func (t Terminator) AnteHandle(ctx Context, _ Tx, _ bool, _ AnteHandler) (Context, error) {
    96  	trc := ctx.AnteTracer()
    97  	if trc != nil {
    98  		trc.RepeatingPin(AnteTerminatorTag)
    99  	}
   100  	return ctx, nil
   101  }