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
645 stars 330 forks source link

StargateClient.searchTx doesn't work if you passing KV-array #1462

Closed seleniumforest closed 10 months ago

seleniumforest commented 1 year ago

It works only if you pass raw string query, but doesn't work with key-value array. Version "@cosmjs/stargate": "^0.31.0"

const { StargateClient } = require("@cosmjs/stargate");

(async () => {
    let client = await StargateClient.connect("https://stargaze-rpc.polkachu.com/");
    let stringResult = await client.searchTx(`tx.height=9525321`);

    //stringResult: 4CB5DC2A0F6EB0F256CCA245CFE10979B091DB281851190B8CB8BBCEE7503137 
    console.log(`stringResult: ${stringResult[0].hash} \n`);

    //Error: Bad status on response: 500
    //[{ key: "height", value: "9525321" }] also doesn't work
    let keyValueResult = await client.searchTx([{ key: "tx.height", value: "9525321" }]);
    console.log(`keyValueResult: ${keyValueResult}`);
})();
webmaster128 commented 1 year ago

Nice find, thank you. What about

await client.searchTx(`tx.height='9525321'`);

? This is what the array version is converted to internally.

seleniumforest commented 1 year ago

Nice find, thank you. What about

await client.searchTx(`tx.height='9525321'`);

? This is what the array version is converted to internally.

Error: Bad status on response: 500

seleniumforest commented 1 year ago

There shouldn't be quotes. This is right query https://stargaze-rpc.polkachu.com/tx_search?query=%22tx.height=9525321%22

That query with '' doesn't work, seems like server parses it as string, but expects int https://stargaze-rpc.polkachu.com/tx_search?query=%22tx.height=%279525321%27%22

webmaster128 commented 1 year ago

Interesting. I was not aware there is a difference between types in that interface. Maybe that changed at some point.

I think we can change the array elements as follows:

 {
   readonly key: string;
-  readonly value: string;
+  readonly value: string | number | bigint | Uint53 | Uint64;
 }

and avoid the quotes for the number case.