Skip to content

Commit

Permalink
feat: archive node block height param
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWoetzel committed Jul 10, 2024
1 parent 1cc4633 commit 3118345
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/client/services/clientServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)),
));

/**
Expand All @@ -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)),
Expand Down
9 changes: 9 additions & 0 deletions src/contracts/services/batchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -85,6 +87,7 @@ const batchQuerySingleBatch$ = ({
client,
contractAddress,
codeHash,
blockHeight,
}).pipe(
map((response) => response as BatchQueryResponse), // map used for typecast only
switchMap((response) => {
Expand Down Expand Up @@ -137,6 +140,7 @@ const batchQuery$ = ({
queries,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}:{
contractAddress: string,
codeHash?: string,
Expand All @@ -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
Expand All @@ -160,6 +165,7 @@ const batchQuery$ = ({
queries: batch,
client,
minBlockHeightValidationOptions,
blockHeight,
})),
).pipe(
concatAll(),
Expand All @@ -185,6 +191,7 @@ async function batchQuery({
queries,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}:{
contractAddress: string,
codeHash?: string,
Expand All @@ -193,6 +200,7 @@ async function batchQuery({
queries: BatchQueryParams[],
batchSize?: number,
minBlockHeightValidationOptions?: MinBlockHeightValidationOptions,
blockHeight?: number,
}) {
return lastValueFrom(batchQuery$({
contractAddress,
Expand All @@ -202,6 +210,7 @@ async function batchQuery({
queries,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}));
}

Expand Down
6 changes: 6 additions & 0 deletions src/contracts/services/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ function batchQueryPairsInfo$({
pairsContracts,
batchSize = SERVICE_BATCH_SIZE.PAIR_INFO,
minBlockHeightValidationOptions,
blockHeight,
}:{
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
Expand All @@ -524,6 +525,7 @@ function batchQueryPairsInfo$({
pairsContracts: Contract[],
batchSize?: number,
minBlockHeightValidationOptions?: MinBlockHeightValidationOptions,
blockHeight?: number,
}) {
const queries:BatchQueryParams[] = pairsContracts.map((contract) => ({
id: contract.address,
Expand All @@ -541,6 +543,7 @@ function batchQueryPairsInfo$({
queries,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}).pipe(
map(parseBatchQueryPairInfoResponse),
first(),
Expand All @@ -558,6 +561,7 @@ async function batchQueryPairsInfo({
pairsContracts,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}:{
queryRouterContractAddress: string,
queryRouterCodeHash?: string,
Expand All @@ -566,6 +570,7 @@ async function batchQueryPairsInfo({
pairsContracts: Contract[],
batchSize?: number,
minBlockHeightValidationOptions?: MinBlockHeightValidationOptions,
blockHeight?: number,
}) {
return lastValueFrom(batchQueryPairsInfo$({
queryRouterContractAddress,
Expand All @@ -575,6 +580,7 @@ async function batchQueryPairsInfo({
pairsContracts,
batchSize,
minBlockHeightValidationOptions,
blockHeight,
}));
}

Expand Down

0 comments on commit 3118345

Please sign in to comment.