Skip to content

Commit

Permalink
Merge pull request #75 from initia-labs/feat/tx-search
Browse files Browse the repository at this point in the history
Allow other operations for tx search api
  • Loading branch information
joon9823 authored Aug 29, 2024
2 parents d9cb6a2 + fc4b73a commit bd35e56
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.2.9",
"version": "0.2.10",
"description": "The JavaScript SDK for Initia",
"license": "Apache-2.0",
"author": "Initia Foundation",
Expand Down
28 changes: 18 additions & 10 deletions src/client/lcd/api/TxAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,14 @@ export namespace SimulateResponse {
}
}

export type TxSearchOp = '=' | '<' | '<=' | '>' | '>=' | 'CONTAINS' | 'EXISTS'

export interface TxSearchOptions extends PaginationOptions {
query: { key: string; value: string }[]
query: {
key: string
value: string
op?: TxSearchOp
}[]
}

export class TxAPI extends BaseAPI {
Expand Down Expand Up @@ -515,18 +521,20 @@ export class TxAPI extends BaseAPI {
): Promise<TxSearchResult> {
const params = new URLSearchParams()

// build search params
options.query?.forEach((v) =>
params.append(
'query',
v.key === 'tx.height' ? `${v.key}=${v.value}` : `${v.key}='${v.value}'`
)
)
const query: string = (options.query ?? []).reduce((str, q) => {
if (!q.key) return str
const op = q.op ?? '='
const value = q.key === 'tx.height' ? `${q.value}` : `'${q.value}'`
const queryStr =
op === 'EXISTS' ? `${q.key} ${op}` : `${q.key} ${op} ${value}`
return str ? `${str} AND ${queryStr}` : queryStr
}, '')

delete options['query']
if (query) params.append('query', query)
options['query'] = undefined

Object.entries(options).forEach((v) => {
params.append(v[0], v[1] as string)
params.append(v[0], v[1].toString())
})

return this.c
Expand Down

0 comments on commit bd35e56

Please sign in to comment.