Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Allow contracts to query whether an address is a contract #9064

Closed
athei opened this issue Jun 10, 2021 · 2 comments · Fixed by #10789
Closed

Allow contracts to query whether an address is a contract #9064

athei opened this issue Jun 10, 2021 · 2 comments · Fixed by #10789
Labels
J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder

Comments

@athei
Copy link
Member

athei commented Jun 10, 2021

The following APIs should be introduced for contracts to call:

fn is_contract(account_id: AccountId) -> bool;
fn caller_is_origin() -> bool;

Technically, caller_is_origin might not be required as is_contract(self.caller()) could be used for that. However, caller_is_origin can be implemented without any storage lookup and therefore uses less gas. Sometimes it is useful to check whether a contract is called by another contract or the origin. caller_is_origin is a cheap way to do so.

Please note that when being called as RPC the origin can indeed be a contract just because the RPC allows the sender to be specified freely. This does not matter here because during on-chain execution the origin can never be a contract and therefore no interaction with dry-running can occur.

Does this API make sense to you @Robbepop @cmichi @ascjones ?

The issue came up here: use-ink/ink#804

@athei athei added J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder labels Jun 10, 2021
@cmichi
Copy link
Contributor

cmichi commented Aug 25, 2021

Yes, makes sense to me.

@athei
Copy link
Member Author

athei commented Nov 3, 2021

Updated is_contract to be bool because tombstones no longer exist.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants