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 ability to evaluate selector during generation of contract from selector's name #806

Closed
xgreenx opened this issue Jun 8, 2021 · 4 comments
Labels
B-feature-request A request for a new feature. P-low Low priority issue.

Comments

@xgreenx
Copy link
Collaborator

xgreenx commented Jun 8, 2021

It will be cool to have the ability to generate a selector inside of code and during the declaration of the selector.

During declaration of selector:

#[ink(message, selector = "IErc20::token_name")]
fn token_name(&self) -> Option<String> {
    Erc20::token_name(self)
}

Somewhere in code:

build_call::<DefaultEnvironment>()
  .callee(to)
  .exec_input(
    ExecutionInput::new(selector!("IErc721Receiver::on_erc721_received"))
        .push_arg(operator)
        .push_arg(from)
        .push_arg(id)
        .push_arg(data),
  )
  .returns::<ReturnType<Result<(), Erc721ReceiverError>>>()
  .fire()
@Robbepop
Copy link
Collaborator

With #928 merged and #665 in the review process and about to be merged soon we can actually start working on this cool feature request.

@Robbepop
Copy link
Collaborator

Note that this feature could be very confusing to users of ink! version 3.0-rc5 and older since until then selector = value:string was allowed with value being of the form 0xC0DECAFE or some other hex-encoded u32 value in this particular form.
If a user does not update their codebase while jumping from ink! version 3.0-rc5 and a future version that implements this new evaluation feature for selectors the user's selectors will just silently change without notice.

@Robbepop
Copy link
Collaborator

#947 implemented this. Closed.

@xgreenx
Copy link
Collaborator Author

xgreenx commented Oct 25, 2021

Thanks=) You implemented the second case, but what about the first?

#[ink(message, selector = "IErc20::token_name")]
fn token_name(&self) -> Option<String> {
    Erc20::token_name(self)
}

Note that this feature could be very confusing to users of ink! version 3.0-rc5 and older since until then selector = value:string was allowed with value being of the form 0xC0DECAFE or some other hex-encoded u32 value in this particular form.

I agree with it. But I think we can create a workaround here. If we are able to parse the string into u32, then we should emit an error(that it is deprecated). But if it is not u32, so it is a user-defined string and we can calculate a hash form it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-feature-request A request for a new feature. P-low Low priority issue.
Projects
None yet
Development

No branches or pull requests

3 participants