import { PageRequest, PageResponse } from "../../../../cosmos/base/query/v1beta1/pagination"; import { Channel, IdentifiedChannel, PacketState } from "./channel"; import { Height, IdentifiedClientState } from "../../client/v1/client"; import { Any } from "../../../../google/protobuf/any"; import { LCDClient } from "@osmonauts/lcd"; import { setPaginationParams } from "@osmonauts/helpers"; import { QueryChannelRequest, QueryChannelResponse, QueryChannelsRequest, QueryChannelsResponse, QueryConnectionChannelsRequest, QueryConnectionChannelsResponse, QueryChannelClientStateRequest, QueryChannelClientStateResponse, QueryChannelConsensusStateRequest, QueryChannelConsensusStateResponse, QueryPacketCommitmentRequest, QueryPacketCommitmentResponse, QueryPacketCommitmentsRequest, QueryPacketCommitmentsResponse, QueryPacketReceiptRequest, QueryPacketReceiptResponse, QueryPacketAcknowledgementRequest, QueryPacketAcknowledgementResponse, QueryPacketAcknowledgementsRequest, QueryPacketAcknowledgementsResponse, QueryUnreceivedPacketsRequest, QueryUnreceivedPacketsResponse, QueryUnreceivedAcksRequest, QueryUnreceivedAcksResponse, QueryNextSequenceReceiveRequest, QueryNextSequenceReceiveResponse } from "./query"; export class LCDQueryClient extends LCDClient { constructor({ restEndpoint }: { restEndpoint: string; }) { super({ restEndpoint }); } /* Channel queries an IBC Channel. */ async channel(params: QueryChannelRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}ports/${params.port_id}`; return await this.request(endpoint); } /* Channels queries all the IBC channels of a chain. */ async channels(params: QueryChannelsRequest = { pagination: undefined }): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `ibc/core/channel/v1/channels`; return await this.request(endpoint, options); } /* ConnectionChannels queries all the channels associated with a connection end. */ async connectionChannels(params: QueryConnectionChannelsRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `ibc/core/channel/v1/connections/${params.connection}/channels`; return await this.request(endpoint, options); } /* ChannelClientState queries for the client state for the channel associated with the provided channel identifiers. */ async channelClientState(params: QueryChannelClientStateRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/client_state`; return await this.request(endpoint); } /* ChannelConsensusState queries for the consensus state for the channel associated with the provided channel identifiers. */ async channelConsensusState(params: QueryChannelConsensusStateRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/consensus_state/revision/${params.revision_number}height/${params.revision_height}`; return await this.request(endpoint); } /* PacketCommitment queries a stored packet commitment hash. */ async packetCommitment(params: QueryPacketCommitmentRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}packet_commitments/${params.sequence}`; return await this.request(endpoint); } /* PacketCommitments returns all the packet commitments hashes associated with a channel. */ async packetCommitments(params: QueryPacketCommitmentsRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/packet_commitments`; return await this.request(endpoint, options); } /* PacketReceipt queries if a given packet sequence has been received on the queried chain */ async packetReceipt(params: QueryPacketReceiptRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}packet_receipts/${params.sequence}`; return await this.request(endpoint); } /* PacketAcknowledgement queries a stored packet acknowledgement hash. */ async packetAcknowledgement(params: QueryPacketAcknowledgementRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}packet_acks/${params.sequence}`; return await this.request(endpoint); } /* PacketAcknowledgements returns all the packet acknowledgements associated with a channel. */ async packetAcknowledgements(params: QueryPacketAcknowledgementsRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } if (typeof params?.packet_commitment_sequences !== "undefined") { options.params.packet_commitment_sequences = params.packet_commitment_sequences; } const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/packet_acknowledgements`; return await this.request(endpoint, options); } /* UnreceivedPackets returns all the unreceived IBC packets associated with a channel and sequences. */ async unreceivedPackets(params: QueryUnreceivedPacketsRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/packet_commitments/${params.packet_commitment_sequences}/unreceived_packets`; return await this.request(endpoint); } /* UnreceivedAcks returns all the unreceived IBC acknowledgements associated with a channel and sequences. */ async unreceivedAcks(params: QueryUnreceivedAcksRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/packet_commitments/${params.packet_ack_sequences}/unreceived_acks`; return await this.request(endpoint); } /* NextSequenceReceive returns the next receive sequence for a given channel. */ async nextSequenceReceive(params: QueryNextSequenceReceiveRequest): Promise { const endpoint = `ibc/core/channel/v1/channels/${params.channel_id}/ports/${params.port_id}/next_sequence`; return await this.request(endpoint); } }