Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dariuszdepta/ghist-addresses
Address handling with bech32
https://github.com/dariuszdepta/ghist-addresses
Last synced: 30 days ago
JSON representation
Address handling with bech32
- Host: GitHub
- URL: https://github.com/dariuszdepta/ghist-addresses
- Owner: DariuszDepta
- License: apache-2.0
- Created: 2023-09-14T13:58:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-07T09:50:57.000Z (8 months ago)
- Last Synced: 2024-03-07T11:48:53.858Z (8 months ago)
- Language: Rust
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Address in CosmWasm
This issue is well-known and was reported in [#1648](https://github.com/CosmWasm/cosmwasm/issues/1648).
The problem was firstly resolved in version **2.0.0-rc.0** of `cosmwasm-std`. It will be officially
available in version **2.0.0** of `cosmwasm-std` and version **2.0.0** of `cw-multi-test`.To reproduce the original error locally, just create a Rust app with following dependencies:
```shell
$ cat Cargo.toml
[package]
name = "addresses"
version = "0.0.1"
edition = "2021"[dependencies]
cosmwasm-std = "1.2.8"
cw-multi-test = { version = "0.20.0", features = ["cosmwasm_1_2"] }
```and a single source file:
```shell
$ cat src/main.rs
use cosmwasm_std::{instantiate2_address, Api};
use cw_multi_test::App;fn main() {
let app = App::default();
let human_addr = app.api().addr_make("creator");
let canonical_addr = app.api().addr_canonicalize(human_addr.as_str()).unwrap();
let checksum = &[87; 32];
let salt = &[1; 5];
let contract_address = instantiate2_address(checksum, &canonical_addr, salt).unwrap();
let result = app.api().addr_humanize(&contract_address);
println!("{:?}", result);
}
```The result should be:
```shell
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.07s
Running `target/debug/addresses`
Err(GenericErr { msg: "Invalid input: canonical address length not correct" })
```To check the fix in `[email protected]` create a simple Rust app with the following dependencies:
```shell
$cat Cargo.toml
[package]
name = "addresses"
version = "0.0.1"
edition = "2021"[dependencies]
cosmwasm-std = "2.0.0-rc.0"
```and a single source file:
```shell
$ cat src/main.rs
use cosmwasm_std::testing::MockApi;
use cosmwasm_std::{instantiate2_address, Api};fn main() {
let api = MockApi::default();
let human_addr = api.addr_make("creator");
let canonical_addr = api.addr_canonicalize(human_addr.as_str()).unwrap();
let checksum = &[87; 32];
let salt = &[1; 5];
let contract_address = instantiate2_address(checksum, &canonical_addr, salt).unwrap();
let result = api.addr_humanize(&contract_address);
println!("{:?}", result);
}
```The result should be:
```shell
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running `target/debug/addresses`
Ok(Addr("cosmwasm19v9fz5q2v9xkkjr7u9jet95pdz8xncq8h5s6xqesph2fpe97dgjs0p38pf"))
```After publishing `[email protected]` we will provide a working example using `cw-multi-test`.