Skip to content

Commit

Permalink
update GetAllOwnersWithPagination
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Aug 14, 2024
1 parent 559cdb6 commit 4dff16a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions x/nft/keeper/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,25 @@ func (k Keeper) GetAllNFTsByOwnerWithPagination(ctx sdk.Context, ownerAddress st
// GetAllOwnersWithPagination returns all nft holders address with pagination
func (k Keeper) GetAllOwnersWithPagination(ctx sdk.Context, pagination *query.PageRequest) ([]string, *query.PageResponse, error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NFTByOwnerKeyPrefix))
var owners []string

uOwner := make(map[string]struct{})
pageRes, err := query.Paginate(store, pagination, func(key []byte, value []byte) error {
var owner types.Owner

k.cdc.MustUnmarshal(value, &owner)
owners = append(owners, owner.Address)
uOwner[owner.Address] = struct{}{}

return nil
})

if err != nil {
return nil, nil, status.Error(codes.Internal, err.Error())
}

var owners []string
for owner := range uOwner {
owners = append(owners, owner)
}

return owners, pageRes, nil

}

0 comments on commit 4dff16a

Please sign in to comment.