tendermint / go-amino

Protobuf3 with Interface support - Designed for blockchains (deterministic, upgradeable, fast, and compact)
Other
260 stars 84 forks source link

Add codec method to retrieve a Go type registered name #316

Open gsora opened 4 years ago

gsora commented 4 years ago

Given a codec, users might want to know what's the Amino type associated with a given struct instance.

This commit adds the functionality needed to do that, for both instance and pointer-to-instance types.

Nil interfaces are rejected by default.

Method completed with tests.


We are in the process of writing various SDKs for our project (commercionetwork), and for the Go one we thought it might be a great idea to simply reuse all the types implemented in our modules.

We need to know at runtime Amino message types for every possible type in order to construct a well-defined Cosmos REST transaction message.

Right now, we manually parse codec.PrintTypes() output and build a map which associates Go type to its Amino name.

This patch integrates basically the same idea, by leveraging the codec's integrated type map.