github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/keeper/facaded.go (about) 1 package keeper 2 3 import ( 4 "context" 5 6 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/common" 7 8 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 9 clienttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types" 10 connectiontypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/types" 11 channeltyeps "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 12 ) 13 14 var _ IBCServerKeeper = (*FacadedKeeper)(nil) 15 16 type Checkable interface { 17 GetIbcEnabled(ctx sdk.Context) bool 18 } 19 type IBCServerKeeper interface { 20 channeltyeps.QueryServer 21 channeltyeps.MsgServer 22 clienttypes.MsgServer 23 connectiontypes.MsgServer 24 25 Checkable 26 27 GetPacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) (string, bool) 28 GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte 29 } 30 31 type FacadedKeeper struct { 32 *common.SelectorStrategy 33 V2Keeper *Keeper 34 } 35 36 func NewFacadedKeeper(v2Keeper *Keeper) *FacadedKeeper { 37 ret := &FacadedKeeper{} 38 ret.V2Keeper = v2Keeper 39 40 ret.SelectorStrategy = common.NewSelectorStrategy(v2Keeper) 41 42 return ret 43 } 44 45 func (f *FacadedKeeper) RegisterKeeper(factories ...common.SelectorFactory) { 46 f.SelectorStrategy.RegisterSelectors(factories...) 47 f.SelectorStrategy.Seal() 48 } 49 50 func (f *FacadedKeeper) GetPacketCommitment(ctx sdk.Context, portID, channelID string, sequence uint64) []byte { 51 k := f.doGetByCtx(ctx) 52 return k.GetPacketCommitment(ctx, portID, channelID, sequence) 53 } 54 55 func (f *FacadedKeeper) GetPacketReceipt(ctx sdk.Context, portID, channelID string, sequence uint64) (string, bool) { 56 k := f.doGetByCtx(ctx) 57 return k.GetPacketReceipt(ctx, portID, channelID, sequence) 58 } 59 60 func (f *FacadedKeeper) Channel(goCtx context.Context, request *channeltyeps.QueryChannelRequest) (*channeltyeps.QueryChannelResponse, error) { 61 k := f.getHeightKeeper(goCtx) 62 return k.Channel(goCtx, request) 63 } 64 65 func (f *FacadedKeeper) Channels(goCtx context.Context, request *channeltyeps.QueryChannelsRequest) (*channeltyeps.QueryChannelsResponse, error) { 66 k := f.getHeightKeeper(goCtx) 67 return k.Channels(goCtx, request) 68 } 69 70 func (f *FacadedKeeper) ConnectionChannels(goCtx context.Context, request *channeltyeps.QueryConnectionChannelsRequest) (*channeltyeps.QueryConnectionChannelsResponse, error) { 71 k := f.getHeightKeeper(goCtx) 72 return k.ConnectionChannels(goCtx, request) 73 } 74 75 func (f *FacadedKeeper) ChannelClientState(goCtx context.Context, request *channeltyeps.QueryChannelClientStateRequest) (*channeltyeps.QueryChannelClientStateResponse, error) { 76 k := f.getHeightKeeper(goCtx) 77 return k.ChannelClientState(goCtx, request) 78 } 79 80 func (f *FacadedKeeper) ChannelConsensusState(goCtx context.Context, request *channeltyeps.QueryChannelConsensusStateRequest) (*channeltyeps.QueryChannelConsensusStateResponse, error) { 81 k := f.getHeightKeeper(goCtx) 82 return k.ChannelConsensusState(goCtx, request) 83 } 84 85 func (f *FacadedKeeper) PacketCommitment(goCtx context.Context, request *channeltyeps.QueryPacketCommitmentRequest) (*channeltyeps.QueryPacketCommitmentResponse, error) { 86 k := f.getHeightKeeper(goCtx) 87 return k.PacketCommitment(goCtx, request) 88 } 89 90 func (f *FacadedKeeper) PacketCommitments(goCtx context.Context, request *channeltyeps.QueryPacketCommitmentsRequest) (*channeltyeps.QueryPacketCommitmentsResponse, error) { 91 k := f.getHeightKeeper(goCtx) 92 return k.PacketCommitments(goCtx, request) 93 } 94 95 func (f *FacadedKeeper) PacketReceipt(goCtx context.Context, request *channeltyeps.QueryPacketReceiptRequest) (*channeltyeps.QueryPacketReceiptResponse, error) { 96 k := f.getHeightKeeper(goCtx) 97 return k.PacketReceipt(goCtx, request) 98 } 99 100 func (f *FacadedKeeper) PacketAcknowledgement(goCtx context.Context, request *channeltyeps.QueryPacketAcknowledgementRequest) (*channeltyeps.QueryPacketAcknowledgementResponse, error) { 101 k := f.getHeightKeeper(goCtx) 102 return k.PacketAcknowledgement(goCtx, request) 103 } 104 105 func (f *FacadedKeeper) PacketAcknowledgements(goCtx context.Context, request *channeltyeps.QueryPacketAcknowledgementsRequest) (*channeltyeps.QueryPacketAcknowledgementsResponse, error) { 106 k := f.getHeightKeeper(goCtx) 107 return k.PacketAcknowledgements(goCtx, request) 108 } 109 110 func (f *FacadedKeeper) UnreceivedPackets(goCtx context.Context, request *channeltyeps.QueryUnreceivedPacketsRequest) (*channeltyeps.QueryUnreceivedPacketsResponse, error) { 111 k := f.getHeightKeeper(goCtx) 112 return k.UnreceivedPackets(goCtx, request) 113 } 114 115 func (f *FacadedKeeper) UnreceivedAcks(goCtx context.Context, request *channeltyeps.QueryUnreceivedAcksRequest) (*channeltyeps.QueryUnreceivedAcksResponse, error) { 116 k := f.getHeightKeeper(goCtx) 117 return k.UnreceivedAcks(goCtx, request) 118 } 119 120 func (f *FacadedKeeper) NextSequenceReceive(goCtx context.Context, request *channeltyeps.QueryNextSequenceReceiveRequest) (*channeltyeps.QueryNextSequenceReceiveResponse, error) { 121 k := f.getHeightKeeper(goCtx) 122 return k.NextSequenceReceive(goCtx, request) 123 } 124 125 func (f *FacadedKeeper) ChannelOpenInit(goCtx context.Context, init *channeltyeps.MsgChannelOpenInit) (*channeltyeps.MsgChannelOpenInitResponse, error) { 126 k := f.getHeightKeeper(goCtx) 127 return k.ChannelOpenInit(goCtx, init) 128 } 129 130 func (f *FacadedKeeper) ChannelOpenTry(goCtx context.Context, try *channeltyeps.MsgChannelOpenTry) (*channeltyeps.MsgChannelOpenTryResponse, error) { 131 k := f.getHeightKeeper(goCtx) 132 return k.ChannelOpenTry(goCtx, try) 133 } 134 135 func (f *FacadedKeeper) ChannelOpenAck(goCtx context.Context, ack *channeltyeps.MsgChannelOpenAck) (*channeltyeps.MsgChannelOpenAckResponse, error) { 136 k := f.getHeightKeeper(goCtx) 137 return k.ChannelOpenAck(goCtx, ack) 138 } 139 140 func (f *FacadedKeeper) ChannelOpenConfirm(goCtx context.Context, confirm *channeltyeps.MsgChannelOpenConfirm) (*channeltyeps.MsgChannelOpenConfirmResponse, error) { 141 k := f.getHeightKeeper(goCtx) 142 return k.ChannelOpenConfirm(goCtx, confirm) 143 } 144 145 func (f *FacadedKeeper) ChannelCloseInit(goCtx context.Context, init *channeltyeps.MsgChannelCloseInit) (*channeltyeps.MsgChannelCloseInitResponse, error) { 146 k := f.getHeightKeeper(goCtx) 147 return k.ChannelCloseInit(goCtx, init) 148 } 149 150 func (f *FacadedKeeper) ChannelCloseConfirm(goCtx context.Context, confirm *channeltyeps.MsgChannelCloseConfirm) (*channeltyeps.MsgChannelCloseConfirmResponse, error) { 151 k := f.getHeightKeeper(goCtx) 152 return k.ChannelCloseConfirm(goCtx, confirm) 153 } 154 155 func (f *FacadedKeeper) RecvPacket(goCtx context.Context, packet *channeltyeps.MsgRecvPacket) (*channeltyeps.MsgRecvPacketResponse, error) { 156 k := f.getHeightKeeper(goCtx) 157 return k.RecvPacket(goCtx, packet) 158 } 159 160 func (f *FacadedKeeper) Timeout(goCtx context.Context, timeout *channeltyeps.MsgTimeout) (*channeltyeps.MsgTimeoutResponse, error) { 161 k := f.getHeightKeeper(goCtx) 162 return k.Timeout(goCtx, timeout) 163 } 164 165 func (f *FacadedKeeper) TimeoutOnClose(goCtx context.Context, onClose *channeltyeps.MsgTimeoutOnClose) (*channeltyeps.MsgTimeoutOnCloseResponse, error) { 166 k := f.getHeightKeeper(goCtx) 167 return k.TimeoutOnClose(goCtx, onClose) 168 } 169 170 func (f *FacadedKeeper) Acknowledgement(goCtx context.Context, acknowledgement *channeltyeps.MsgAcknowledgement) (*channeltyeps.MsgAcknowledgementResponse, error) { 171 k := f.getHeightKeeper(goCtx) 172 return k.Acknowledgement(goCtx, acknowledgement) 173 } 174 175 func (f *FacadedKeeper) CreateClient(goCtx context.Context, client *clienttypes.MsgCreateClient) (*clienttypes.MsgCreateClientResponse, error) { 176 k := f.getHeightKeeper(goCtx) 177 return k.CreateClient(goCtx, client) 178 } 179 180 func (f *FacadedKeeper) UpdateClient(goCtx context.Context, client *clienttypes.MsgUpdateClient) (*clienttypes.MsgUpdateClientResponse, error) { 181 k := f.getHeightKeeper(goCtx) 182 return k.UpdateClient(goCtx, client) 183 } 184 185 func (f *FacadedKeeper) UpgradeClient(goCtx context.Context, client *clienttypes.MsgUpgradeClient) (*clienttypes.MsgUpgradeClientResponse, error) { 186 k := f.getHeightKeeper(goCtx) 187 return k.UpgradeClient(goCtx, client) 188 } 189 190 func (f *FacadedKeeper) SubmitMisbehaviour(goCtx context.Context, misbehaviour *clienttypes.MsgSubmitMisbehaviour) (*clienttypes.MsgSubmitMisbehaviourResponse, error) { 191 k := f.getHeightKeeper(goCtx) 192 return k.SubmitMisbehaviour(goCtx, misbehaviour) 193 } 194 195 func (f *FacadedKeeper) ConnectionOpenInit(goCtx context.Context, init *connectiontypes.MsgConnectionOpenInit) (*connectiontypes.MsgConnectionOpenInitResponse, error) { 196 k := f.getHeightKeeper(goCtx) 197 return k.ConnectionOpenInit(goCtx, init) 198 } 199 200 func (f *FacadedKeeper) ConnectionOpenTry(goCtx context.Context, try *connectiontypes.MsgConnectionOpenTry) (*connectiontypes.MsgConnectionOpenTryResponse, error) { 201 k := f.getHeightKeeper(goCtx) 202 return k.ConnectionOpenTry(goCtx, try) 203 } 204 205 func (f *FacadedKeeper) ConnectionOpenAck(goCtx context.Context, ack *connectiontypes.MsgConnectionOpenAck) (*connectiontypes.MsgConnectionOpenAckResponse, error) { 206 k := f.getHeightKeeper(goCtx) 207 return k.ConnectionOpenAck(goCtx, ack) 208 } 209 210 func (f *FacadedKeeper) ConnectionOpenConfirm(goCtx context.Context, confirm *connectiontypes.MsgConnectionOpenConfirm) (*connectiontypes.MsgConnectionOpenConfirmResponse, error) { 211 k := f.getHeightKeeper(goCtx) 212 return k.ConnectionOpenConfirm(goCtx, confirm) 213 } 214 215 func (f *FacadedKeeper) getHeightKeeper(goCtx context.Context) IBCServerKeeper { 216 ctx := sdk.UnwrapSDKContext(goCtx) 217 return f.doGetByCtx(ctx) 218 } 219 220 func (f *FacadedKeeper) doGetByCtx(ctx sdk.Context) IBCServerKeeper { 221 return f.GetProxy(ctx).(IBCServerKeeper) 222 } 223 224 func (f *FacadedKeeper) GetIbcEnabled(ctx sdk.Context) bool { 225 return f.doGetByCtx(ctx).GetIbcEnabled(ctx) 226 }