Skip to content

Commit

Permalink
Add member key and SetMember func
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Dusek committed Apr 18, 2024
1 parent 3d6881e commit e8fb9c4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions x/market/keeper/member.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/runtime"

"context"
"onex/x/market/types"
)

// GetParams get all parameters as types.Params
func (k Keeper) GetMember(
ctx context.Context,
denomA string,
denomB string,
) (member types.Member, found bool) {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
bz := store.Get(types.MemberKey(
denomA,
denomB,
))
if bz == nil {
return member, false
}

k.cdc.MustUnmarshal(bz, &member)
return member, true
}
8 changes: 8 additions & 0 deletions x/market/keeper/msg_server_create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func (k msgServer) CreatePool(goCtx context.Context, msg *types.MsgCreatePool) (
denom2 := coinPair.GetDenomByIndex(1)
pair := strings.Join([]string{denom1, denom2}, ",")

// Test if pool either exists and active or exists and inactive
// Inactive pool will be dry or have no drops
member1, _ := k.GetMember(ctx, denom2, denom1)

member2, _ := k.GetMember(ctx, denom1, denom2)

_ = member1
_ = member2
_ = pair
_ = ctx

Expand Down
24 changes: 24 additions & 0 deletions x/market/types/key_member.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package types

const (
// MemberKeyPrefix is the prefix to retrieve all Member
MemberKeyPrefix = "Member/value/"
)

// MemberKey returns the store key to retrieve a Member from the index fields
func MemberKey(
denomA string,
denomB string,
) []byte {
var key []byte

denomABytes := []byte(denomA)
key = append(key, denomABytes...)
key = append(key, []byte("/")...)

denomBBytes := []byte(denomB)
key = append(key, denomBBytes...)
key = append(key, []byte("/")...)

return key
}

0 comments on commit e8fb9c4

Please sign in to comment.