-
Notifications
You must be signed in to change notification settings - Fork 1
/
commitment.go
183 lines (169 loc) · 5.54 KB
/
commitment.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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/modules/core/24-host"
"github.com/cosmos/ibc-go/modules/core/exported"
)
func (k Keeper) GetProxyClientState(
ctx sdk.Context,
upstreamPrefix exported.Prefix,
counterpartyClientIdentifier string, // clientID corresponding to downstream on upstream
upstreamClientID string, // client id corresponding to upstream on proxy
) (exported.ClientState, bool) {
store := k.ProxyClientStore(ctx, upstreamPrefix, upstreamClientID, counterpartyClientIdentifier)
bz := store.Get(host.ClientStateKey())
if len(bz) == 0 {
return nil, false
}
return clienttypes.MustUnmarshalClientState(k.cdc, bz), true
}
func (k Keeper) GetProxyClientConsensusState(
ctx sdk.Context,
upstreamPrefix exported.Prefix,
counterpartyClientIdentifier string,
upstreamClientID string,
consensusHeight exported.Height,
) (exported.ConsensusState, bool) {
store := k.ProxyClientStore(ctx, upstreamPrefix, upstreamClientID, counterpartyClientIdentifier)
bz := store.Get(host.ConsensusStateKey(consensusHeight))
if len(bz) == 0 {
return nil, false
}
return clienttypes.MustUnmarshalConsensusState(k.cdc, bz), true
}
func (k Keeper) GetProxyConnection(
ctx sdk.Context,
upstreamPrefix exported.Prefix,
upstreamClientID string,
connectionID string,
) (connectiontypes.ConnectionEnd, bool) {
var connection connectiontypes.ConnectionEnd
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
bz := store.Get(host.ConnectionKey(connectionID))
if len(bz) == 0 {
return connection, false
}
k.cdc.MustUnmarshal(bz, &connection)
return connection, true
}
func (k Keeper) GetProxyChannel(
ctx sdk.Context,
upstreamPrefix exported.Prefix,
upstreamClientID string,
portID,
channelID string,
) (channeltypes.Channel, bool) {
var channel channeltypes.Channel
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
bz := store.Get(host.ChannelKey(portID, channelID))
if len(bz) == 0 {
return channel, false
}
k.cdc.MustUnmarshal(bz, &channel)
return channel, true
}
func (k Keeper) SetProxyClientState(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
counterpartyClientIdentifier string, // clientID corresponding to downstream on upstream
upstreamClientID string, // client id corresponding to upstream on proxy
clientState exported.ClientState,
) error {
store := k.ProxyClientStore(ctx, upstreamPrefix, upstreamClientID, counterpartyClientIdentifier)
bz := clienttypes.MustMarshalClientState(k.cdc, clientState)
store.Set(host.ClientStateKey(), bz)
return nil
}
func (k Keeper) SetProxyClientConsensusState(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
counterpartyClientIdentifier string,
upstreamClientID string,
consensusHeight exported.Height,
consensusState exported.ConsensusState,
) error {
store := k.ProxyClientStore(ctx, upstreamPrefix, upstreamClientID, counterpartyClientIdentifier)
bz := clienttypes.MustMarshalConsensusState(k.cdc, consensusState)
store.Set(host.ConsensusStateKey(consensusHeight), bz)
return nil
}
func (k Keeper) SetProxyConnection(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
upstreamClientID string,
connectionID string,
connectionEnd connectiontypes.ConnectionEnd,
) error {
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
bz := k.cdc.MustMarshal(&connectionEnd)
store.Set(host.ConnectionKey(connectionID), bz)
return nil
}
func (k Keeper) SetProxyChannel(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
upstreamClientID string,
portID,
channelID string,
channelEnd exported.ChannelI,
) error {
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
channel := channelEnd.(channeltypes.Channel)
bz := k.cdc.MustMarshal(&channel)
store.Set(host.ChannelKey(portID, channelID), bz)
return nil
}
func (k Keeper) SetProxyPacketCommitment(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
upstreamClientID string,
portID,
channelID string,
sequence uint64,
commitmentBytes []byte,
) error {
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
store.Set(host.PacketCommitmentKey(portID, channelID, sequence), commitmentBytes)
return nil
}
func (k Keeper) SetProxyPacketAcknowledgement(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
upstreamClientID string,
portID,
channelID string,
sequence uint64,
acknowledgement []byte,
) error {
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
store.Set(host.PacketAcknowledgementKey(portID, channelID, sequence), channeltypes.CommitAcknowledgement(acknowledgement))
return nil
}
func (k Keeper) SetProxyPacketReceiptAbsence(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
upstreamClientID string,
portID,
channelID string,
sequence uint64,
) error {
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
store.Set(host.PacketReceiptKey(portID, channelID, sequence), []byte{byte(1)})
return nil
}
func (k Keeper) SetProxyNextSequenceRecv(
ctx sdk.Context,
upstreamPrefix exported.Prefix, // upstream's prefix
upstreamClientID string,
portID,
channelID string,
nextSequenceRecv uint64,
) error {
store := k.ProxyStore(ctx, upstreamPrefix, upstreamClientID)
bz := sdk.Uint64ToBigEndian(nextSequenceRecv)
store.Set(host.NextSequenceRecvKey(portID, channelID), bz)
return nil
}