Skip to content

Experiment with new syntax for messages #24

Closed
@Robbepop

Description

@Robbepop

Currently to flag a function in a contract impl block to be a message that can (only) be called from outside we set its visibility to pub(external) like in the following example:

contract! {
    struct MyContract;
    impl Deploy for MyContract { ... }

    impl MyContract {
        pub(external) fn callable_from_outside() { ... }
        fn private_fn() { ... }
    }
}

This has some downsides.
Fist of all it might be confusing to use the pub(restricted) syntax to restrict local entities from accessing but unrestrict remote accesses. Also it would be nice to not have to apply those annotation everywhere.
The following syntax might solve these issues.

contract! {
    struct MyContract;
    impl Deploy for MyContract { ... }

    impl MyContract {
        #[extern] fn callable_from_outside() { ... }
        fn private_fn() { ... }
    }
}

With the #[extern] semantic attribute we can either annotate functions or entire impl blocks to mark them as callable from remote sources. An example of an annotated impl block can be seen below.

contract! {
    struct MyContract;
    impl Deploy for MyContract { ... }

    #[extern]
    impl MyContract {
        fn callable_from_outside() { ... }
    }

    impl MyContract {
        fn private_fn() { ... }
    }
}

Another advantage is that this syntax is more aligned to standard Rust code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ink_lang[ink_lang] Work itemB-designDesigning a new component, interface or functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions