Merge pull request #1503 from cosmos/properly-handle-numeric-values
Handle key value pairs in tx search correctly for numbers
This commit is contained in:
commit
9be43b0722
@ -15,6 +15,13 @@ and this project adheres to
|
||||
|
||||
[#1489]: https://github.com/cosmos/cosmjs/pull/1489
|
||||
|
||||
### Fixed
|
||||
|
||||
- @cosmjs/stargate: Handle key value pairs in tx search correctly if the value
|
||||
is a numeric value. ([#1462])
|
||||
|
||||
[#1462] : https://github.com/cosmos/cosmjs/issues/1462
|
||||
|
||||
### Changed
|
||||
|
||||
- all: Upgrade cosmjs-types to 0.9.0. This makes a few fields non-optional. It
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
DeliverTxResponse,
|
||||
fromTendermintEvent,
|
||||
IndexedTx,
|
||||
isSearchTxQueryArray,
|
||||
QueryClient,
|
||||
SearchTxQuery,
|
||||
SequenceResponse,
|
||||
@ -216,8 +217,14 @@ export class CosmWasmClient {
|
||||
let rawQuery: string;
|
||||
if (typeof query === "string") {
|
||||
rawQuery = query;
|
||||
} else if (Array.isArray(query)) {
|
||||
rawQuery = query.map((t) => `${t.key}='${t.value}'`).join(" AND ");
|
||||
} else if (isSearchTxQueryArray(query)) {
|
||||
rawQuery = query
|
||||
.map((t) => {
|
||||
// numeric values must not have quotes https://github.com/cosmos/cosmjs/issues/1462
|
||||
if (typeof t.value === "string") return `${t.key}='${t.value}'`;
|
||||
else return `${t.key}=${t.value}`;
|
||||
})
|
||||
.join(" AND ");
|
||||
} else {
|
||||
throw new Error("Got unsupported query type. See CosmJS 0.31 CHANGELOG for API breaking changes here.");
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ export {
|
||||
QueryClient,
|
||||
QueryStoreResponse,
|
||||
} from "./queryclient";
|
||||
export { SearchTxQuery } from "./search";
|
||||
export { isSearchTxQueryArray, SearchPair, SearchTxQuery } from "./search";
|
||||
export {
|
||||
createDefaultAminoConverters,
|
||||
defaultRegistryTypes,
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
/** A key value pair for searching transactions */
|
||||
export interface SearchPair {
|
||||
readonly key: string;
|
||||
readonly value: string | number | bigint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This query type allows you to pass arbitrary key/value pairs to the backend.
|
||||
*/
|
||||
export type SearchTxQuery =
|
||||
| string
|
||||
| ReadonlyArray<{
|
||||
readonly key: string;
|
||||
readonly value: string;
|
||||
}>;
|
||||
export type SearchTxQuery = string | readonly SearchPair[];
|
||||
|
||||
export function isSearchTxQueryArray(query: SearchTxQuery): query is readonly SearchPair[] {
|
||||
return Array.isArray(query);
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ import {
|
||||
TxExtension,
|
||||
} from "./modules";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { SearchTxQuery } from "./search";
|
||||
import { isSearchTxQueryArray, SearchTxQuery } from "./search";
|
||||
|
||||
export class TimeoutError extends Error {
|
||||
public readonly txId: string;
|
||||
@ -386,8 +386,14 @@ export class StargateClient {
|
||||
let rawQuery: string;
|
||||
if (typeof query === "string") {
|
||||
rawQuery = query;
|
||||
} else if (Array.isArray(query)) {
|
||||
rawQuery = query.map((t) => `${t.key}='${t.value}'`).join(" AND ");
|
||||
} else if (isSearchTxQueryArray(query)) {
|
||||
rawQuery = query
|
||||
.map((t) => {
|
||||
// numeric values must not have quotes https://github.com/cosmos/cosmjs/issues/1462
|
||||
if (typeof t.value === "string") return `${t.key}='${t.value}'`;
|
||||
else return `${t.key}=${t.value}`;
|
||||
})
|
||||
.join(" AND ");
|
||||
} else {
|
||||
throw new Error("Got unsupported query type. See CosmJS 0.31 CHANGELOG for API breaking changes here.");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user