Skip to content

Commit

Permalink
feat: rough start, needs work
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPresident committed Oct 30, 2023
1 parent 755243f commit a02451b
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/client/services/clientServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { SecretNetworkClient } from 'secretjs';
import { createFetchClient } from '~/client/services/createFetch';
import { identifyQueryResponseErrors } from '~/errors';

import { Buffer } from 'buffer';

/**
* query the contract using a secret client
*/
Expand All @@ -29,6 +31,40 @@ const secretClientContractQuery$ = ({
})),
));

type BatchQuery = {
contract: {
address: string,
code_hash: string,
},
query: any,
}

const secretClientBatchQuery$ = ({
client,
queryRouterAddress,
queryRouterCodeHash,
queries,
}: {
client: SecretNetworkClient,
queryRouterAddress: string,
queryRouterCodeHash?: string
queries: BatchQuery[],
}) => createFetchClient(defer(
() => from(client.query.compute.queryContract({
contract_address: queryRouterAddress,
code_hash: queryRouterCodeHash,
query: {
batch: {
queries: queries.map((q, i) => ({
id: Buffer.from(i.toString(), 'binary').toString('base64'),
contract: q.contract,
query: Buffer.from(JSON.stringify(q.query), 'binary').toString('base64'),
})),
},
},
})),
));

/**
* sets up the service observable for calling the querying with the secret client
*/
Expand All @@ -53,6 +89,28 @@ const sendSecretClientContractQuery$ = ({
first(),
);

const sendSecretClientBatchQuery$ = ({
client,
queryRouterAddress,
queryRouterCodeHash,
queries,
}: {
client: SecretNetworkClient,
queryRouterAddress: string,
queryRouterCodeHash?: string
queries: BatchQuery[],
}) => secretClientBatchQuery$({
client,
queryRouterAddress,
queryRouterCodeHash,
queries,
})
.pipe(
tap((response) => identifyQueryResponseErrors(response)),
first(),
);

export {
sendSecretClientContractQuery$,
sendSecretClientBatchQuery$,
};

0 comments on commit a02451b

Please sign in to comment.