Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose types #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Expose types #292

wants to merge 1 commit into from

Conversation

jackzampolin
Copy link

Replaces #291

@@ -145,6 +145,18 @@ func NewCodec() *Codec {
return cdc
}

func (cdc *Codec) TypeInfos() map[reflect.Type]*TypeInfo {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have too much context here, but simply returning maps on a reference type is somewhat dangerous as the caller can unexpectedly modify the reference (i.e. the codec). Instead, return a copy of the map.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's add simple godocs.

@ebuchman
Copy link
Contributor

Can we open an issue for this please?

Also note there is the Codec.PrintTypes method which outputs a pretty table like: https://github.com/tendermint/tendermint/blob/master/docs/spec/blockchain/encoding.md#public-key-cryptography. Ie that table is the output of https://github.com/tendermint/tendermint/blob/master/crypto/encoding/amino/encode_test.go#L56

I'm not sure exactly the use case here, but if you don't need it programmatically, hopefully printing the table is sufficient. Otherwise you will need to grab the mutex and copy the map, as bez pointed out

@jackzampolin
Copy link
Author

jackzampolin commented Nov 20, 2019

This was some quick hacking I did one afternoon to try to expose the types tracked by amino in a json format so that we could turn them easily into typescript definitions. The codec.PrintTypes function doesn't give enough info for this. This PR should be in draft and thats my bad.

I believe that Hans is working on this so I would like to check with him before closing/doing more work.

@ebuchman
Copy link
Contributor

Oh cool - would a method that just dumps JSON be sufficient then? Might be easier than trying to programmatically export the mutex protected maps ...

@jackzampolin
Copy link
Author

@ebuchman I think it would. How to do that with the existing code? This also could be useful for generating .proto types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants