github.com/okex/exchain@v1.8.0/libs/ibc-go/modules/core/24-host/keys.go (about)

     1  package host
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/okex/exchain/libs/ibc-go/modules/core/exported"
     7  )
     8  
     9  const (
    10  	// ModuleName is the name of the IBC module
    11  	ModuleName = "ibc"
    12  
    13  	// StoreKey is the string store representation
    14  	StoreKey string = ModuleName
    15  
    16  	// QuerierRoute is the querier route for the IBC module
    17  	QuerierRoute string = ModuleName
    18  
    19  	// RouterKey is the msg router key for the IBC module
    20  	RouterKey string = ModuleName
    21  )
    22  
    23  // KVStore key prefixes for IBC
    24  var (
    25  	KeyClientStorePrefix = []byte("clients")
    26  )
    27  
    28  // KVStore key prefixes for IBC
    29  const (
    30  	KeyClientState             = "clientState"
    31  	KeyConsensusStatePrefix    = "consensusStates"
    32  	KeyConnectionPrefix        = "connections"
    33  	KeyChannelEndPrefix        = "channelEnds"
    34  	KeyChannelPrefix           = "channels"
    35  	KeyPortPrefix              = "ports"
    36  	KeySequencePrefix          = "sequences"
    37  	KeyChannelCapabilityPrefix = "capabilities"
    38  	KeyNextSeqSendPrefix       = "nextSequenceSend"
    39  	KeyNextSeqRecvPrefix       = "nextSequenceRecv"
    40  	KeyNextSeqAckPrefix        = "nextSequenceAck"
    41  	KeyPacketCommitmentPrefix  = "commitments"
    42  	KeyPacketAckPrefix         = "acks"
    43  	KeyPacketReceiptPrefix     = "receipts"
    44  )
    45  
    46  // FullClientPath returns the full path of a specific client path in the format:
    47  // "clients/{clientID}/{path}" as a string.
    48  func FullClientPath(clientID string, path string) string {
    49  	return fmt.Sprintf("%s/%s/%s", KeyClientStorePrefix, clientID, path)
    50  }
    51  
    52  // FullClientKey returns the full path of specific client path in the format:
    53  // "clients/{clientID}/{path}" as a byte array.
    54  func FullClientKey(clientID string, path []byte) []byte {
    55  	return []byte(FullClientPath(clientID, string(path)))
    56  }
    57  
    58  // ICS02
    59  // 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
    60  
    61  // FullClientStatePath takes a client identifier and returns a Path under which to store a
    62  // particular client state
    63  func FullClientStatePath(clientID string) string {
    64  	return FullClientPath(clientID, KeyClientState)
    65  }
    66  
    67  // FullClientStateKey takes a client identifier and returns a Key under which to store a
    68  // particular client state.
    69  func FullClientStateKey(clientID string) []byte {
    70  	return FullClientKey(clientID, []byte(KeyClientState))
    71  }
    72  
    73  // ClientStateKey returns a store key under which a particular client state is stored
    74  // in a client prefixed store
    75  func ClientStateKey() []byte {
    76  	return []byte(KeyClientState)
    77  }
    78  
    79  // FullConsensusStatePath takes a client identifier and returns a Path under which to
    80  // store the consensus state of a client.
    81  func FullConsensusStatePath(clientID string, height exported.Height) string {
    82  	return FullClientPath(clientID, ConsensusStatePath(height))
    83  }
    84  
    85  // FullConsensusStateKey returns the store key for the consensus state of a particular
    86  // client.
    87  func FullConsensusStateKey(clientID string, height exported.Height) []byte {
    88  	return []byte(FullConsensusStatePath(clientID, height))
    89  }
    90  
    91  // ConsensusStatePath returns the suffix store key for the consensus state at a
    92  // particular height stored in a client prefixed store.
    93  func ConsensusStatePath(height exported.Height) string {
    94  	return fmt.Sprintf("%s/%s", KeyConsensusStatePrefix, height)
    95  }
    96  
    97  // ConsensusStateKey returns the store key for a the consensus state of a particular
    98  // client stored in a client prefixed store.
    99  func ConsensusStateKey(height exported.Height) []byte {
   100  	return []byte(ConsensusStatePath(height))
   101  }
   102  
   103  // ICS03
   104  // 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
   105  
   106  // ClientConnectionsPath defines a reverse mapping from clients to a set of connections
   107  func ClientConnectionsPath(clientID string) string {
   108  	return FullClientPath(clientID, KeyConnectionPrefix)
   109  }
   110  
   111  // ClientConnectionsKey returns the store key for the connections of a given client
   112  func ClientConnectionsKey(clientID string) []byte {
   113  	return []byte(ClientConnectionsPath(clientID))
   114  }
   115  
   116  // ConnectionPath defines the path under which connection paths are stored
   117  func ConnectionPath(connectionID string) string {
   118  	return fmt.Sprintf("%s/%s", KeyConnectionPrefix, connectionID)
   119  }
   120  
   121  // ConnectionKey returns the store key for a particular connection
   122  func ConnectionKey(connectionID string) []byte {
   123  	return []byte(ConnectionPath(connectionID))
   124  }
   125  
   126  // ICS04
   127  // 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
   128  
   129  // ChannelPath defines the path under which channels are stored
   130  func ChannelPath(portID, channelID string) string {
   131  	return fmt.Sprintf("%s/%s", KeyChannelEndPrefix, channelPath(portID, channelID))
   132  }
   133  
   134  // ChannelKey returns the store key for a particular channel
   135  func ChannelKey(portID, channelID string) []byte {
   136  	return []byte(ChannelPath(portID, channelID))
   137  }
   138  
   139  // ChannelCapabilityPath defines the path under which capability keys associated
   140  // with a channel are stored
   141  func ChannelCapabilityPath(portID, channelID string) string {
   142  	return fmt.Sprintf("%s/%s", KeyChannelCapabilityPrefix, channelPath(portID, channelID))
   143  }
   144  
   145  // NextSequenceSendPath defines the next send sequence counter store path
   146  func NextSequenceSendPath(portID, channelID string) string {
   147  	return fmt.Sprintf("%s/%s", KeyNextSeqSendPrefix, channelPath(portID, channelID))
   148  }
   149  
   150  // NextSequenceSendKey returns the store key for the send sequence of a particular
   151  // channel binded to a specific port.
   152  func NextSequenceSendKey(portID, channelID string) []byte {
   153  	return []byte(NextSequenceSendPath(portID, channelID))
   154  }
   155  
   156  // NextSequenceRecvPath defines the next receive sequence counter store path.
   157  func NextSequenceRecvPath(portID, channelID string) string {
   158  	return fmt.Sprintf("%s/%s", KeyNextSeqRecvPrefix, channelPath(portID, channelID))
   159  }
   160  
   161  // NextSequenceRecvKey returns the store key for the receive sequence of a particular
   162  // channel binded to a specific port
   163  func NextSequenceRecvKey(portID, channelID string) []byte {
   164  	return []byte(NextSequenceRecvPath(portID, channelID))
   165  }
   166  
   167  // NextSequenceAckPath defines the next acknowledgement sequence counter store path
   168  func NextSequenceAckPath(portID, channelID string) string {
   169  	return fmt.Sprintf("%s/%s", KeyNextSeqAckPrefix, channelPath(portID, channelID))
   170  }
   171  
   172  // NextSequenceAckKey returns the store key for the acknowledgement sequence of
   173  // a particular channel binded to a specific port.
   174  func NextSequenceAckKey(portID, channelID string) []byte {
   175  	return []byte(NextSequenceAckPath(portID, channelID))
   176  }
   177  
   178  // PacketCommitmentPath defines the commitments to packet data fields store path
   179  func PacketCommitmentPath(portID, channelID string, sequence uint64) string {
   180  	return fmt.Sprintf("%s/%d", PacketCommitmentPrefixPath(portID, channelID), sequence)
   181  }
   182  
   183  // PacketCommitmentKey returns the store key of under which a packet commitment
   184  // is stored
   185  func PacketCommitmentKey(portID, channelID string, sequence uint64) []byte {
   186  	return []byte(PacketCommitmentPath(portID, channelID, sequence))
   187  }
   188  
   189  // PacketCommitmentPrefixPath defines the prefix for commitments to packet data fields store path.
   190  func PacketCommitmentPrefixPath(portID, channelID string) string {
   191  	return fmt.Sprintf("%s/%s/%s", KeyPacketCommitmentPrefix, channelPath(portID, channelID), KeySequencePrefix)
   192  }
   193  
   194  // PacketAcknowledgementPath defines the packet acknowledgement store path
   195  func PacketAcknowledgementPath(portID, channelID string, sequence uint64) string {
   196  	return fmt.Sprintf("%s/%d", PacketAcknowledgementPrefixPath(portID, channelID), sequence)
   197  }
   198  
   199  // PacketAcknowledgementKey returns the store key of under which a packet
   200  // acknowledgement is stored
   201  func PacketAcknowledgementKey(portID, channelID string, sequence uint64) []byte {
   202  	return []byte(PacketAcknowledgementPath(portID, channelID, sequence))
   203  }
   204  
   205  // PacketAcknowledgementPrefixPath defines the prefix for commitments to packet data fields store path.
   206  func PacketAcknowledgementPrefixPath(portID, channelID string) string {
   207  	return fmt.Sprintf("%s/%s/%s", KeyPacketAckPrefix, channelPath(portID, channelID), KeySequencePrefix)
   208  }
   209  
   210  // PacketReceiptPath defines the packet receipt store path
   211  func PacketReceiptPath(portID, channelID string, sequence uint64) string {
   212  	return fmt.Sprintf("%s/%s/%s", KeyPacketReceiptPrefix, channelPath(portID, channelID), sequencePath(sequence))
   213  }
   214  
   215  // PacketReceiptKey returns the store key of under which a packet
   216  // receipt is stored
   217  func PacketReceiptKey(portID, channelID string, sequence uint64) []byte {
   218  	return []byte(PacketReceiptPath(portID, channelID, sequence))
   219  }
   220  
   221  func channelPath(portID, channelID string) string {
   222  	return fmt.Sprintf("%s/%s/%s/%s", KeyPortPrefix, portID, KeyChannelPrefix, channelID)
   223  }
   224  
   225  func sequencePath(sequence uint64) string {
   226  	return fmt.Sprintf("%s/%d", KeySequencePrefix, sequence)
   227  }
   228  
   229  // ICS05
   230  // The following paths are the keys to the store as defined in https://github.com/cosmos/ibc/tree/master/spec/core/ics-005-port-allocation#store-paths
   231  
   232  // PortPath defines the path under which ports paths are stored on the capability module
   233  func PortPath(portID string) string {
   234  	return fmt.Sprintf("%s/%s", KeyPortPrefix, portID)
   235  }