github.com/KiraCore/sekai@v0.3.43/x/layer2/keeper/dapp_leader_denounce.go (about)

     1  package keeper
     2  
     3  import (
     4  	"github.com/KiraCore/sekai/x/layer2/types"
     5  	sdk "github.com/cosmos/cosmos-sdk/types"
     6  )
     7  
     8  func (k Keeper) SetDappLeaderDenouncement(ctx sdk.Context, denouncement types.DappLeaderDenouncement) {
     9  	bz := k.cdc.MustMarshal(&denouncement)
    10  	store := ctx.KVStore(k.storeKey)
    11  	store.Set(types.DappLeaderDenouncementKey(denouncement.DappName, denouncement.Leader, denouncement.Sender), bz)
    12  }
    13  
    14  func (k Keeper) DeleteDappLeaderDenouncement(ctx sdk.Context, name, denouncement, sender string) {
    15  	store := ctx.KVStore(k.storeKey)
    16  	store.Delete(types.DappLeaderDenouncementKey(name, denouncement, sender))
    17  }
    18  
    19  func (k Keeper) GetDappLeaderDenouncement(ctx sdk.Context, name, denouncement, sender string) types.DappLeaderDenouncement {
    20  	store := ctx.KVStore(k.storeKey)
    21  	bz := store.Get(types.DappLeaderDenouncementKey(name, denouncement, sender))
    22  	if bz == nil {
    23  		return types.DappLeaderDenouncement{}
    24  	}
    25  
    26  	denouncementInfo := types.DappLeaderDenouncement{}
    27  	k.cdc.MustUnmarshal(bz, &denouncementInfo)
    28  	return denouncementInfo
    29  }
    30  
    31  func (k Keeper) GetDappLeaderDenouncements(ctx sdk.Context, name, denouncement string) []types.DappLeaderDenouncement {
    32  	store := ctx.KVStore(k.storeKey)
    33  
    34  	denouncements := []types.DappLeaderDenouncement{}
    35  	it := sdk.KVStorePrefixIterator(store, append(append([]byte(types.PrefixDappLeaderDenouncementKey), name...), denouncement...))
    36  	defer it.Close()
    37  
    38  	for ; it.Valid(); it.Next() {
    39  		denouncement := types.DappLeaderDenouncement{}
    40  		k.cdc.MustUnmarshal(it.Value(), &denouncement)
    41  		denouncements = append(denouncements, denouncement)
    42  	}
    43  	return denouncements
    44  }
    45  
    46  func (k Keeper) GetAllDappLeaderDenouncements(ctx sdk.Context) []types.DappLeaderDenouncement {
    47  	store := ctx.KVStore(k.storeKey)
    48  
    49  	denouncements := []types.DappLeaderDenouncement{}
    50  	it := sdk.KVStorePrefixIterator(store, []byte(types.PrefixDappLeaderDenouncementKey))
    51  	defer it.Close()
    52  
    53  	for ; it.Valid(); it.Next() {
    54  		denouncement := types.DappLeaderDenouncement{}
    55  		k.cdc.MustUnmarshal(it.Value(), &denouncement)
    56  		denouncements = append(denouncements, denouncement)
    57  	}
    58  	return denouncements
    59  }