Skip to content

Commit

Permalink
updating keys to reflect naming changes
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Jun 13, 2022
1 parent 7af30a6 commit 49ce2f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
14 changes: 7 additions & 7 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (k Keeper) GetAllFeeEnabledChannels(ctx sdk.Context) []types.FeeEnabledChan
// GetPayeeAddress retrieves the fee payee address stored in state given the provided channel identifier and relayer address
func (k Keeper) GetPayeeAddress(ctx sdk.Context, relayerAddr, channelID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyPayeeAddress(relayerAddr, channelID)
key := types.KeyPayee(relayerAddr, channelID)

if !store.Has(key) {
return "", false
Expand All @@ -162,13 +162,13 @@ func (k Keeper) GetPayeeAddress(ctx sdk.Context, relayerAddr, channelID string)
// SetPayeeAddress stores the fee payee address in state keyed by the provided channel identifier and relayer address
func (k Keeper) SetPayeeAddress(ctx sdk.Context, relayerAddr, payeeAddr, channelID string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyPayeeAddress(relayerAddr, channelID), []byte(payeeAddr))
store.Set(types.KeyPayee(relayerAddr, channelID), []byte(payeeAddr))
}

// GetAllPayeeAddresses returns all registered payees
func (k Keeper) GetAllPayeeAddresses(ctx sdk.Context) []types.RegisteredPayee {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PayeeAddressKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PayeeKeyPrefix))
defer iterator.Close()

var registeredPayees []types.RegisteredPayee
Expand All @@ -194,13 +194,13 @@ func (k Keeper) GetAllPayeeAddresses(ctx sdk.Context) []types.RegisteredPayee {
// The receiving chain must store the mapping from: address -> counterpartyPayeeAddress for the given channel
func (k Keeper) SetCounterpartyPayeeAddress(ctx sdk.Context, address, counterpartyAddress, channelID string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.KeyCounterpartyRelayer(address, channelID), []byte(counterpartyAddress))
store.Set(types.KeyCounterpartyPayee(address, channelID), []byte(counterpartyAddress))
}

// GetCounterpartyPayeeAddress gets the counterparty payee address given a destination relayer address
func (k Keeper) GetCounterpartyPayeeAddress(ctx sdk.Context, address, channelID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyCounterpartyRelayer(address, channelID)
key := types.KeyCounterpartyPayee(address, channelID)

if !store.Has(key) {
return "", false
Expand All @@ -213,12 +213,12 @@ func (k Keeper) GetCounterpartyPayeeAddress(ctx sdk.Context, address, channelID
// GetAllRelayerAddresses returns all registered relayer addresses
func (k Keeper) GetAllRelayerAddresses(ctx sdk.Context) []types.RegisteredRelayerAddress {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.CounterpartyRelayerAddressKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte(types.CounterpartyPayeeKeyPrefix))
defer iterator.Close()

var registeredAddrArr []types.RegisteredRelayerAddress
for ; iterator.Valid(); iterator.Next() {
address, channelID, err := types.ParseKeyCounterpartyRelayer(string(iterator.Key()))
address, channelID, err := types.ParseKeyCounterpartyPayee(string(iterator.Key()))
if err != nil {
panic(err)
}
Expand Down
24 changes: 12 additions & 12 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const (
// FeeEnabledPrefix is the key prefix for storing fee enabled flag
FeeEnabledKeyPrefix = "feeEnabled"

// PayeeAddressKeyPrefix is the key prefix for the fee payee address stored in state
PayeeAddressKeyPrefix = "payeeAddress"
// PayeeKeyPrefix is the key prefix for the fee payee address stored in state
PayeeKeyPrefix = "payee"

// CounterpartyRelayerAddressKeyPrefix is the key prefix for relayer address mapping
CounterpartyRelayerAddressKeyPrefix = "relayerAddress"
// CounterpartyPayeeKeyPrefix is the key prefix for the counterparty payee address mapping
CounterpartyPayeeKeyPrefix = "counterpartyPayee"

// FeesInEscrowPrefix is the key prefix for fee in escrow mapping
FeesInEscrowPrefix = "feesInEscrow"
Expand Down Expand Up @@ -73,9 +73,9 @@ func ParseKeyFeeEnabled(key string) (portID, channelID string, err error) {
return portID, channelID, nil
}

// KeyPayeeAddress returns the key for relayer address -> payee address mapping
func KeyPayeeAddress(relayerAddr, channelID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", PayeeAddressKeyPrefix, relayerAddr, channelID))
// KeyPayee returns the key for relayer address -> payee address mapping
func KeyPayee(relayerAddr, channelID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", PayeeKeyPrefix, relayerAddr, channelID))
}

// ParseKeyPayeeAddress returns the registered relayer addresss and channelID used to the store the fee payee address
Expand All @@ -90,13 +90,13 @@ func ParseKeyPayeeAddress(key string) (relayerAddr, channelID string, err error)
return keySplit[1], keySplit[2], nil
}

// KeyCounterpartyRelayer returns the key for relayer address -> counterparty address mapping
func KeyCounterpartyRelayer(address, channelID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", CounterpartyRelayerAddressKeyPrefix, address, channelID))
// KeyCounterpartyPayee returns the key for relayer address -> counterparty payee address mapping
func KeyCounterpartyPayee(address, channelID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", CounterpartyPayeeKeyPrefix, address, channelID))
}

// ParseKeyCounterpartyRelayer returns the registered relayer address and channelID used to store the counterpartyrelayer address
func ParseKeyCounterpartyRelayer(key string) (address string, channelID string, error error) {
// ParseKeyCounterpartyPayee returns the registered relayer address and channelID used to store the counterparty payee address
func ParseKeyCounterpartyPayee(key string) (address string, channelID string, error error) {
keySplit := strings.Split(key, "/")
if len(keySplit) != 3 {
return "", "", sdkerrors.Wrapf(
Expand Down
22 changes: 11 additions & 11 deletions modules/apps/29-fee/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (

var validPacketID = channeltypes.NewPacketId(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1)

func TestKeyPayeeAddress(t *testing.T) {
key := types.KeyPayeeAddress("relayer-address", ibctesting.FirstChannelID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.PayeeAddressKeyPrefix, "relayer-address", ibctesting.FirstChannelID))
func TestKeyPayee(t *testing.T) {
key := types.KeyPayee("relayer-address", ibctesting.FirstChannelID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.PayeeKeyPrefix, "relayer-address", ibctesting.FirstChannelID))
}

func TestParseKeyPayeeAddress(t *testing.T) {
func TestParseKeyPayee(t *testing.T) {
testCases := []struct {
name string
key string
expPass bool
}{
{
"success",
string(types.KeyPayeeAddress("relayer-address", ibctesting.FirstChannelID)),
string(types.KeyPayee("relayer-address", ibctesting.FirstChannelID)),
true,
},
{
Expand All @@ -49,14 +49,14 @@ func TestParseKeyPayeeAddress(t *testing.T) {
}
}

func TestKeyCounterpartyRelayer(t *testing.T) {
func TestKeyCounterpartyPayee(t *testing.T) {
var (
relayerAddress = "relayer_address"
channelID = "channel-0"
)

key := types.KeyCounterpartyRelayer(relayerAddress, channelID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.CounterpartyRelayerAddressKeyPrefix, relayerAddress, channelID))
key := types.KeyCounterpartyPayee(relayerAddress, channelID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.CounterpartyPayeeKeyPrefix, relayerAddress, channelID))
}

func TestKeyFeesInEscrow(t *testing.T) {
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestParseKeyForwardRelayerAddress(t *testing.T) {
}
}

func TestParseKeyCounterpartyRelayer(t *testing.T) {
func TestParseKeyCounterpartyPayee(t *testing.T) {
relayerAddress := "relayer_address"

testCases := []struct {
Expand All @@ -182,7 +182,7 @@ func TestParseKeyCounterpartyRelayer(t *testing.T) {
}{
{
"success",
string(types.KeyCounterpartyRelayer(relayerAddress, ibctesting.FirstChannelID)),
string(types.KeyCounterpartyPayee(relayerAddress, ibctesting.FirstChannelID)),
true,
},
{
Expand All @@ -193,7 +193,7 @@ func TestParseKeyCounterpartyRelayer(t *testing.T) {
}

for _, tc := range testCases {
address, channelID, err := types.ParseKeyCounterpartyRelayer(tc.key)
address, channelID, err := types.ParseKeyCounterpartyPayee(tc.key)

if tc.expPass {
require.NoError(t, err)
Expand Down

0 comments on commit 49ce2f6

Please sign in to comment.