Skip to content

Commit

Permalink
adding basic bank query coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Aug 12, 2024
1 parent 21acf4f commit 6a44f7b
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 2 deletions.
45 changes: 45 additions & 0 deletions src/interfaces/snackages/IBankExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
DQueryAllBalances,
DQueryBalance,
TQueryAllBalancesResponseStrict,
TQueryBalanceResponseStrict
} from '@/types/queries'

/**
* @interface IBankExtension
* @property {IBankExtensionMembers} bank
*/
export interface IBankExtension
extends Record<string, IBankExtensionMembers> {
readonly bank: IBankExtensionMembers
}

/**
* Some functions for querying data from the Bank module.
*
* @interface IStorageExtensionMembers
* @property {allBalances} allBalances()
* @property {balance} balance()
*/
export interface IBankExtensionMembers
extends Record<string, (request?: any) => Promise<any>> {
/**
* @function allBalances
* @param {DQueryAllBalances} request
* @returns Promise<TQueryAllBalancesResponseStrict>
*/
readonly allBalances: (
request: DQueryAllBalances
) => Promise<TQueryAllBalancesResponseStrict>

/**
* @function balance
* @param {DQueryBalance} request
* @returns Promise<TQueryBalanceResponseStrict>
*/
readonly balance: (
request: DQueryBalance
) => Promise<TQueryBalanceResponseStrict>

}
1 change: 1 addition & 0 deletions src/interfaces/snackages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@/interfaces/snackages/IBankExtension'
export * from '@/interfaces/snackages/ICosmwasmExtension'
export * from '@/interfaces/snackages/IFileTreeExtension'
export * from '@/interfaces/snackages/IJklMintExtension'
Expand Down
7 changes: 5 additions & 2 deletions src/snackages/clientGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
} from '@/compatibility'
import { createCosmwasmExtension } from '@/snackages/query/cosmwasm'
import { cosmwasmTypes, TxCosmwasm } from '@/snackages/tx/cosmwasm'
import { createBankExtension } from '@/snackages/cosmos/query'

export type TJackalQueryClient = IIbcQueryClient<TQueryExtensions>
export type THostQueryClient = IIbcQueryClient<THostQueryExtensions>
Expand All @@ -59,7 +60,8 @@ export async function connectJackalQueryClient(
createOracleExtension,
createRnsExtension,
createStorageExtension,
createCosmwasmExtension
createCosmwasmExtension,
createBankExtension
]

return await IbcQueryClient.connect<TQueryExtensions>(endpoint, options)
Expand Down Expand Up @@ -96,7 +98,8 @@ export async function connectJackalSigningClient(
createOracleExtension,
createRnsExtension,
createStorageExtension,
createCosmwasmExtension
createCosmwasmExtension,
createBankExtension
]
const txLibrary = {
fileTree: TxFileTree,
Expand Down
45 changes: 45 additions & 0 deletions src/snackages/cosmos/query/bank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createProtobufRpcClient, QueryClient } from '@cosmjs/stargate'
import type { IBankExtension } from '@/interfaces'
import type { QueryAllBalancesRequest, QueryBalanceRequest } from '@/postGen/cosmos/bank/v1beta1/query'
import { QueryClientImpl } from '@/postGen/cosmos/bank/v1beta1/query'
import type {
DQueryAllBalances,
DQueryBalance,
TQueryAllBalancesResponseStrict,
TQueryBalanceResponseStrict
} from '@/types'
import { warnError } from '@/utils/misc'
import { assertDefined } from '@cosmjs/utils'

export function createBankExtension (base: QueryClient): IBankExtension {
const rpc = createProtobufRpcClient(base)
const queryService = new QueryClientImpl(rpc)

return {
bank: {
allBalances: async (
request: DQueryAllBalances
): Promise<TQueryAllBalancesResponseStrict> => {
const resp = await queryService
.AllBalances(request as QueryAllBalancesRequest)
.catch((err) => {
warnError('[Bank] allBalances', err)
throw err
})
return resp as TQueryAllBalancesResponseStrict
},
balance: async (
request: DQueryBalance
): Promise<TQueryBalanceResponseStrict> => {
const resp = await queryService
.Balance(request as QueryBalanceRequest)
.catch((err) => {
warnError('[Bank] balance', err)
throw err
})
assertDefined(resp.balance)
return resp as TQueryBalanceResponseStrict
}
}
}
}
1 change: 1 addition & 0 deletions src/snackages/cosmos/query/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@/snackages/cosmos/query/bank'
30 changes: 30 additions & 0 deletions src/types/queries/bank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { PageRequest } from '@/postGen/cosmos/base/query/v1beta1/pagination'
import { WithOptional } from '@/types/misc'
import { QueryAllBalancesRequest, QueryBalanceRequest } from '@/postGen/cosmos/bank/v1beta1/query'

/**
* QueryAllBalances Documentation
* @prop {string} address - Address of token.
* @prop {PageRequest} [pagination] - Optional pagination, defaults to first 100 results.
*/
export type DQueryAllBalances = Documentation<
{
address: string
pagination?: PageRequest
},
WithOptional<QueryAllBalancesRequest, 'pagination'>
>

/**
* QueryBalance Documentation
* @prop {string} address - Address of token.
* @prop {string} denom - Denom of token.
*/
export type DQueryBalance = Documentation<
{
address: string
denom: string

},
QueryBalanceRequest
>
1 change: 1 addition & 0 deletions src/types/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@/types/queries/bank'
export * from '@/types/queries/cosmwasm'
export * from '@/types/queries/fileTree'
export * from '@/types/queries/jklMint'
Expand Down
25 changes: 25 additions & 0 deletions src/types/queries/responses/bank.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { PageResponse } from '@/postGen/cosmos/base/query/v1beta1/pagination'
import type { QueryAllBalancesResponse, QueryBalanceResponse } from '@/postGen/cosmos/bank/v1beta1/query'
import type { DCoin } from '@/types'

/**
* This is the response for the [Bank] Query/AllBalances RPC method.
*
* @prop {DCoin[]} balances - Array of DCoin items.
* @prop {PageResponse} pagination - Pagination details.
*/
export type TQueryAllBalancesResponseStrict = ModifyDeep<
QueryAllBalancesResponse,
{ pagination: PageResponse }
>

/**
* This is the response for the [Bank] Query/Balance RPC method.
*
* @prop {DCoin} balance - Single DCoin item.
*/
export type TQueryBalanceResponseStrict = ModifyDeep<
QueryBalanceResponse,
{ balance: DCoin }
>

1 change: 1 addition & 0 deletions src/types/queries/responses/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@/types/queries/responses/bank'
export * from '@/types/queries/responses/cosmwasm'
export * from '@/types/queries/responses/fileTree'
export * from '@/types/queries/responses/jklMint'
Expand Down

0 comments on commit 6a44f7b

Please sign in to comment.