diff --git a/packages/stargate/src/index.ts b/packages/stargate/src/index.ts index a7e963dd..6dd9e6eb 100644 --- a/packages/stargate/src/index.ts +++ b/packages/stargate/src/index.ts @@ -22,8 +22,20 @@ export { setupStakingExtension, StakingExtension, } from "./queries"; +export { + SearchByHeightQuery, + SearchBySentFromOrToQuery, + SearchByTagsQuery, + SearchTxQuery, + SearchTxFilter, + isSearchByHeightQuery, + isSearchBySentFromOrToQuery, + isSearchByTagsQuery, +} from "./search"; export { assertIsBroadcastTxSuccess, + Block, + BlockHeader, BroadcastTxFailure, BroadcastTxResponse, BroadcastTxSuccess, diff --git a/packages/stargate/src/search.ts b/packages/stargate/src/search.ts new file mode 100644 index 00000000..aae61508 --- /dev/null +++ b/packages/stargate/src/search.ts @@ -0,0 +1,34 @@ +export interface SearchByHeightQuery { + readonly height: number; +} + +export interface SearchBySentFromOrToQuery { + readonly sentFromOrTo: string; +} + +/** + * This query type allows you to pass arbitrary key/value pairs to the backend. It is + * more powerful and slightly lower level than the other search options. + */ +export interface SearchByTagsQuery { + readonly tags: ReadonlyArray<{ readonly key: string; readonly value: string }>; +} + +export type SearchTxQuery = SearchByHeightQuery | SearchBySentFromOrToQuery | SearchByTagsQuery; + +export function isSearchByHeightQuery(query: SearchTxQuery): query is SearchByHeightQuery { + return (query as SearchByHeightQuery).height !== undefined; +} + +export function isSearchBySentFromOrToQuery(query: SearchTxQuery): query is SearchBySentFromOrToQuery { + return (query as SearchBySentFromOrToQuery).sentFromOrTo !== undefined; +} + +export function isSearchByTagsQuery(query: SearchTxQuery): query is SearchByTagsQuery { + return (query as SearchByTagsQuery).tags !== undefined; +} + +export interface SearchTxFilter { + readonly minHeight?: number; + readonly maxHeight?: number; +} diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index 6ba5914a..8ee069bd 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -1,13 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { toHex } from "@cosmjs/encoding"; -import { - Block, - isSearchByHeightQuery, - isSearchBySentFromOrToQuery, - isSearchByTagsQuery, - SearchTxFilter, - SearchTxQuery, -} from "@cosmjs/launchpad"; import { Uint53 } from "@cosmjs/math"; import { broadcastTxCommitSuccess, @@ -20,6 +12,38 @@ import { Account, accountFromAny } from "./accounts"; import { MsgData, TxMsgData } from "./codec/cosmos/base/abci/v1beta1/abci"; import { Coin } from "./codec/cosmos/base/v1beta1/coin"; import { AuthExtension, BankExtension, QueryClient, setupAuthExtension, setupBankExtension } from "./queries"; +import { + isSearchByHeightQuery, + isSearchBySentFromOrToQuery, + isSearchByTagsQuery, + SearchTxFilter, + SearchTxQuery, +} from "./search"; + +/** + * This is the same as BlockHeader from @cosmjs/launchpad but those might diverge in the future. + */ +export interface BlockHeader { + readonly version: { + readonly block: string; + readonly app: string; + }; + readonly height: number; + readonly chainId: string; + /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ + readonly time: string; +} + +/** + * This is the same as Block from @cosmjs/launchpad but those might diverge in the future. + */ +export interface Block { + /** The ID is a hash of the block header (uppercase hex) */ + readonly id: string; + readonly header: BlockHeader; + /** Array of raw transactions */ + readonly txs: readonly Uint8Array[]; +} /** A transaction that is indexed as part of the transaction history */ export interface IndexedTx {