cosmology-tech / telescope

A TypeScript Transpiler for Cosmos Protobufs ⚛️
https://cosmology.zone/products/telescope
Apache License 2.0
146 stars 43 forks source link

Supporting doubles #599

Open KeKs0r opened 7 months ago

KeKs0r commented 7 months ago

Hi,

I am trying to decode queries for Umee, and they apparently use the double type: https://github.com/umee-network/umee/blob/main/proto/umee/leverage/v1/query.proto#L409

But when generating code i see that the binary reader throws an error that double is not supported:

Error: double not supported

Is there a known workaround, or way to support doubles?

pyramation commented 7 months ago

hey there @KeKs0r ! Thanks for reporting. it was our understanding not to support floats, doubles, or proto2 fields.

@webmaster128 — Simon, did we misunderstand, and is double something we need? It looks like umee is using double, not sure how the encoding should output, but we can take a look at ts-proto output

ideally mayabe we can treat double similar to other fields and maybe not a big add on

webmaster128 commented 7 months ago

As far as I can tell (and according to this resource), the JavaScript number type is a 64 bit float, i.e. can hold protobuf floats and doubles.

Floats/doubles are generally not used much in blockchains as their behaviour can be host specific and can lead to non-deterministic execution. However, there are cases like compute in a query where this is safe as long as the query result is not used by the chain itself (which happens if you allow CosmWasm contracts to do the query).