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

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

@athei

Description

@athei

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    J0-enhancementAn additional feature request.Z1-easyCan be fixed primarily by duplicating and adapting code by an intermediate coder

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions