Skip to content
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

Add query to determine if address contains a contract #896

Closed
ethanfrey opened this issue Apr 21, 2021 · 4 comments
Closed

Add query to determine if address contains a contract #896

ethanfrey opened this issue Apr 21, 2021 · 4 comments

Comments

@ethanfrey
Copy link
Member

Resolves a large part of #893

Sometime a contract wants to know if it is called by a pubkey (external user) or another contract. Or if we are given a cw20-contract address, we can quickly check if it is really a contract or someone faking this.

Let's add is_contract(&self, addr: &str) -> bool on QuerierWrapper, such that it returns true iff addr is a valid address and there is a cosmwasm contract stored at that address. Add appropriate variant to QueryRequest and wasmd as well.

@webmaster128 what do you think of this? May be small enough to fit in 0.14? Just need to figure out where to place it. wasmd implementation should not be hard.

This is somewhat related to ideas in #143. Maybe we want to provide more info than just bool? We can also push to 0.14.1 or later if you think it is worthwhile to return more info and we should reflect on that some

@webmaster128
Copy link
Member

webmaster128 commented Apr 21, 2021

I'd implement more or less this query into x/wasm: https://github.com/cosmos/cosmjs/blob/v0.25.0-alpha.2/packages/cosmwasm-stargate/src/cosmwasmclient.ts#L288-L305. Instead of throwing we turn the result into a Option<ContractInfo> or something like that. This would be well in line with the wasm query service https://github.com/CosmWasm/wasmd/blob/master/proto/cosmwasm/wasm/v1beta1/query.proto#L14-L55

@webmaster128
Copy link
Member

I think this can already be implemented in contracts today by using a copy of this code, an arbitrary key and handling SystemError::NoSuchContract instead of converting it to an StdError: https://github.com/CosmWasm/cosmwasm/blob/v0.14.0-beta4/packages/std/src/traits.rs#L230-L261

@ethanfrey
Copy link
Member Author

Hmmm... maybe we will want this Option<ContractInfo>.
With #889 we start caring about the admin of a contract more and more.

@ethanfrey
Copy link
Member Author

Closed by #1089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants