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