-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor: allow getting address prefix from address codec #15913
Conversation
@julienrbrt your pull request is missing a changelog! |
We do not need one here. |
core/address/codec.go
Outdated
@@ -2,6 +2,8 @@ package address | |||
|
|||
// Codec defines an interface to convert addresses from and to string/bytes. | |||
type Codec interface { | |||
// GetBech32Prefix returns the bech32 prefix | |||
GetBech32Prefix() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid adding bech32 specific to this interface, this interface is meant to be agnostic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I rename it to GetAddressPrefix and that it returns "" when there is none, how does it sound for you?
@@ -2,8 +2,10 @@ package address | |||
|
|||
// Codec defines an interface to convert addresses from and to string/bytes. | |||
type Codec interface { | |||
// StringToBytes decodes text to bytes | |||
// GetAddressPrefix returns the address prefix (if any). | |||
GetAddressPrefix() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume the codec is always bech32. I'd rather find another way to deal with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes (#15913 (comment)), so do you find this naming not fitting if the address has no prefix?
I do not know if you've seen the autocli PR but this come handy there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that fine for autocli to depend directly on auth then?
Personally, I don't like it, but that would solve the issue I have there.
Another way I thought would be autocli to depend on auth config, but this was still less clean than with this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since autocli is built off of grpc why not use
rpc Bech32Prefix(Bech32PrefixRequest) returns (Bech32PrefixResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is almost what it already uses there, and it works fine for hubl, which will build the command after having queried an endpoint. However, for normal commands, like simd
, gaiad
, etc.. When we enrich the root command, we have no endpoint to query. The information is however available, and imho this was the cleanest way to get it.
We could however:
- Add an argument in EnhanceRootCommand for the bech32 prefix (easiest but most ugly because for hubl we'll need to pass an empty string)
- Inject address codec and add api to get address prefix (this was my preferred solution and what is done in this PR)
- Inject auth configuration and use
config.Bech32Prefix
for the address prefix, which is fine for app wiring app, but it makes it weird when you have to construct AppOptions manually - Inject auth, then we have a hard dependency on auth for autocli
I am open to other suggestions however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just change the flag.Builder argument to take address.Codec instead of bech32 prefix. I think that would resolve this without needing to change address.Codec. Also if we do need the actual prefix let's use an extension interface instead of changing address.Codec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think of the problem this way. This would indeed work too, and only complexify the flag builder
I will close this then and re-open it shortly with only the clean-ups that were done here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume the codec is always bech32. I'd rather find another way to deal with this
While we can't assume this, this is pretty baked into the SDK and I personally can't see this changing in the future.
Description
Needed by #15906 so we can avoid passing config.
This PR does not need a changelog.
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change