import { setPaginationParams } from "../../../helpers"; import { LCDClient } from "@osmonauts/lcd"; import { QueryContractInfoRequest, QueryContractInfoResponseSDKType, QueryContractHistoryRequest, QueryContractHistoryResponseSDKType, QueryContractsByCodeRequest, QueryContractsByCodeResponseSDKType, QueryAllContractStateRequest, QueryAllContractStateResponseSDKType, QueryRawContractStateRequest, QueryRawContractStateResponseSDKType, QuerySmartContractStateRequest, QuerySmartContractStateResponseSDKType, QueryCodeRequest, QueryCodeResponseSDKType, QueryCodesRequest, QueryCodesResponseSDKType, QueryPinnedCodesRequest, QueryPinnedCodesResponseSDKType } from "./query"; export class LCDQueryClient { req: LCDClient; constructor({ requestClient }: { requestClient: LCDClient; }) { this.req = requestClient; this.contractInfo = this.contractInfo.bind(this); this.contractHistory = this.contractHistory.bind(this); this.contractsByCode = this.contractsByCode.bind(this); this.allContractState = this.allContractState.bind(this); this.rawContractState = this.rawContractState.bind(this); this.smartContractState = this.smartContractState.bind(this); this.code = this.code.bind(this); this.codes = this.codes.bind(this); this.pinnedCodes = this.pinnedCodes.bind(this); } /* ContractInfo gets the contract meta data */ async contractInfo(params: QueryContractInfoRequest): Promise { const endpoint = `cosmwasm/wasm/v1/contract/${params.address}`; return await this.req.get(endpoint); } /* ContractHistory gets the contract code history */ async contractHistory(params: QueryContractHistoryRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `cosmwasm/wasm/v1/contract/${params.address}/history`; return await this.req.get(endpoint, options); } /* ContractsByCode lists all smart contracts for a code id */ async contractsByCode(params: QueryContractsByCodeRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `cosmwasm/wasm/v1/code/${params.codeId}/contracts`; return await this.req.get(endpoint, options); } /* AllContractState gets all raw store data for a single contract */ async allContractState(params: QueryAllContractStateRequest): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `cosmwasm/wasm/v1/contract/${params.address}/state`; return await this.req.get(endpoint, options); } /* RawContractState gets single key from the raw store data of a contract */ async rawContractState(params: QueryRawContractStateRequest): Promise { const endpoint = `wasm/v1/contract/${params.address}raw/${params.queryData}`; return await this.req.get(endpoint); } /* SmartContractState get smart query result from the contract */ async smartContractState(params: QuerySmartContractStateRequest): Promise { const endpoint = `wasm/v1/contract/${params.address}smart/${params.queryData}`; return await this.req.get(endpoint); } /* Code gets the binary code and metadata for a singe wasm code */ async code(params: QueryCodeRequest): Promise { const endpoint = `cosmwasm/wasm/v1/code/${params.codeId}`; return await this.req.get(endpoint); } /* Codes gets the metadata for all stored wasm codes */ async codes(params: QueryCodesRequest = { pagination: undefined }): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `cosmwasm/wasm/v1/code`; return await this.req.get(endpoint, options); } /* PinnedCodes gets the pinned code ids */ async pinnedCodes(params: QueryPinnedCodesRequest = { pagination: undefined }): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `cosmwasm/wasm/v1/codes/pinned`; return await this.req.get(endpoint, options); } }