Closed NoahSaso closed 11 months ago
Hi, I've figured out a good way of handling implements_interface, this can let people better use interface.enable: https://www.loom.com/share/33256b4ea33147cc9794e282a2902a52
A POC of handling implements_interface: https://github.com/cosmology-tech/telescope/tree/impl-interfaces/__fixtures__/misc/output-impl-interfaces
Even though toAmino is not included in the sample code, but I guess the idea would be alike. I'll be working on this, hopefully it can be done soon.
Hi, I've figured out a good way of handling implements_interface, this can let people better use interface.enable: https://www.loom.com/share/33256b4ea33147cc9794e282a2902a52
A POC of handling implements_interface: https://github.com/cosmology-tech/telescope/tree/impl-interfaces/__fixtures__/misc/output-impl-interfaces
Even though toAmino is not included in the sample code, but I guess the idea would be alike. I'll be working on this, hopefully it can be done soon.
Oh cool. If another system exists to decode, then maybe I can stop using interfaces.enable
entirely. For now, I submitted a PR that should satisfy my immediate needs.
Hi, the PR's been merged and published: @cosmology/telescope@1.0.13
Right now, the only way to utilize interface decoders is the global
options.interfaces.enabled
flag. When this is used, decoding a protobuf recursively decodes all nestedAny
interfaces inside. This is great UX for viewing the raw data of a message, but breaks Amino signing. Here's why...This is how Amino signing works right now:
392
: protobuf messages transformed into Amino messages (toAmino
)394
: Amino messages sent to wallet/signer for signing398
: signed Amino messages decoded back into protobuf messages (fromAmino
)402
: TX body protobuf encoded with messagesThe
toAmino
function uses its nested types'_ToAmino
interface encoding functions when interfaces are enabled. The_ToAmino
function usestoAmino(decode(nestedAny.value))
on the nested type to get the correct Amino data for it in a switch block. Thedecode
function then uses_InterfaceDecoder
s whenAny
s with interfaces exist.This path shows that encoding to Amino leads to decoding nested
Any
types. When interfaces are disabled,Any
interfaces are decoded withAny.decode
, which is the correct type that is expected by the chain. When interfaces are enabled, the default behavior becomes decoding with the nested type's decoding function.I think the default behavior should always be to not use the interface, so that messages are decoded into the format expected by the chain. Then there can be an additional flag on the
decode
andtoAmino
functions calleduseInterfaces
, which defaults tofalse
, and setting it totrue
can then recursively decodeAny
s with interfaces. The key is that this flag is passed fromtoAmino
through the_ToAmino
interface encoder to both thetoAmino
anddecode
functions of nested types so that any recursivedecode
functions can decide to simply useAny.decode
instead of one the_InterfaceDecoder
functions.Simply disabling the interface feature globally is insufficient because there are different times we want to richly decode a protobuf and other times we want to encode protobufs for Amino signing.