/
blocks.go
38 lines (31 loc) · 1.52 KB
/
blocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/desmos-labs/desmos/v5/x/relationships/types"
)
// SaveUserBlock allows to store the given block inside the store
func (k Keeper) SaveUserBlock(ctx sdk.Context, userBlock types.UserBlock) {
store := ctx.KVStore(k.storeKey)
key := types.UserBlockStoreKey(userBlock.Blocker, userBlock.Blocked, userBlock.SubspaceID)
store.Set(key, k.cdc.MustMarshal(&userBlock))
}
// HasUserBlocked returns true if the provided blocker has blocked the given user for the given subspace.
func (k Keeper) HasUserBlocked(ctx sdk.Context, blocker, blocked string, subspaceID uint64) bool {
store := ctx.KVStore(k.storeKey)
return store.Has(types.UserBlockStoreKey(blocker, blocked, subspaceID))
}
// GetUserBlock returns the user block that has been created from the given blocker towards the provided
// blocked address for the specified subspace.
func (k Keeper) GetUserBlock(ctx sdk.Context, blocker, blocked string, subspaceID uint64) (userBlock types.UserBlock, found bool) {
store := ctx.KVStore(k.storeKey)
key := types.UserBlockStoreKey(blocker, blocked, subspaceID)
if !store.Has(key) {
return types.UserBlock{}, false
}
return types.MustUnmarshalUserBlock(k.cdc, store.Get(key)), true
}
// DeleteUserBlock allows to the specified blocker to unblock the given blocked user
func (k Keeper) DeleteUserBlock(ctx sdk.Context, blocker, blocked string, subspaceID uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.UserBlockStoreKey(blocker, blocked, subspaceID))
}