-
Notifications
You must be signed in to change notification settings - Fork 354
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
New implementation for addr_canonicalize and addr_humanize functions #1873
Comments
After brainstorming about this change with @webmaster128 and @chipshort we agreed, Planned changesImplementation of the trait Function
|
Implementation planAdding function Changing the behaviour of functions Adding Bech32 prefix to MockApi seems to be a non-breaking change and can be implemented immediately. |
I agree with the above except for one thing: I think it would be good to keep Addr encoding agnostic. |
I like the idea. Let's keep |
I pulled out #1887 as a preparation that allows users to use it instead of Addr::unchecked. This I think should go in 1.5. The rest if this ticket we can do later. |
This issue and the corresponding PR is a proposal of using new algorithms in functions:
Api::addr_canonicalize
, andApi::addr_humanize
implemented in
cosmwasm_std::testing::MockApi
.The new implementation is based on Bech32 encoding format (as idescribed in BIP-0173 and Bech32m encoding format described in BIP-0350) and uses the implementation provided by crate bech32.
Proposed solution supports all currently implemented functionality, like the possibility of using short custom addresses like foobar that are not bech32 encoded. Additionaly, new functions allow users to generate humanized addresses just like real-life blockchain in bech32 format with user-defined prefix like juno, osmosis etc. Finally, this solution solves the issue #1648 and unlocks implementation of the issue #39.
Proposed solution
This solution is based on Bech32 encoding format with default or user-defined bech32 prefix. User can define Bech32 prefix during MockApi instantiation.
All input addresses represented directly as a string or wrapped with
Addr
are treated either as Bech32 encoded or as a plain text. The simplest usage scenario is following: a user provides a simple plain-text address which is then canonicalized and humanized, e.g.:When a user provides a long address, similar as in Juno chain, then the previous example would look like this:
When a user wants to generate and humanize a predictable contract address using a function
instantiate2_address
while testing contracts in Juno chain test cases, then it could be done as follows:Proposed algorithm
It is assumed, that MockApi has configured Bech32 prefix during instantiation for example: juno. The reversed version of this prefix (rev_prefix) is used internally as desribed below.
addr_canonicalize
addr_humanize
The text was updated successfully, but these errors were encountered: