Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow other operations for tx search api #75

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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