Skip to content
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

Adds Generic Middleware helper functions #383

Merged
merged 7 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions modules/core/04-channel/types/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package types

import "strings"

// SplitChannelVersion splits the channel version string
// into the outermost middleware version and the underlying app version.
// It will use the default delimiter `:` for middleware versions.
// In case there's no delimeter, this function returns an empty string for the middleware version (first return argument),
// and the full input as the second underlying app version.
func SplitChannelVersion(version string) (middlewareVersion, appVersion string) {
// only split out the first middleware version
splitVersions := strings.Split(version, ":")
if len(splitVersions) == 1 {
return "", version
}
middlewareVersion = splitVersions[0]
appVersion = strings.Join(splitVersions[1:], ":")
return
}
43 changes: 43 additions & 0 deletions modules/core/04-channel/types/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/modules/core/04-channel/types"
)

func TestSplitVersions(t *testing.T) {
testCases := []struct {
name string
version string
mwVersion string
appVersion string
}{
{
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
"single wrapped middleware",
"fee29-1:ics20-1",
"fee29-1",
"ics20-1",
},
{
"multiple wrapped middleware",
"fee29-1:whitelist:ics20-1",
"fee29-1",
"whitelist:ics20-1",
},
{
"no middleware",
"ics20-1",
"",
"ics20-1",
},
}

for _, tc := range testCases {
mwVersion, appVersion := types.SplitChannelVersion(tc.version)
require.Equal(t, tc.mwVersion, mwVersion, "middleware version is unexpected for case: %s", tc.name)
require.Equal(t, tc.appVersion, appVersion, "app version is unexpected for case: %s", tc.name)
}
}
10 changes: 10 additions & 0 deletions modules/core/24-host/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
KeyPortPrefix = "ports"
KeySequencePrefix = "sequences"
KeyChannelCapabilityPrefix = "capabilities"
KeyAppCapabilityPrefix = "appCapabilities"
AdityaSripal marked this conversation as resolved.
Show resolved Hide resolved
KeyNextSeqSendPrefix = "nextSequenceSend"
KeyNextSeqRecvPrefix = "nextSequenceRecv"
KeyNextSeqAckPrefix = "nextSequenceAck"
Expand Down Expand Up @@ -142,6 +143,15 @@ func ChannelCapabilityPath(portID, channelID string) string {
return fmt.Sprintf("%s/%s", KeyChannelCapabilityPrefix, channelPath(portID, channelID))
}

// AppCapabilityPath defines the path under which application capabilities can be issued by
// an ICS30 middleware wrapping an ICS26 application.
// Note the app capability path is only the name the middleware uses to reference a capability it issues
// to the underlying app. The underlying app will use the channel capability path to claim this capability
// from middleware just as the original capability issued by IBC is claimed by middleware using channel capability path.
func AppCapabilityPath(portID, channelID string) string {
return fmt.Sprintf("%s/%s", KeyAppCapabilityPrefix, channelPath(portID, channelID))
}

// NextSequenceSendPath defines the next send sequence counter store path
func NextSequenceSendPath(portID, channelID string) string {
return fmt.Sprintf("%s/%s", KeyNextSeqSendPrefix, channelPath(portID, channelID))
Expand Down