package keeper import ( "context" "errors" "fmt" "math/big" "colinear/x/colinearcore/types" sdk "github.com/cosmos/cosmos-sdk/types" ) func (k msgServer) UnlockAllFunds(goCtx context.Context, msg *types.MsgUnlockAllFunds) (*types.MsgUnlockAllFundsResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) lockedUsers, ok := k.Keeper.GetLockedUsers(ctx) if !ok { return nil, errors.New("unable to get locked users") } lockedBalStr, ok := lockedUsers.Users[msg.Creator] if !ok { return nil, fmt.Errorf("no locked balance found for user %s", msg.Creator) } else { if lockedBalStr == "0" { return nil, fmt.Errorf("no CLR to unlock for user %s", msg.Creator) } } sendAmtBI := new(big.Int) sendAmtBI.SetString(lockedBalStr, 10) sendAmt := sdk.NewIntFromBigInt(sendAmtBI) sendCoins := sdk.NewCoins(sdk.NewCoin("uclr", sendAmt)) if err := k.bank.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sdk.AccAddress(msg.Creator), sendCoins); err != nil { return nil, fmt.Errorf("failed to send %s uCLR: %s", lockedBalStr, err) } delete(lockedUsers.Users, msg.Creator) k.Keeper.SetLockedUsers(ctx, lockedUsers) return &types.MsgUnlockAllFundsResponse{}, nil }