github.com/Finschia/finschia-sdk@v0.48.1/x/crisis/keeper/msg_server.go (about) 1 package keeper 2 3 import ( 4 "context" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 "github.com/Finschia/finschia-sdk/x/crisis/types" 8 ) 9 10 var _ types.MsgServer = Keeper{} 11 12 func (k Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvariant) (*types.MsgVerifyInvariantResponse, error) { 13 ctx := sdk.UnwrapSDKContext(goCtx) 14 constantFee := sdk.NewCoins(k.GetConstantFee(ctx)) 15 16 sender, err := sdk.AccAddressFromBech32(msg.Sender) 17 if err != nil { 18 return nil, err 19 } 20 if err := k.SendCoinsFromAccountToFeeCollector(ctx, sender, constantFee); err != nil { 21 return nil, err 22 } 23 24 // use a cached context to avoid gas costs during invariants 25 cacheCtx, _ := ctx.CacheContext() 26 27 found := false 28 msgFullRoute := msg.FullInvariantRoute() 29 30 var res string 31 var stop bool 32 for _, invarRoute := range k.Routes() { 33 if invarRoute.FullRoute() == msgFullRoute { 34 res, stop = invarRoute.Invar(cacheCtx) 35 found = true 36 37 break 38 } 39 } 40 41 if !found { 42 return nil, types.ErrUnknownInvariant 43 } 44 45 if stop { 46 // Currently, because the chain halts here, this transaction will never be included in the 47 // blockchain thus the constant fee will have never been deducted. Thus no refund is required. 48 49 // TODO replace with circuit breaker 50 panic(res) 51 } 52 53 ctx.EventManager().EmitEvents(sdk.Events{ 54 sdk.NewEvent( 55 types.EventTypeInvariant, 56 sdk.NewAttribute(types.AttributeKeyRoute, msg.InvariantRoute), 57 ), 58 }) 59 60 return &types.MsgVerifyInvariantResponse{}, nil 61 }