diff --git a/src/client/services/clientServices.ts b/src/client/services/clientServices.ts index 10b2ef3..3b43216 100644 --- a/src/client/services/clientServices.ts +++ b/src/client/services/clientServices.ts @@ -10,23 +10,31 @@ import { identifyQueryResponseErrors } from '~/errors'; /** * query the contract using a secret client + * @param blockHeight This is an optional property to query at a specific block height + * and may require use of an archive node depending on how far into the history data + * is required. */ const secretClientContractQuery$ = ({ queryMsg, client, contractAddress, codeHash, + blockHeight, }: { queryMsg: any, client: SecretNetworkClient, contractAddress: string, codeHash?: string + blockHeight?: number }) => createFetchClient(defer( - () => from(client.query.compute.queryContract({ - contract_address: contractAddress, - code_hash: codeHash, - query: queryMsg, - })), + () => from(client.query.compute.queryContract( + { + contract_address: contractAddress, + code_hash: codeHash, + query: queryMsg, + }, + blockHeight ? [['x-cosmos-block-height', blockHeight.toString()]] : undefined, + )), )); /** @@ -37,16 +45,19 @@ const sendSecretClientContractQuery$ = ({ client, contractAddress, codeHash, + blockHeight, }: { queryMsg: any, client: SecretNetworkClient, contractAddress: string, - codeHash?: string + codeHash?: string, + blockHeight?: number, }) => secretClientContractQuery$({ queryMsg, client, contractAddress, codeHash, + blockHeight, }) .pipe( tap((response) => identifyQueryResponseErrors(response)), diff --git a/src/contracts/services/batchQuery.ts b/src/contracts/services/batchQuery.ts index a6f2c9e..732f801 100644 --- a/src/contracts/services/batchQuery.ts +++ b/src/contracts/services/batchQuery.ts @@ -70,12 +70,14 @@ const batchQuerySingleBatch$ = ({ queries, client, minBlockHeightValidationOptions, + blockHeight, }:{ contractAddress: string, codeHash?: string, queries: BatchQueryParams[], client: SecretNetworkClient, minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, }) => { let retryCount = 0; return of(1).pipe( // placeholder observable of(1) used here so that we can start a data stream @@ -85,6 +87,7 @@ const batchQuerySingleBatch$ = ({ client, contractAddress, codeHash, + blockHeight, }).pipe( map((response) => response as BatchQueryResponse), // map used for typecast only switchMap((response) => { @@ -137,6 +140,7 @@ const batchQuery$ = ({ queries, batchSize, minBlockHeightValidationOptions, + blockHeight, }:{ contractAddress: string, codeHash?: string, @@ -145,6 +149,7 @@ const batchQuery$ = ({ queries: BatchQueryParams[], batchSize?: number, minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, }) => { // if batch size is passed in, convert single batch into multiple batches, // otherwise process all data in a single batch @@ -160,6 +165,7 @@ const batchQuery$ = ({ queries: batch, client, minBlockHeightValidationOptions, + blockHeight, })), ).pipe( concatAll(), @@ -185,6 +191,7 @@ async function batchQuery({ queries, batchSize, minBlockHeightValidationOptions, + blockHeight, }:{ contractAddress: string, codeHash?: string, @@ -193,6 +200,7 @@ async function batchQuery({ queries: BatchQueryParams[], batchSize?: number, minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, }) { return lastValueFrom(batchQuery$({ contractAddress, @@ -202,6 +210,7 @@ async function batchQuery({ queries, batchSize, minBlockHeightValidationOptions, + blockHeight, })); } diff --git a/src/contracts/services/swap.ts b/src/contracts/services/swap.ts index d272df2..0d941b5 100644 --- a/src/contracts/services/swap.ts +++ b/src/contracts/services/swap.ts @@ -516,6 +516,7 @@ function batchQueryPairsInfo$({ pairsContracts, batchSize = SERVICE_BATCH_SIZE.PAIR_INFO, minBlockHeightValidationOptions, + blockHeight, }:{ queryRouterContractAddress: string, queryRouterCodeHash?: string, @@ -524,6 +525,7 @@ function batchQueryPairsInfo$({ pairsContracts: Contract[], batchSize?: number, minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, }) { const queries:BatchQueryParams[] = pairsContracts.map((contract) => ({ id: contract.address, @@ -541,6 +543,7 @@ function batchQueryPairsInfo$({ queries, batchSize, minBlockHeightValidationOptions, + blockHeight, }).pipe( map(parseBatchQueryPairInfoResponse), first(), @@ -558,6 +561,7 @@ async function batchQueryPairsInfo({ pairsContracts, batchSize, minBlockHeightValidationOptions, + blockHeight, }:{ queryRouterContractAddress: string, queryRouterCodeHash?: string, @@ -566,6 +570,7 @@ async function batchQueryPairsInfo({ pairsContracts: Contract[], batchSize?: number, minBlockHeightValidationOptions?: MinBlockHeightValidationOptions, + blockHeight?: number, }) { return lastValueFrom(batchQueryPairsInfo$({ queryRouterContractAddress, @@ -575,6 +580,7 @@ async function batchQueryPairsInfo({ pairsContracts, batchSize, minBlockHeightValidationOptions, + blockHeight, })); }