github.com/Finschia/finschia-sdk@v0.49.1/x/auth/ante/ext.go (about)

     1  package ante
     2  
     3  import (
     4  	codectypes "github.com/Finschia/finschia-sdk/codec/types"
     5  	"github.com/Finschia/finschia-sdk/types"
     6  	sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
     7  )
     8  
     9  type HasExtensionOptionsTx interface {
    10  	GetExtensionOptions() []*codectypes.Any
    11  	GetNonCriticalExtensionOptions() []*codectypes.Any
    12  }
    13  
    14  // RejectExtensionOptionsDecorator is an AnteDecorator that rejects all extension
    15  // options which can optionally be included in protobuf transactions. Users that
    16  // need extension options should create a custom AnteHandler chain that handles
    17  // needed extension options properly and rejects unknown ones.
    18  type RejectExtensionOptionsDecorator struct{}
    19  
    20  // NewRejectExtensionOptionsDecorator creates a new RejectExtensionOptionsDecorator
    21  func NewRejectExtensionOptionsDecorator() RejectExtensionOptionsDecorator {
    22  	return RejectExtensionOptionsDecorator{}
    23  }
    24  
    25  var _ types.AnteDecorator = RejectExtensionOptionsDecorator{}
    26  
    27  // AnteHandle implements the AnteDecorator.AnteHandle method
    28  func (r RejectExtensionOptionsDecorator) AnteHandle(ctx types.Context, tx types.Tx, simulate bool, next types.AnteHandler) (newCtx types.Context, err error) {
    29  	if hasExtOptsTx, ok := tx.(HasExtensionOptionsTx); ok {
    30  		if len(hasExtOptsTx.GetExtensionOptions()) != 0 {
    31  			return ctx, sdkerrors.ErrUnknownExtensionOptions
    32  		}
    33  	}
    34  
    35  	return next(ctx, tx, simulate)
    36  }