-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '@/snackages/cosmos/query/bank' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters