-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Cosmos Scalars #9694
Comments
ACK 👍 |
I'm not a fan of changing internal structure of protobuf objects as it's done by gogoproto "customtype", it means that every protobuf generator used needs to be aware of those definitions and how they change structures internally. First pain-point it's gonna be in ORM codegen, which will need to also understand to cast the type too for example when someone is wishing to index every balance by address which should be a protobuf string but needs to be casted to the custom type. I think it would be fine to mark how certain types should be decoded, but I wouldn't go as far as mangling with protobuf object structures, for the sake of more mantainable and losely coupled code-bases. I'm bringing this up because I'm currently working on the ORM codegen and I'm constantly hitting walls due to gogoproto, incompatibility with the protobuf plugin, and the need to be aware of gogoproto options to parse objects and generate clients in the correct way. |
So the idea with the new codegen would be to properly implement protoreflect.Message so that other tools can use that rather than reflect over golang fields like you'd need to do with gogo. That is the correct way to do things with v2 afaik so it shouldn't matter what happens with the go fields as long as protoreflect works. Also I'd like to coordinate the ORM codegen work with the codegen work we're doing, but still if protoreflect is correct it shouldn't matter. |
Absolutely. The problem we'd hit, for example, would be in |
We need to decide in which repo to put these annotations (e.g. in related cosmos/cosmos-proto#4 |
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #9694 goes hand-in-hand with cosmos/cosmos-proto#17 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
Summary
Introduce the notion of cosmos scalars.
Part of #7091.
Problem Definition
We decided to use strings to represent addresses in proto definitions. A string can mean anything, and it sometimes be hard to guess that the string actually represents an address.
This issue introduces the notion of a Cosmos "Scalar" type (similar to the notion of Scalar type in GraphQL), which would just be simple aliases that give human-understable meaning to the underlying type, both in Go code and in Proto definitions.
How it looks like
Introduce the following Cosmos scalar types (naming to be confirmed):
cosmos.AddressString
: the string representation of an address.cosmos.AddressBytes
: address as bytes,cosmos.Int
: integerscosmos.Dec
: decimalsOther scalars can be introduced in the future.
Usage in Protobuf
Usage in Go Code
The above code would generate in Go (with cosmos-proto):
Proposal
Go through all the proto files, and add annotations to all relevant fields.
Types we need add annotation for:
Open questions:
cosmos_proto.scalar =
: string or enum (do we want people to extend scalars)?cc @aaronc @cyberbono3
For Admin Use
The text was updated successfully, but these errors were encountered: