import { setPaginationParams } from "../../../helpers"; import { LCDClient } from "@osmonauts/lcd"; import { GetTxRequest, GetTxResponseSDKType, GetTxsEventRequest, GetTxsEventResponseSDKType, GetBlockWithTxsRequest, GetBlockWithTxsResponseSDKType } from "./service"; export class LCDQueryClient { req: LCDClient; constructor({ requestClient }: { requestClient: LCDClient; }) { this.req = requestClient; this.getTx = this.getTx.bind(this); this.getTxsEvent = this.getTxsEvent.bind(this); this.getBlockWithTxs = this.getBlockWithTxs.bind(this); } /* GetTx fetches a tx by hash. */ async getTx(params: GetTxRequest): Promise { const endpoint = `cosmos/tx/v1beta1/txs/${params.hash}`; return await this.req.get(endpoint); } /* GetTxsEvent fetches txs by event. */ async getTxsEvent(params: GetTxsEventRequest): Promise { const options: any = { params: {} }; if (typeof params?.events !== "undefined") { options.params.events = params.events; } if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } if (typeof params?.orderBy !== "undefined") { options.params.order_by = params.orderBy; } if (typeof params?.page !== "undefined") { options.params.page = params.page; } if (typeof params?.limit !== "undefined") { options.params.limit = params.limit; } if (typeof params?.query !== "undefined") { options.params.query = params.query; } const endpoint = `cosmos/tx/v1beta1/txs`; return await this.req.get(endpoint, options); } /* GetBlockWithTxs fetches a block with decoded txs. Since: cosmos-sdk 0.45.2 */ async getBlockWithTxs(params: GetBlockWithTxsRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `cosmos/tx/v1beta1/txs/block/${params.height}`; return await this.req.get(endpoint, options); } }