github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/staking/keeper/keeper_ibc.go (about)

     1  package keeper
     2  
     3  import (
     4  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/prefix"
     5  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/query"
     7  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/staking/types"
     8  )
     9  
    10  func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
    11  	delAddr sdk.AccAddress, valAddr sdk.ValAddress) (ubd types.UnbondingDelegation, found bool) {
    12  
    13  	store := ctx.KVStore(k.storeKey)
    14  	key := types.GetUBDKey(delAddr, valAddr)
    15  	value := store.Get(key)
    16  	if value == nil {
    17  		return ubd, false
    18  	}
    19  
    20  	ubd = types.MustUnmarshalUBD(k.cdcMarshl.GetCdc(), value)
    21  	return ubd, true
    22  }
    23  
    24  func (k Keeper) GetDelegatorUnbondingDelegations(ctx sdk.Context,
    25  	delAddr sdk.AccAddress, page *query.PageRequest) (types.UnbondingDelegations, *query.PageResponse, error) {
    26  
    27  	var unbondingDelegations types.UnbondingDelegations
    28  
    29  	store := ctx.KVStore(k.storeKey)
    30  	unbStore := prefix.NewStore(store, types.GetUBDsKey(delAddr))
    31  	pageRes, err := query.Paginate(unbStore, page, func(key []byte, value []byte) error {
    32  		unbond, err := types.UnmarshalUBD(k.cdcMarshl.GetCdc(), value)
    33  		if err != nil {
    34  			return err
    35  		}
    36  		unbondingDelegations = append(unbondingDelegations, unbond)
    37  		return nil
    38  	})
    39  	if err != nil {
    40  		return nil, nil, nil
    41  	}
    42  
    43  	return unbondingDelegations, pageRes, nil
    44  }