cosmos / cosmjs

The Swiss Army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers.
https://cosmos.github.io/cosmjs/
Apache License 2.0
636 stars 324 forks source link

feature request: add support for comparsion operator to SearchPair #1580

Open seleniumforest opened 2 months ago

seleniumforest commented 2 months ago

search.ts

export interface SearchPair {
  readonly key: string;
  readonly value: string | number | bigint;
  readonly comparsionOp?: ">" | ">=" | "<" | "<="
}

It will be useful, for example, when you want to find logs by composite key in range of blocks (stargateclient.ts)

rawQuery = query
        .map((t) => {
          let compOp = t.comparsionOp || "="
          if (typeof t.value === "string") return `${t.key}${compOp}'${t.value}'`;
          else return `${t.key}${compOp}${t.value}`;
        })
        .join(" AND ");

Then client could use like this:

await searchTx([
  {key: "tx.height",  comparsionOp: ">" ,value: 10},
  {key: "tx.height",  comparsionOp: "<" ,value: 20},
])