Skip to content

Commit

Permalink
Add in ability to query all drops
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed Jun 22, 2024
1 parent e3a9ef7 commit 7dbbbc4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion x/market/keeper/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func (k Keeper) SetDrop(ctx sdk.Context, drop types.Drop) {
), a)
}

// SetDrops set a specific drops in the store from its index
func (k Keeper) SetDrops(ctx sdk.Context, drops types.Drops, owner string, pair string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DropsKeyPrefix))
a := k.cdc.MustMarshal(&drops)
store.Set(types.DropsKey(
owner,
pair,
), a)
}

// GetDrop returns a drop from its index
func (k Keeper) GetDrop(
ctx sdk.Context,
Expand All @@ -41,7 +51,7 @@ func (k Keeper) GetDrop(
return val, true
}

// GetDrop returns a drop from its index
// GetDropPairs returns all pairs that an address owns drops
func (k Keeper) GetDropPairs(
ctx sdk.Context,
address string,
Expand Down Expand Up @@ -268,6 +278,22 @@ func (k Keeper) GetAllDrop(ctx sdk.Context) (list []types.Drop) {
return
}

// GetAllDrops returns all drops
func (k Keeper) GetAllDrops(ctx sdk.Context) (list []types.Drops) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.DropsKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.Drops
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}

// GetOwnerDrops returns drops from a single owner
func (k Keeper) GetPairs(
ctx sdk.Context,
Expand Down

0 comments on commit 7dbbbc4

Please sign in to comment.