Skip to content

Experiment with new syntax for messages #24

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

Closed
Robbepop opened this issue Mar 13, 2019 · 2 comments
Closed

Experiment with new syntax for messages #24

Robbepop opened this issue Mar 13, 2019 · 2 comments
Labels
A-ink_lang [ink_lang] Work item B-design Designing a new component, interface or functionality.

Comments

@Robbepop
Copy link
Collaborator

Robbepop commented Mar 13, 2019

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.

@Robbepop Robbepop added B-design Designing a new component, interface or functionality. D-hard A-ink_lang [ink_lang] Work item and removed D-hard labels Mar 13, 2019
@Robbepop
Copy link
Collaborator Author

Robbepop commented Mar 14, 2019

When we have implemented automatic message selectors (IDs) we could use this new syntax to opt-out of automatic ID generation for single messages like this:

#[extern(selector = 42)]
fn callable_from_outside( ... ) { ... }

This attribute argument however, is obviously only available for messages and not for entire impl blocks.

@Robbepop
Copy link
Collaborator Author

Robbepop commented Aug 8, 2019

We shouldn't break compatibility with ink! 1.0 but can look for new syntax with the upcoming ink_plugin approach. So this issue is superseeded by #163.

Closed.

@Robbepop Robbepop closed this as completed Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_lang [ink_lang] Work item B-design Designing a new component, interface or functionality.
Projects
None yet
Development

No branches or pull requests

1 participant