Skip to content

Commit

Permalink
Merge branch 'master' into ag-contains
Browse files Browse the repository at this point in the history
  • Loading branch information
agryaznov committed May 2, 2022
2 parents 5612229 + 67290c2 commit c9b8b12
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
blank_issues_enabled: true
contact_links:
- name: Support & Troubleshooting with the Stack Exchange Community
url: https://substrate.stackexchange.com
- name: Ask questions and find answers using our dedicated StackExchange site
url: https://substrate.stackexchange.com/questions/tagged/ink/
about: |
For general questions you might already find an answer in our community.
We encourage everyone to also share their understanding by answering questions for others.
We encourage everyone to also share their understanding by answering questions for others too.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ More relevant links:
* [`cargo-contract`](https://github.com/paritytech/cargo-contract) ‒ CLI tool for ink! contracts
* [Contracts UI](https://paritytech.github.io/contracts-ui/) ‒ Frontend for contract instantiation and interaction
* [Substrate Contracts Node](https://github.com/paritytech/substrate-contracts-node) ‒ Simple Substrate blockchain which includes smart contract functionality
* [Substrate Stack Exchange](https://substrate.stackexchange.com/) - Forum for getting your ink! questions answered
* [Substrate Stack Exchange](https://substrate.stackexchange.com/questions/tagged/ink/) - Forum for getting your ink! questions answered


## Table of Contents
Expand Down
62 changes: 25 additions & 37 deletions crates/lang/codegen/src/generator/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,48 +154,37 @@ impl Dispatch<'_> {
) -> TokenStream2 {
let span = self.contract.module().storage().span();
let storage_ident = self.contract.module().storage().ident();
let inherent_ids = self
let message_ids = self
.contract
.module()
.impls()
.filter(|item_impl| item_impl.trait_path().is_none())
.flat_map(|item_impl| item_impl.iter_messages())
.map(|message| {
let span = message.span();
message_spans.push(span);
let id = message
.composed_selector()
.into_be_u32()
.hex_padded_suffixed();
quote_spanned!(span=> #id)
.flat_map(|item_impl| {
iter::repeat(item_impl.trait_path()).zip(item_impl.iter_messages())
})
.collect::<Vec<_>>();
let trait_ids = self
.contract
.module()
.impls()
.filter_map(|item_impl| {
item_impl
.trait_path()
.map(|trait_path| {
iter::repeat(trait_path).zip(item_impl.iter_messages())
})
})
.flatten()
.map(|(trait_path, message)| {
let local_id = message.local_id().hex_padded_suffixed();
let span = message.span();
message_spans.push(span);
quote_spanned!(span=>
{
::core::primitive::u32::from_be_bytes(
<<::ink_lang::reflect::TraitDefinitionRegistry<<#storage_ident as ::ink_lang::reflect::ContractEnv>::Env>
as #trait_path>::__ink_TraitInfo
as ::ink_lang::reflect::TraitMessageInfo<#local_id>>::SELECTOR
)
}
)
});

if let Some(trait_path) = trait_path {
let local_id = message.local_id().hex_padded_suffixed();
quote_spanned!(span=>
{
::core::primitive::u32::from_be_bytes(
<<::ink_lang::reflect::TraitDefinitionRegistry<<#storage_ident as ::ink_lang::reflect::ContractEnv>::Env>
as #trait_path>::__ink_TraitInfo
as ::ink_lang::reflect::TraitMessageInfo<#local_id>>::SELECTOR
)
}
)
} else {
let id = message
.composed_selector()
.into_be_u32()
.hex_padded_suffixed();
quote_spanned!(span=> #id)
}
})
.collect::<Vec<_>>();
quote_spanned!(span=>
impl ::ink_lang::reflect::ContractDispatchableMessages<{
<#storage_ident as ::ink_lang::reflect::ContractAmountDispatchables>::MESSAGES
Expand All @@ -204,8 +193,7 @@ impl Dispatch<'_> {
::core::primitive::u32;
<#storage_ident as ::ink_lang::reflect::ContractAmountDispatchables>::MESSAGES
] = [
#( #inherent_ids , )*
#( #trait_ids ),*
#( #message_ids , )*
];
}
)
Expand Down
63 changes: 56 additions & 7 deletions crates/lang/tests/ui/contract/pass/message-selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,45 @@ mod contract {
#[ink(storage)]
pub struct Contract {}

#[ink_lang::trait_definition]
pub trait Messages {
#[ink(message)]
fn message_0(&self);

#[ink(message, selector = 1)]
fn message_1(&self);
}

impl Messages for Contract {
#[ink(message)]
fn message_0(&self) {}

#[ink(message, selector = 1)]
fn message_1(&self) {}
}

impl Contract {
#[ink(constructor)]
pub fn constructor() -> Self {
Self {}
}

#[ink(message)]
pub fn message_0(&self) {}

#[ink(message, selector = 1)]
pub fn message_1(&self) {}

#[ink(message, selector = 0xC0DE_CAFE)]
pub fn message_2(&self) {}

#[ink(message, selector = _)]
pub fn message_3(&self) {}
}

#[ink_lang::trait_definition]
pub trait Messages2 {
#[ink(message, selector = 0x12345678)]
fn message_4(&self);
}

impl Messages2 for Contract {
#[ink(message, selector = 0x12345678)]
fn message_4(&self) {}
}
}

Expand All @@ -34,7 +59,7 @@ fn main() {
>>::IDS[0]
},
>>::SELECTOR,
[0x5A, 0x6A, 0xC1, 0x5D],
[0xFB, 0xAB, 0x03, 0xCE],
);
assert_eq!(
<Contract as ::ink_lang::reflect::DispatchableMessageInfo<
Expand All @@ -60,4 +85,28 @@ fn main() {
>>::SELECTOR,
0xC0DE_CAFE_u32.to_be_bytes(),
);
assert_eq!(
<Contract as ::ink_lang::reflect::DispatchableMessageInfo<
{
<Contract as ::ink_lang::reflect::ContractDispatchableMessages<
{
<Contract as ::ink_lang::reflect::ContractAmountDispatchables>::MESSAGES
},
>>::IDS[3]
},
>>::SELECTOR,
[0xB6, 0xC3, 0x27, 0x49],
);
assert_eq!(
<Contract as ::ink_lang::reflect::DispatchableMessageInfo<
{
<Contract as ::ink_lang::reflect::ContractDispatchableMessages<
{
<Contract as ::ink_lang::reflect::ContractAmountDispatchables>::MESSAGES
},
>>::IDS[4]
},
>>::SELECTOR,
0x12345678_u32.to_be_bytes(),
);
}

0 comments on commit c9b8b12

Please sign in to comment.