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
635 stars 328 forks source link

Duplication code #1524

Open happylolonly opened 7 months ago

happylolonly commented 7 months ago

Hi, why need such funcs? https://github.com/cosmos/cosmjs/blob/v0.32.0/packages/stargate/src/stargateclient.ts#L333

It is not possible to just use them from inherited modules, than make public?

In our project our devs made same, and code looks duplicated https://github.com/cybercongress/soft3.js/blob/main/src/cyberclient.ts#L430

Or you can do: public getAllBalances = this.forceGetQueryClient().bank.allBalances; it will be shorter, and keep types correct.

What do you think?

happylolonly commented 7 months ago

Ideally I would want something like this. (or better inherit from that module's extension such https://github.com/cybercongress/soft3.js/blob/main/src/queries/bandwidth.ts#L26 )

image
happylolonly commented 7 months ago

What if make queryClient public, than private? It will alow to use all methods from extensions

https://github.com/cosmos/cosmjs/blob/v0.32.0/packages/stargate/src/stargateclient.ts#L200

webmaster128 commented 7 months ago

The whole idea of those wrapper functions does not scale and needs to be abandoned at some point, for both queries and messages/transactions. This was already touched briefly in https://github.com/cosmos/cosmjs/issues/1440. There is an experimental generic Client class that comes without them shown in https://github.com/cosmos/cosmjs/pull/1486. So yeah, it was a good idea when this API was originally designed but we can't keep up with the amount of functionality and at the same time using the protobuf API directly got more convenient.