From e8fb9c4c6bccca7562abff44120fe340e996556e Mon Sep 17 00:00:00 2001 From: Charles Dusek Date: Wed, 17 Apr 2024 21:51:44 -0500 Subject: [PATCH] Add member key and SetMember func --- x/market/keeper/member.go | 27 +++++++++++++++++++++++ x/market/keeper/msg_server_create_pool.go | 8 +++++++ x/market/types/key_member.go | 24 ++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 x/market/keeper/member.go create mode 100644 x/market/types/key_member.go diff --git a/x/market/keeper/member.go b/x/market/keeper/member.go new file mode 100644 index 0000000..315641f --- /dev/null +++ b/x/market/keeper/member.go @@ -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 +} diff --git a/x/market/keeper/msg_server_create_pool.go b/x/market/keeper/msg_server_create_pool.go index 7f148e7..77e6ba9 100644 --- a/x/market/keeper/msg_server_create_pool.go +++ b/x/market/keeper/msg_server_create_pool.go @@ -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 diff --git a/x/market/types/key_member.go b/x/market/types/key_member.go new file mode 100644 index 0000000..cd41a6f --- /dev/null +++ b/x/market/types/key_member.go @@ -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 +}