-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding GetChannelsWithPortPrefix function to 04-channel #2304
Changes from 2 commits
74dbd34
ebbcd36
b5e1e9f
b8bbe7d
9001e64
691748b
137439f
2ffd5e4
fc0c1a4
b44777e
5bd25fd
019afc6
1b663db
2707071
78697b5
e3e4fc5
afe7941
f404c27
ba22f69
d287003
0e61f33
d7ee861
b085b89
bd9ded4
4f695dc
c8364f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
package keeper | ||||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"strconv" | ||||||
"strings" | ||||||
|
||||||
|
@@ -384,6 +385,24 @@ func (k Keeper) IterateChannels(ctx sdk.Context, cb func(types.IdentifiedChannel | |||||
} | ||||||
} | ||||||
|
||||||
// GetChannelsWithPortPrefix returns all channels with the specified port prefix. | ||||||
func (k Keeper) GetChannelsWithPortPrefix(ctx sdk.Context, portPrefix string) []types.IdentifiedChannel { | ||||||
colin-axner marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider naming this function to align with Maybe I don't feel particularly strongly but just a thought. cc. @crodriguezvega @colin-axner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. I have no preference |
||||||
store := ctx.KVStore(k.storeKey) | ||||||
iterator := sdk.KVStorePrefixIterator(store, filteredPortPrefix(portPrefix)) | ||||||
defer iterator.Close() | ||||||
|
||||||
var filteredChannels []types.IdentifiedChannel | ||||||
for ; iterator.Valid(); iterator.Next() { | ||||||
var channel types.Channel | ||||||
k.cdc.MustUnmarshal(iterator.Value(), &channel) | ||||||
|
||||||
portID, channelID := host.MustParseChannelPath(string(iterator.Key())) | ||||||
identifiedChannel := types.NewIdentifiedChannel(portID, channelID, channel) | ||||||
filteredChannels = append(filteredChannels, identifiedChannel) | ||||||
} | ||||||
return filteredChannels | ||||||
} | ||||||
|
||||||
// GetAllChannels returns all stored Channel objects. | ||||||
func (k Keeper) GetAllChannels(ctx sdk.Context) (channels []types.IdentifiedChannel) { | ||||||
k.IterateChannels(ctx, func(channel types.IdentifiedChannel) bool { | ||||||
|
@@ -469,3 +488,8 @@ func (k Keeper) iterateHashes(_ sdk.Context, iterator db.Iterator, cb func(portI | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
// filteredPortPrefix returns the prefix key for the given port prefix. | ||||||
func filteredPortPrefix(portPrefix string) []byte { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to place this function in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good suggestion, done! |
||||||
return []byte(fmt.Sprintf("%s/ports/%s", host.KeyChannelEndPrefix, portPrefix)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call |
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how this ended up as
commitmenttypes
I see the import previously would've been incorrect also.It should be
controllertypes.SubModuleName
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I was wondering about that actually, I changed the import to be inline with other imports in the file. I can update this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the dangers of
types
as the import alias.