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

Report error when instantiating a contract from a non-payable message #939

Closed
cmichi opened this issue Sep 23, 2021 · 1 comment
Closed
Labels
A-ink_lang [ink_lang] Work item

Comments

@cmichi
Copy link
Collaborator

cmichi commented Sep 23, 2021

I'm creating this issue as a follow-up for #740.

The issue is that if a contract has a method a la

#[ink(message)]
pub fn deploy(&mut self, version: u32, code_hash: Hash) {
    let _ = Subcontract::new(b)
        .endowment(self.env().balance() / 4)
        .code_hash(code_hash)
        .salt_bytes(version.to_le_bytes())
        .instantiate()
        .expect("failed at instantiating);
}

Then calling this method will fail at runtime with ContractTrapped. This is because the payable attribute is missing, the message signature should be #[ink(message, payable)].

In an ideal world we would detect this already at compile time, though I'm not sure how feasible this is with nested functions and what not.

Either way: We should improve the error reporting and documentation on this in some way.

@cmichi cmichi added the A-ink_lang [ink_lang] Work item label Sep 23, 2021
@cmichi
Copy link
Collaborator Author

cmichi commented Sep 23, 2021

Closing the issue, since the payable is not actually necessary, just verified it. The contract pays entirely from it's own balance for the deployment.

@cmichi cmichi closed this as completed Sep 23, 2021
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
Projects
None yet
Development

No branches or pull requests

1 participant