forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split key and path functions in separate files (cosmos#5670)
- Loading branch information
1 parent
6ceba47
commit 4efbc8a
Showing
8 changed files
with
185 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package host | ||
|
||
import "fmt" | ||
|
||
const ( | ||
KeyChannelEndPrefix = "channelEnds" | ||
KeyChannelPrefix = "channels" | ||
KeyChannelUpgradePrefix = "channelUpgrades" | ||
KeyUpgradePrefix = "upgrades" | ||
KeyUpgradeErrorPrefix = "upgradeError" | ||
KeyCounterpartyUpgrade = "counterpartyUpgrade" | ||
KeyChannelCapabilityPrefix = "capabilities" | ||
) | ||
|
||
// ICS04 | ||
// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-004-channel-and-packet-semantics#store-paths | ||
|
||
// ChannelPath defines the path under which channels are stored | ||
func ChannelPath(portID, channelID string) string { | ||
return fmt.Sprintf("%s/%s", KeyChannelEndPrefix, channelPath(portID, channelID)) | ||
} | ||
|
||
// ChannelCapabilityPath defines the path under which capability keys associated | ||
// with a channel are stored | ||
func ChannelCapabilityPath(portID, channelID string) string { | ||
return fmt.Sprintf("%s/%s", KeyChannelCapabilityPrefix, channelPath(portID, channelID)) | ||
} | ||
|
||
// ChannelUpgradeErrorPath defines the path under which the ErrorReceipt is stored in the case that a chain does not accept the proposed upgrade | ||
func ChannelUpgradeErrorPath(portID, channelID string) string { | ||
return fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyUpgradeErrorPrefix, channelPath(portID, channelID)) | ||
} | ||
|
||
// ChannelUpgradePath defines the path which stores the information related to an upgrade attempt | ||
func ChannelUpgradePath(portID, channelID string) string { | ||
return fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyUpgradePrefix, channelPath(portID, channelID)) | ||
} | ||
|
||
// ChannelCounterpartyUpgradePath defines the path under which the upgrade used on the counterparty channel is stored. | ||
func ChannelCounterpartyUpgradePath(portID, channelID string) string { | ||
return fmt.Sprintf("%s/%s/%s", KeyChannelUpgradePrefix, KeyCounterpartyUpgrade, channelPath(portID, channelID)) | ||
} | ||
|
||
func channelPath(portID, channelID string) string { | ||
return fmt.Sprintf("%s/%s/%s/%s", KeyPortPrefix, portID, KeyChannelPrefix, channelID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package host | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/ibc-go/v8/modules/core/exported" | ||
) | ||
|
||
// KeyClientStorePrefix defines the KVStore key prefix for IBC clients | ||
var KeyClientStorePrefix = []byte("clients") | ||
|
||
const ( | ||
KeyClientState = "clientState" | ||
KeyConsensusStatePrefix = "consensusStates" | ||
) | ||
|
||
// FullClientPath returns the full path of a specific client path in the format: | ||
// "clients/{clientID}/{path}" as a string. | ||
func FullClientPath(clientID string, path string) string { | ||
return fmt.Sprintf("%s/%s/%s", KeyClientStorePrefix, clientID, path) | ||
} | ||
|
||
// PrefixedClientStorePath returns a key path which can be used for prefixed | ||
// key store iteration. The prefix may be a clientType, clientID, or any | ||
// valid key prefix which may be concatenated with the client store constant. | ||
func PrefixedClientStorePath(prefix []byte) string { | ||
return fmt.Sprintf("%s/%s", KeyClientStorePrefix, prefix) | ||
} | ||
|
||
// ICS02 | ||
// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-002-client-semantics#path-space | ||
|
||
// FullClientStatePath takes a client identifier and returns a Path under which to store a | ||
// particular client state | ||
func FullClientStatePath(clientID string) string { | ||
return FullClientPath(clientID, KeyClientState) | ||
} | ||
|
||
// FullConsensusStatePath takes a client identifier and returns a Path under which to | ||
// store the consensus state of a client. | ||
func FullConsensusStatePath(clientID string, height exported.Height) string { | ||
return FullClientPath(clientID, ConsensusStatePath(height)) | ||
} | ||
|
||
// ConsensusStatePath returns the suffix store key for the consensus state at a | ||
// particular height stored in a client prefixed store. | ||
func ConsensusStatePath(height exported.Height) string { | ||
return fmt.Sprintf("%s/%s", KeyConsensusStatePrefix, height) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package host | ||
|
||
import "fmt" | ||
|
||
const KeyConnectionPrefix = "connections" | ||
|
||
// ICS03 | ||
// The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/blob/master/spec/core/ics-003-connection-semantics#store-paths | ||
|
||
// ClientConnectionsPath defines a reverse mapping from clients to a set of connections | ||
func ClientConnectionsPath(clientID string) string { | ||
return FullClientPath(clientID, KeyConnectionPrefix) | ||
} | ||
|
||
// ConnectionPath defines the path under which connection paths are stored | ||
func ConnectionPath(connectionID string) string { | ||
return fmt.Sprintf("%s/%s", KeyConnectionPrefix, connectionID) | ||
} |
Oops, something went wrong.