func (k Keeper) Delete(ctx sdk.Context, owner sdk.AccAddress, resourceHash hash.Hash) error {
	store := ctx.KVStore(k.storeKey)
	own, err := k.get(store, resourceHash)
	if err != nil {
		return err
	}
	if own == nil {
		return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "resource %q do not have any ownership", resourceHash)
	}
	if own.Owner != owner.String() {
		return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "resource %q is not owned by you", resourceHash)
	}
	coins := k.bankKeeper.GetCoins(ctx, own.ResourceAddress)
	if !coins.IsZero() {
		if err := k.bankKeeper.SendCoins(ctx, own.ResourceAddress, owner, coins); err != nil {
			return err
		}
	}
	store.Delete(own.Hash)
	ctx.EventManager().EmitEvent(
		sdk.NewEvent(
			types.EventType,
			sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeActionDeleted),
			sdk.NewAttribute(types.AttributeKeyHash, own.Hash.String()),
			sdk.NewAttribute(types.AttributeKeyResourceHash, own.ResourceHash.String()),
			sdk.NewAttribute(types.AttributeKeyResourceType, own.Resource.String()),
			sdk.NewAttribute(types.AttributeKeyResourceAddress, own.ResourceAddress.String()),
		),
	)
	return nil
}
Delete deletes an ownership.
package keeper
import (
	"fmt"
	"github.com/cosmos/cosmos-sdk/codec"
	sdk "github.com/cosmos/cosmos-sdk/types"
	sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
	"github.com/mesg-foundation/engine/hash"
	"github.com/mesg-foundation/engine/ownership"
	"github.com/mesg-foundation/engine/x/ownership/internal/types"
	"github.com/tendermint/tendermint/libs/log"
)
type Keeper struct {
	storeKey sdk.StoreKey
	cdc      *codec.Codec
	bankKeeper types.BankKeeper
}
func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, bankKeeper types.BankKeeper) Keeper {
	keeper := Keeper{
		storeKey:   key,
		cdc:        cdc,
		bankKeeper: bankKeeper,
	}
	return keeper
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
	return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
func (k *Keeper) List(ctx sdk.Context) ([]*ownership.Ownership, error) {
	var (
		ownerships []*ownership.Ownership
		iter       = ctx.KVStore(k.storeKey).Iterator(nil, nil)
	)
	defer iter.Close()
	for iter.Valid() {
		var o *ownership.Ownership
		if err := k.cdc.UnmarshalBinaryLengthPrefixed(iter.Value(), &o); err != nil {
			return nil, sdkerrors.Wrapf(sdkerrors.ErrJSONUnmarshal, err.Error())
		}
		ownerships = append(ownerships, o)
		iter.Next()
	}
	return ownerships, nil
}
func (k Keeper) Set(ctx sdk.Context, owner sdk.AccAddress, resourceHash hash.Hash, resource ownership.Ownership_Resource, resourceAddress sdk.AccAddress) (*ownership.Ownership, error) {
	store := ctx.KVStore(k.storeKey)
	own, err := k.get(store, resourceHash)
	if err != nil {
		return nil, err
	}
	if own != nil {
		return nil, sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "resource %s:%q already has an owner", resource, resourceHash)
	}
	own, err = ownership.New(owner.String(), resource, resourceHash, resourceAddress)
	if err != nil {
		return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, err.Error())
	}
	data, err := k.cdc.MarshalBinaryLengthPrefixed(own)
	if err != nil {
		return nil, sdkerrors.Wrapf(sdkerrors.ErrJSONMarshal, err.Error())
	}
	store.Set(own.Hash, data)
	ctx.EventManager().EmitEvent(
		sdk.NewEvent(
			types.EventType,
			sdk.NewAttribute(sdk.AttributeKeyAction, types.AttributeActionCreated),
			sdk.NewAttribute(types.AttributeKeyHash, own.Hash.String()),
			sdk.NewAttribute(types.AttributeKeyResourceHash, own.ResourceHash.String()),
			sdk.NewAttribute(types.AttributeKeyResourceType, own.Resource.String()),
			sdk.NewAttribute(types.AttributeKeyResourceAddress, own.ResourceAddress.String()),
		),
	)
	return own, nil
}