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

Amino support for Protobuf enum #1161

Open
jefft0 opened this issue Sep 21, 2023 · 0 comments
Open

Amino support for Protobuf enum #1161

jefft0 opened this issue Sep 21, 2023 · 0 comments

Comments

@jefft0
Copy link
Contributor

jefft0 commented Sep 21, 2023

One of the API functions in GnoMobile returns key info which includes the key type. This is defined in types.go:

// KeyType reflects a human-readable type for key listing.
type KeyType uint

// Info KeyTypes
const (
	TypeLocal   KeyType = 0
	TypeLedger  KeyType = 1
	TypeOffline KeyType = 2
	TypeMulti   KeyType = 3
)

If we use KeyType for a field in a Go struct, then the Protobuf definition made by amino is just an integer. The useful names like "Local" and "Ledger" are lost. The related Protobuf enum would be:

enum KeyType {
  TypeLocal = 0;
  TypeLedger = 1;
  TypeOffline = 2;
  TypeMulti = 3;
}

But amino doesn't created this enum. Interestingly, the Protobuf compiler converts this enum into the following Go code:

type KeyType int32

const (
	KeyType_TypeLocal   KeyType = 0
	KeyType_TypeLedger  KeyType = 1
	KeyType_TypeOffline KeyType = 2
	KeyType_TypeMulti   KeyType = 3
)

This is the exact inverse of what it would be nice for amino to do. Issue #1157 asks a related question about preserving comments from the Go struct definition, which is difficult because the Go reflection of the struct type doesn't have comments. A proposed solution to that issue is to parse the original Go code into an AST and extract the comments. Perhaps at the same time that amino is extracting comments it could notice that a type alias like KeyType is being used as an enum and produce the Protobuf enum.

If this solution (or a better one) seems desirable, we (Berty devs) could work on a pull request with a little help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔵 Not Needed for Launch
Status: In Progress
Development

No branches or pull requests

2 participants