-
Notifications
You must be signed in to change notification settings - Fork 31
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
consider contract address length for instantiate2 #97
consider contract address length for instantiate2 #97
Conversation
packages/ics721/src/helpers.rs
Outdated
if let Some(len) = CONTRACT_ADDR_LENGTH.may_load(deps.storage)? { | ||
Ok(deps | ||
.api | ||
.addr_humanize(&canonical_cw721_addr[..len].into())?) | ||
} else { | ||
Ok(deps.api.addr_humanize(&canonical_cw721_addr)?) | ||
} |
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.
Here is the main logic for slicing addr
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.
@humanalgorithm look here, for Injective CONTRACT_ADDR_LENGTH
is set with 20
. All other chains have no entry in CONTRACT_ADDR_LENGTH
storage.
Value is then used for slicing first 20 bytes: canonical_cw721_addr[..len]
packages/ics721/src/msg.rs
Outdated
@@ -31,6 +31,8 @@ pub struct InstantiateMsg { | |||
pub pauser: Option<String>, | |||
/// The admin address for instantiating new cw721 contracts. In case of None, contract is immutable. | |||
pub cw721_admin: Option<String>, | |||
/// The optional contract address length being used for instantiate2. In case of None, default length is 32 (standard in cosmwasm). | |||
pub contract_addr_length: Option<usize>, |
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.
usize has different sizes in dev and production. Better use u32 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.
fixed and changed to u32
This PR adds new
CONTRACT_ADDR_LENGTH: Item<usize> = Item::new("n")
storage. In most case it can be left empty. For Injective it contains20
as value.By default cosmwasm considers addresses with 32 bytes as a constant. Injective on the other hand is of length 20 bytes.
See details here: CosmWasm/cosmwasm#2155
So
instantiate2
fails, when transferring from a chain to Injective. Solution is simple - as suggested by Simon: slicing and taking first 20 bytes.This has been tested on testnet, Stargaze -> Injective, and works like a charm.